Skip to content

Commit

Permalink
Truncate usernames in profile links
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKhorev committed Dec 30, 2023
1 parent 7e73286 commit 61e3578
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/helpers/changesets_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def changeset_user_link(changeset)
if changeset.user.status == "deleted"
t("users.no_such_user.deleted")
elsif changeset.user.data_public?
link_to(changeset.user.display_name, user_path(changeset.user))
truncated_user_link changeset.user
else
t("browse.anonymous")
end
Expand Down
10 changes: 10 additions & 0 deletions app/helpers/user_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ def user_image_url(user, options = {})
end
end

def truncated_user_link(user, **options)
classes = %w[d-inline-block align-bottom text-truncate]
if options[:width]
style = "max-width: #{options[:width]}"
else
classes <<= "mw-100"
end
link_to user.display_name, user_path(user), :class => classes, :style => style
end

# External authentication support

def openid_logo
Expand Down
2 changes: 1 addition & 1 deletion app/views/messages/_message_summary.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<tr id="inbox-<%= message_summary.id %>" class="inbox-row<%= "-unread" unless message_summary.message_read? %>">
<td><%= link_to message_summary.sender.display_name, user_path(message_summary.sender) %></td>
<td><%= truncated_user_link message_summary.sender, :width => "30em" %></td>
<td><%= link_to message_summary.title, message_path(message_summary) %></td>
<td class="text-nowrap"><%= l message_summary.sent_on, :format => :friendly %></td>
<td class="text-nowrap d-flex justify-content-end gap-1">
Expand Down
2 changes: 1 addition & 1 deletion app/views/messages/_sent_message_summary.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<tr class="inbox-row">
<td><%= link_to sent_message_summary.recipient.display_name, user_path(sent_message_summary.recipient) %></td>
<td><%= truncated_user_link sent_message_summary.recipient, :width => "30em" %></td>
<td><%= link_to sent_message_summary.title, message_path(sent_message_summary) %></td>
<td class="text-nowrap"><%= l sent_message_summary.sent_on, :format => :friendly %></td>
<td class="text-nowrap d-flex justify-content-end gap-1">
Expand Down
4 changes: 2 additions & 2 deletions app/views/user_blocks/_block.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<tr>
<% if show_user_name %>
<td><%= link_to block.user.display_name, user_path(block.user) %></td>
<td><%= truncated_user_link block.user, :width => "30em" %></td>
<% end %>
<% if show_creator_name %>
<td><%= link_to block.creator.display_name, user_path(block.creator) %></td>
<td><%= truncated_user_link block.creator, :width => "20em" %></td>
<% end %>
<td><%= h truncate(block.reason) %></td>
<td><%= h block_status(block) %></td>
Expand Down

0 comments on commit 61e3578

Please sign in to comment.