Skip to content

Commit

Permalink
Show reporting user on issues screen
Browse files Browse the repository at this point in the history
  • Loading branch information
nertc committed Sep 5, 2024
1 parent cee9818 commit 7d67d4e
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/assets/javascripts/turbo_tooltip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
$(document).ready(function () {
const tooltipFn = function () {
const toolitps = $("[data-bs-toggle='tooltip']");
toolitps.tooltip();

$(this).on("turbo:click.tooltip turbo:submit-start.tooltip", function ({ detail }) {
const pathname =
(detail.url && new URL(detail.url).pathname) ||
(detail.formSubmission && detail.formSubmission.fetchRequest.url.pathname);
toolitps.tooltip("dispose");
if (pathname === window.location.pathname) {
$(this).off("turbo:click.tooltip turbo:submit-start.tooltip");
} else {
$(this).off(".tooltip");
}
});
};

tooltipFn();
$(document).on("turbo:load.tooltip", tooltipFn);
});
8 changes: 8 additions & 0 deletions app/assets/stylesheets/common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,14 @@ tr.turn {
}
}

/* Rules for the issues page */

.issues.issues-index {
td.reporter_users {
max-width: 5rem;
}
}

/* Rules for the account confirmation page */

.users-terms {
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/issues_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ def index
end

@issues, @newer_issues_id, @older_issues_id = get_page_items(@issues, :limit => @params[:limit])

@unique_reporters = @issues.each_with_object({}) do |issue, reporters|
reporters[issue.id] = issue.reports.preload(:user).map(&:user).uniq
end

render :partial => "page" if turbo_frame_request_id == "pagination"
end

Expand Down
4 changes: 4 additions & 0 deletions app/views/issues/_page.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<th><%= t ".reports" %></th>
<th><%= t ".reported_item" %></th>
<th><%= t ".reported_user" %></th>
<th class="reporter_users"><%= t ".reporter_users" %></th>
<th><%= t ".last_updated" %></th>
</tr>
</thead>
Expand All @@ -23,6 +24,9 @@
<td class="text-nowrap"><%= link_to t(".reports_count", :count => issue.reports_count), issue %></td>
<td><%= link_to reportable_title(issue.reportable), reportable_url(issue.reportable) %></td>
<td><%= link_to issue.reported_user.display_name, issue.reported_user if issue.reported_user %></td>
<td class="reporter_users text-truncate" data-bs-toggle="tooltip" data-bs-placement="left" data-bs-title="<%= safe_join(@unique_reporters[issue.id].map(&:display_name), ", ") %>">
<%= safe_join(@unique_reporters[issue.id].map { |reporter| link_to reporter.display_name, reporter }, ", ") %>
</td>
<td>
<% if issue.user_updated %>
<%= t ".last_updated_time_ago_user_html", :user => link_to(issue.user_updated.display_name, issue.user_updated),
Expand Down
1 change: 1 addition & 0 deletions app/views/issues/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<% content_for :heading do %>
<h1><%= t ".title" %></h1>
<%= javascript_include_tag "turbo_tooltip" %>
<% end %>

<p><%= t ".search_guidance" %></p>
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1481,6 +1481,7 @@ en:
reports: Reports
last_updated: Last Updated
last_updated_time_ago_user_html: "%{time_ago} by %{user}"
reporter_users: Reporter Users
reports_count:
one: "%{count} Report"
other: "%{count} Reports"
Expand Down
10 changes: 10 additions & 0 deletions test/system/issues_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,14 @@ def test_issues_pagination
assert_no_content(/extra_#{n}[^\d]/i)
end
end

def test_issue_reporters
sign_in_as(create(:moderator_user))
issue = create(:issue, :assigned_role => "moderator")
issue.reports << create(:report, :user => create(:user, :display_name => "Test Name"))

visit issues_path
assert_content issue.reported_user.display_name
assert_content issue.reports.first.user.display_name
end
end

0 comments on commit 7d67d4e

Please sign in to comment.