Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/controllers/scholarships_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def index
{ grant: :donor },
{ recipient: [ { affiliations: { organization: :addresses } }, { event_registrations: :event } ] }
)
if params[:recipient_id].present?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ€– From Claude: The scholarships index previously only grouped by funder with no per-recipient view, so this adds a recipient_id filter (applied before grouping) so the person-edit card lands on just that person's awards.

scholarships = scholarships.where(recipient_id: params[:recipient_id])
@recipient = Person.find_by(id: params[:recipient_id])
end
@funder_groups = ScholarshipsGrouping.new(scholarships).funder_groups
@scholarships_count = scholarships.size
end
Expand Down
4 changes: 3 additions & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ def form_field_option_source(field)
people: "fa-user",
organizations: "fa-building",
workshops: "fa-chalkboard-user",
resources: "fa-book"
resources: "fa-book",
scholarships: "fa-graduation-cap",
notifications: "fa-bell"
}.freeze

# Themed card-style link to a filtered index. The collection drives the
Expand Down
9 changes: 9 additions & 0 deletions app/views/people/_associated_records.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<% return unless person.persisted? %>
<% email = person.preferred_email %>
<% notifications = email.present? ? Notification.email(email) : Notification.none %>
<ul class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-x-6 gap-y-2">
<li><%= index_button person.event_registrations, params: { registrant_id: person.id } %></li>

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ€– From Claude: Only these two records get cards because they have person-scoped destinations: registrations filter on registrant_id, and workshop_logs_person_path is the per-person view. Scholarships/grants/form-submissions have no person-filtered index, so a card would land on an unfiltered list β€” omitted intentionally.

<li><%= index_button(person.user&.workshop_logs || WorkshopLog.none, path: workshop_logs_person_path(person)) %></li>
<li><%= index_button person.scholarships, params: { recipient_id: person.id } %></li>
<li><%= index_button notifications, params: { email: email } %></li>
</ul>
12 changes: 12 additions & 0 deletions app/views/people/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,18 @@
</div>
</div>

<% if f.object.persisted? %>
<% person = f.object.respond_to?(:object) ? f.object.object : f.object %>
<div class="form-group space-y-4 mb-8">
<div class="font-semibold text-gray-700 mb-2">
Associated records
</div>
<div class="rounded-lg border border-gray-200 bg-gray-50 p-4 mb-4 shadow-sm">
<%= render "associated_records", person: person %>
</div>
</div>
<% end %>

<% if f.object.persisted? %>
<!-- Comments -->
<% if allowed_to?(:manage?, Comment) %>
Expand Down
6 changes: 6 additions & 0 deletions app/views/scholarships/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
</div>
</div>

<% if @recipient %>
<div class="mb-4 flex items-center gap-2 text-sm text-gray-600">
<span>Filtered to <span class="font-medium text-gray-900"><%= @recipient.name %></span></span>
<%= link_to "Clear", scholarships_path, class: "text-blue-600 hover:underline" %>
</div>
<% end %>
<% if @funder_groups.any? %>
<div class="space-y-4">
<%= render partial: "funder_group", collection: @funder_groups, as: :funder_group %>
Expand Down
26 changes: 26 additions & 0 deletions spec/requests/people_associated_records_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require "rails_helper"

RSpec.describe "Person edit associated records", type: :request do
let(:admin) { create(:user, :admin) }

before { sign_in admin }

describe "GET /people/:id/edit" do
it "links to the person's filtered registrations, workshop logs, scholarships, and notifications" do
person = create(:person)
create(:event_registration, registrant: person)
create(:workshop_log, created_by: person.user)
create(:scholarship, recipient: person)
create(:notification, recipient_email: person.preferred_email)

get edit_person_path(person)

expect(response).to have_http_status(:ok)
expect(response.body).to include("Associated records")
expect(response.body).to include(event_registrations_path(registrant_id: person.id))
expect(response.body).to include(workshop_logs_person_path(person))
expect(response.body).to include(scholarships_path(recipient_id: person.id))
expect(response.body).to include(notifications_path(email: person.preferred_email))
end
end
end
13 changes: 13 additions & 0 deletions spec/requests/scholarships_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,19 @@

expect(response.body).to include(grant_path(grant, from_scholarships: true))
end

it "filters to a single recipient when recipient_id is given" do
recipient = create(:person, first_name: "Carmen", last_name: "Gomez")
other = create(:person, first_name: "Jane", last_name: "Doe")
create(:scholarship, recipient: recipient)
create(:scholarship, recipient: other)

get scholarships_path(recipient_id: recipient.id)

expect(response.body).to include("Filtered to")
expect(response.body).to include("Carmen Gomez")
expect(response.body).not_to include("Jane Doe")
end
end
end

Expand Down