Skip to content

Commit

Permalink
truncate long names so nav-container does not grow (#550)
Browse files Browse the repository at this point in the history
  • Loading branch information
voodoo authored Nov 16, 2024
1 parent d445dde commit 751d103
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
module ApplicationHelper

def truncate_long_name(name)
truncate(name, length: 20)
end

def at_most_two_initials(initials)
return initials if initials.nil? || initials.length <= 2
initials[0] + initials[-1]
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<div tabindex="0" role="button" class="flex items-center justify-between w-full h-10 pr-2 mb-1 rounded-lg cursor-pointer scale-down hover:bg-gray-100 dark:hover:bg-gray-700 group !outline-0">
<%= render partial: "layouts/user_avatar", locals: { user: Current.user, size: 7, classes: "ml-2 mr-2" } %>
<div class="flex-1 text-sm truncate text-gray-950 dark:text-gray-100">
<%= Current.user.name.full || "Profile" %>
<%= truncate_long_name(Current.user.name.full) || "Profile" %>
</div>
<%= icon "chevron-up", variant: :mini, class: 'text-gray-500 ml-[2px]' %>
</div>
Expand Down
4 changes: 2 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2024_11_11_131751) do
ActiveRecord::Schema[7.2].define(version: 2024_11_11_131751) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -172,8 +172,8 @@
t.boolean "supports_tools", default: false
t.decimal "input_token_cost_cents", precision: 30, scale: 15
t.decimal "output_token_cost_cents", precision: 30, scale: 15
t.boolean "supports_system_message", default: false
t.boolean "best", default: false
t.boolean "supports_system_message", default: false
t.index ["api_service_id"], name: "index_language_models_on_api_service_id"
t.index ["user_id", "deleted_at"], name: "index_language_models_on_user_id_and_deleted_at"
t.index ["user_id"], name: "index_language_models_on_user_id"
Expand Down
13 changes: 13 additions & 0 deletions test/helpers/application_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,17 @@ class ApplicationHelperTest < ActionView::TestCase
test "can have spaces" do
assert_equal "pQ", at_most_two_initials("p v Q")
end

test "truncates long names" do
assert_equal "John D. Z. Smith ...", truncate_long_name("John D. Z. Smith Jane Doe")
end

test "short names are not truncated" do
assert_equal "John D. Doe", truncate_long_name("John D. Doe")
end

test "handles nil" do
assert_nil truncate_long_name(nil)
end

end

0 comments on commit 751d103

Please sign in to comment.