-
Notifications
You must be signed in to change notification settings - Fork 24
HOLD: Add related-comments overview + global comments index #1866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
maebeale
wants to merge
1
commit into
main
Choose a base branch
from
maebeale/comments-index-page
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| module CommentsHelper | ||
| # One-line description of what a record's related-comments overview pulls in, | ||
| # mirroring the logic in RelatedComments. | ||
| def related_comments_summary(commentable) | ||
| case commentable | ||
| when EventRegistration then "Includes the registrant, their user account, and active organizations." | ||
| when Person then "Includes their user account and active organizations." | ||
| when Organization then "Includes people with an active affiliation." | ||
| when User then "Includes the linked person and their active organizations." | ||
| when Workshop then "Includes the workshop's creator and their organizations." | ||
| else "Comments on this record." | ||
| end | ||
| end | ||
|
|
||
| # Maps a comment's polymorphic commentable to the label, name, link, and badge | ||
| # styling used in the "About" column of the full-page comments index. | ||
| def comment_subject(commentable) | ||
| case commentable | ||
| when EventRegistration | ||
| { type: "Registration", name: commentable.event&.title || "Registration", | ||
| path: edit_event_registration_path(commentable), badge: "bg-blue-100 text-blue-800" } | ||
| when Person | ||
| { type: "Person", name: commentable.full_name, | ||
| path: person_path(commentable), badge: "bg-green-100 text-green-800" } | ||
| when Organization | ||
| { type: "Organization", name: commentable.name, | ||
| path: organization_path(commentable), badge: "bg-purple-100 text-purple-800" } | ||
| when User | ||
| { type: "User account", name: commentable.person&.name || commentable.name.presence || commentable.email, | ||
| path: user_path(commentable), badge: "bg-amber-100 text-amber-800" } | ||
| when Workshop | ||
| { type: "Workshop", name: commentable.try(:title).presence || commentable.try(:name) || "Workshop", | ||
| path: edit_workshop_path(commentable), badge: "bg-rose-100 text-rose-800" } | ||
| else | ||
| { type: commentable.class.name, name: commentable.try(:name) || "##{commentable.id}", | ||
| path: nil, badge: "bg-gray-100 text-gray-800" } | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| # Collects every comment "related" to a commentable, where the meaning of | ||
| # related depends on the commentable's type. The type is the signal of which | ||
| # comment box the user opened the overview from (each box links to its own | ||
| # polymorphic comments path), so this is the single place that decides what | ||
| # context to surface for each kind of record. | ||
| class RelatedComments | ||
| def initialize(commentable) | ||
| @commentable = commentable | ||
| end | ||
|
|
||
| def comments | ||
| commentable_groups | ||
| .map { |type, ids| Comment.where(commentable_type: type, commentable_id: ids) } | ||
| .reduce(:or) | ||
| .includes(:commentable, created_by: :person, updated_by: :person) | ||
| .newest_first | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def commentable_groups | ||
| ([ @commentable ] + related_records).compact.uniq | ||
| .group_by { |record| record.class.base_class.name } | ||
| .transform_values { |records| records.map(&:id).uniq } | ||
| end | ||
|
|
||
| def related_records | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 From Claude: The commentable's type is the only signal of which comment box the button was clicked from — each box links to its own polymorphic |
||
| case @commentable | ||
| when EventRegistration then registration_related | ||
| when Person then person_related | ||
| when Organization then organization_related | ||
| when User then user_related | ||
| when Workshop then workshop_related | ||
| else [] | ||
| end | ||
| end | ||
|
|
||
| def registration_related | ||
| person = @commentable.registrant | ||
| return [] unless person | ||
|
|
||
| [ person, person.user, *active_organizations(person) ] | ||
| end | ||
|
|
||
| def person_related | ||
| [ @commentable.user, *active_organizations(@commentable) ] | ||
| end | ||
|
|
||
| def organization_related | ||
| @commentable.people.merge(Affiliation.active).distinct.to_a | ||
| end | ||
|
|
||
| def user_related | ||
| person = @commentable.person | ||
| return [] unless person | ||
|
|
||
| [ person, *active_organizations(person) ] | ||
| end | ||
|
|
||
| def workshop_related | ||
| creator = @commentable.created_by | ||
| return [] unless creator | ||
|
|
||
| [ creator, creator.person, *(creator.person ? active_organizations(creator.person) : []) ] | ||
| end | ||
|
|
||
| def active_organizations(person) | ||
| person.organizations.merge(Affiliation.active).distinct.to_a | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <%= link_to polymorphic_path([ commentable, :comments ]), | ||
| class: "inline-flex items-center gap-1.5 text-xs font-medium text-gray-500 hover:text-gray-700 hover:underline whitespace-nowrap", | ||
| target: "_blank", rel: "noopener" do %> | ||
| View all related comments | ||
| <i class="fa-solid fa-arrow-up-right-from-square text-[0.6rem]"></i> | ||
| <% end %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,69 @@ | ||
| <% content_for(:page_bg_class, "admin-only bg-blue-100") %> | ||
| <%= render "comments/list", commentable: @commentable, comments: @comments %> | ||
| <div class="max-w-6xl mx-auto"> | ||
| <div class="mb-6"> | ||
| <% if @commentable %> | ||
| <% subject = comment_subject(@commentable) %> | ||
| <% if subject[:path] %> | ||
| <%= link_to "← Back", subject[:path], class: "text-sm text-gray-500 hover:text-gray-700 mb-2 inline-block" %> | ||
| <% end %> | ||
| <h1 class="text-2xl font-semibold text-gray-900">Related comments</h1> | ||
| <p class="text-gray-600 mt-1"> | ||
| <span class="inline-block <%= subject[:badge] %> text-xs px-2 py-0.5 rounded align-middle"><%= subject[:type] %></span> | ||
| <%= subject[:name] %> | ||
| </p> | ||
| <p class="text-sm text-gray-500 mt-1"><%= related_comments_summary(@commentable) %></p> | ||
| <% else %> | ||
| <h1 class="text-2xl font-semibold text-gray-900">All comments</h1> | ||
| <p class="text-sm text-gray-500 mt-1">Every comment in the system, with the record each one is about.</p> | ||
| <% end %> | ||
| </div> | ||
|
|
||
| <% if @comments.any? %> | ||
| <div class="overflow-x-auto animate-fade"> | ||
| <table class="min-w-full divide-y divide-gray-200"> | ||
| <thead class="bg-gray-50"> | ||
| <tr> | ||
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Date</th> | ||
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">About</th> | ||
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Author</th> | ||
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Comment</th> | ||
| </tr> | ||
| </thead> | ||
|
|
||
| <tbody class="bg-white divide-y divide-gray-200"> | ||
| <% @comments.each do |comment| %> | ||
| <% subject = comment_subject(comment.commentable) %> | ||
| <% author = comment.created_by&.person&.name || comment.created_by&.name %> | ||
| <% editor = comment.updated_by && comment.updated_by != comment.created_by ? (comment.updated_by.person&.name || comment.updated_by.name) : nil %> | ||
| <tr class="hover:bg-gray-50 align-top"> | ||
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500"><%= comment.created_at.strftime("%-m/%-d/%Y %-I:%M %p") %></td> | ||
| <td class="px-6 py-4 whitespace-nowrap text-sm"> | ||
| <span class="inline-block <%= subject[:badge] %> text-xs px-2 py-0.5 rounded mb-1"><%= subject[:type] %></span> | ||
| <div> | ||
| <% if subject[:path] %> | ||
| <%= link_to subject[:name], subject[:path], class: "text-blue-600 hover:text-blue-800", data: { turbo_frame: "_top" } %> | ||
| <% else %> | ||
| <span class="text-gray-900"><%= subject[:name] %></span> | ||
| <% end %> | ||
| </div> | ||
| </td> | ||
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900"> | ||
| <%= author.presence || "—" %> | ||
| <% if editor %> | ||
| <span class="block text-xs text-gray-400">edited by <%= editor %></span> | ||
| <% end %> | ||
| </td> | ||
| <td class="px-6 py-4 text-sm text-gray-900 max-w-xl"><%= simple_format(comment.body, {}, sanitize: true) %></td> | ||
| </tr> | ||
| <% end %> | ||
| </tbody> | ||
| </table> | ||
| </div> | ||
|
|
||
| <% if @comments.total_pages > 1 %> | ||
| <div class="pagination flex justify-center mt-6"><%= tailwind_paginate @comments %></div> | ||
| <% end %> | ||
| <% else %> | ||
| <p class="text-gray-500 text-center py-6">There are no comments to show yet.</p> | ||
| <% end %> | ||
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 From Claude: Three modes share this action: scoped related overview (full page), global
/commentspreview (no commentable), and the existing bare turbo-frame list for embeds/create — kept intact so the inline comment widgets don't change.