-
Notifications
You must be signed in to change notification settings - Fork 24
WAIT: Add organization status and location filters to registrants list #1839
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/filter-rows-card-org-status
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
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,93 @@ | ||
| # Classifies an event's registrations by how their organization is resolved, | ||
| # mirroring the badge logic in `events/_registrants_results` so the registrants | ||
| # filter and the displayed pills agree: | ||
| # | ||
| # - linked: the registration has at least one linked organization | ||
| # - pending: the registrant submitted an agency name that doesn't match any | ||
| # linked organization (needs admin attention) | ||
| # - none: no linked organization and no submitted agency name | ||
| # | ||
| # The states are not mutually exclusive — a registration can be both linked and | ||
| # pending — so each option returns everyone matching that predicate. | ||
| class EventOrganizationLinkStatus | ||
| STATUSES = %w[linked pending none].freeze | ||
|
|
||
| def initialize(event) | ||
| @event = event | ||
| end | ||
|
|
||
| # Registration ids matching the given status ("linked"/"pending"/"none"). | ||
| # Returns [] for an unrecognized status so callers can scope to nothing. | ||
| def registration_ids_for(status) | ||
| case status.to_s | ||
| when "linked" then linked_registration_ids | ||
| when "pending" then pending_registration_ids | ||
| when "none" then none_registration_ids | ||
| else [] | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| attr_reader :event | ||
|
|
||
| def linked_registration_ids | ||
| registrations.select { |registration| linked_names(registration).present? }.map(&:id) | ||
| end | ||
|
|
||
| def pending_registration_ids | ||
| registrations.select { |registration| needs_linking?(registration) }.map(&:id) | ||
| end | ||
|
|
||
| def none_registration_ids | ||
| registrations.select do |registration| | ||
| linked_names(registration).blank? && submitted_name(registration).blank? | ||
| end.map(&:id) | ||
| end | ||
|
|
||
| def needs_linking?(registration) | ||
| name = submitted_name(registration) | ||
| name.present? && linked_names(registration).exclude?(name.downcase) | ||
| end | ||
|
|
||
| def linked_names(registration) | ||
| linked_names_by_registration.fetch(registration.id, []) | ||
| end | ||
|
|
||
| def submitted_name(registration) | ||
| submitted_names_by_registrant[registration.registrant_id].to_s.strip | ||
| end | ||
|
|
||
| def registrations | ||
| @registrations ||= event.event_registrations.pluck(:id, :registrant_id) | ||
| .map { |id, registrant_id| Registration.new(id, registrant_id) } | ||
| end | ||
|
|
||
| # Linked organization names (lowercased) keyed by registration id. | ||
| def linked_names_by_registration | ||
| @linked_names_by_registration ||= EventRegistrationOrganization | ||
| .joins(:organization) | ||
| .where(event_registration_id: registrations.map(&:id)) | ||
| .pluck(:event_registration_id, Arel.sql("organizations.name")) | ||
| .each_with_object(Hash.new { |hash, key| hash[key] = [] }) do |(registration_id, name), memo| | ||
| memo[registration_id] << name.to_s.strip.downcase | ||
| end | ||
| end | ||
|
|
||
| # Agency name submitted on the registration form, keyed by registrant (person) id. | ||
| def submitted_names_by_registrant | ||
| return @submitted_names_by_registrant if defined?(@submitted_names_by_registrant) | ||
| form = event.registration_form | ||
| field = form&.form_fields&.find_by(field_identifier: "agency_name") | ||
| @submitted_names_by_registrant = if field | ||
| FormAnswer.joins(:form_submission) | ||
| .where(form_submissions: { person_id: registrations.map(&:registrant_id), form_id: form.id }, form_field_id: field.id) | ||
| .pluck(Arel.sql("form_submissions.person_id"), :submitted_answer) | ||
| .to_h | ||
| else | ||
| {} | ||
| end | ||
| end | ||
|
|
||
| Registration = Struct.new(:id, :registrant_id) | ||
| 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,90 +1,132 @@ | ||
| <%= form_with url: registrants_event_path(@event), method: :get, | ||
| data: { controller: "collection", turbo_frame: "registrants_results" }, | ||
| autocomplete: "off", | ||
| class: "flex flex-col md:flex-row md:flex-wrap md:items-end gap-4 mb-6" do %> | ||
| <div class="rounded-lg border border-gray-200 bg-white p-4 shadow-sm mb-6"> | ||
| <%= form_with url: registrants_event_path(@event), method: :get, | ||
| data: { controller: "collection", turbo_frame: "registrants_results" }, | ||
| autocomplete: "off", | ||
| class: "flex flex-col gap-4" do %> | ||
|
|
||
| <%= hidden_field_tag :status_filter, params[:status_filter].presence || "active" %> | ||
| <%= hidden_field_tag :status_filter, params[:status_filter].presence || "active" %> | ||
|
|
||
| <div class="w-full md:flex-1"> | ||
| <%= label_tag :keyword, "Keyword", class: "block text-sm font-medium text-gray-700 mb-1" %> | ||
| <div class="relative"> | ||
| <%= text_field_tag :keyword, params[:keyword], | ||
| <%# Row 1: keyword, organization status, scholarship, payment, attendance %> | ||
| <div class="flex flex-col md:flex-row md:flex-wrap md:items-end gap-4"> | ||
| <div class="w-full md:flex-1 md:min-w-[16rem]"> | ||
| <%= label_tag :keyword, "Keyword", class: "block text-sm font-medium text-gray-700 mb-1" %> | ||
| <div class="relative"> | ||
| <%= text_field_tag :keyword, params[:keyword], | ||
| class: "w-full rounded-lg border border-gray-300 px-3 py-2 text-gray-800 shadow-sm | ||
| focus:border-blue-500 focus:ring focus:ring-blue-200 focus:outline-none", | ||
| placeholder: "Name, email, phone, city, or organization" %> | ||
| <button type="submit" | ||
| class="absolute inset-y-0 right-0 flex items-center pr-3 text-gray-500 hover:text-blue-600"> | ||
| <i class="fa fa-search"></i> | ||
| </button> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div class="w-full md:w-48"> | ||
| <%= label_tag :organization_status, "Organization status", class: "block text-sm font-medium text-gray-700 mb-1" %> | ||
| <%= select_tag :organization_status, | ||
| options_for_select( | ||
| [ [ "Linked", "linked" ], [ "Pending", "pending" ], [ "None", "none" ] ], | ||
| params[:organization_status] | ||
| ), | ||
| include_blank: "All", | ||
| class: "w-full rounded-lg border border-gray-300 px-3 py-2 text-gray-800 shadow-sm | ||
| focus:border-blue-500 focus:ring focus:ring-blue-200 focus:outline-none" %> | ||
| </div> | ||
|
|
||
| <% if @event.cost_cents.to_i > 0 %> | ||
| <div class="w-full md:w-48"> | ||
| <%= label_tag :scholarship, "Scholarship", class: "block text-sm font-medium text-gray-700 mb-1" %> | ||
| <%= select_tag :scholarship, | ||
| options_for_select( | ||
| [ [ "All recipients", "yes" ], [ "Tasks complete", "complete" ], [ "Tasks not complete", "incomplete" ] ], | ||
| params[:scholarship] | ||
| ), | ||
| include_blank: "All registrants", | ||
| class: "w-full rounded-lg border border-gray-300 px-3 py-2 text-gray-800 shadow-sm | ||
| focus:border-blue-500 focus:ring focus:ring-blue-200 focus:outline-none", | ||
| placeholder: "Name, email, phone, city, or organization" %> | ||
| <button type="submit" | ||
| class="absolute inset-y-0 right-0 flex items-center pr-3 text-gray-500 hover:text-blue-600"> | ||
| <i class="fa fa-search"></i> | ||
| </button> | ||
| </div> | ||
| </div> | ||
| focus:border-blue-500 focus:ring focus:ring-blue-200 focus:outline-none" %> | ||
| </div> | ||
|
|
||
| <div class="w-full md:w-48"> | ||
| <%= label_tag :attendance_status, "Attendance status", class: "block text-sm font-medium text-gray-700 mb-1" %> | ||
| <%= select_tag :attendance_status, | ||
| options_for_select( | ||
| EventRegistration::ATTENDANCE_STATUSES.map { |s| [EventRegistration.new(status: s).attendance_status_label, s] }, | ||
| params[:attendance_status] | ||
| ), | ||
| include_blank: "All statuses", | ||
| class: "w-full rounded-lg border border-gray-300 px-3 py-2 text-gray-800 shadow-sm | ||
| focus:border-blue-500 focus:ring focus:ring-blue-200 focus:outline-none" %> | ||
| </div> | ||
| <div class="w-full md:w-48"> | ||
| <%= label_tag :payment_status, "Payment", class: "block text-sm font-medium text-gray-700 mb-1" %> | ||
| <%= select_tag :payment_status, | ||
| options_for_select( | ||
| [ [ "Due", "unpaid" ], [ "Paid", "paid" ], [ "Intends to pay", "intends_to_pay" ] ], | ||
| params[:payment_status] | ||
| ), | ||
| include_blank: "Any payment status", | ||
| class: "w-full rounded-lg border border-gray-300 px-3 py-2 text-gray-800 shadow-sm | ||
| focus:border-blue-500 focus:ring focus:ring-blue-200 focus:outline-none" %> | ||
| </div> | ||
| <% end %> | ||
|
|
||
| <% if @event.cost_cents.to_i > 0 %> | ||
| <div class="w-full md:w-48"> | ||
| <%= label_tag :payment_status, "Payment", class: "block text-sm font-medium text-gray-700 mb-1" %> | ||
| <%= select_tag :payment_status, | ||
| options_for_select( | ||
| [ [ "Due", "unpaid" ], [ "Paid", "paid" ], [ "Intends to pay", "intends_to_pay" ] ], | ||
| params[:payment_status] | ||
| ), | ||
| include_blank: "Any payment status", | ||
| class: "w-full rounded-lg border border-gray-300 px-3 py-2 text-gray-800 shadow-sm | ||
| <div class="w-full md:w-48"> | ||
| <%= label_tag :attendance_status, "Attendance status", class: "block text-sm font-medium text-gray-700 mb-1" %> | ||
| <%= select_tag :attendance_status, | ||
| options_for_select( | ||
| EventRegistration::ATTENDANCE_STATUSES.map { |s| [EventRegistration.new(status: s).attendance_status_label, s] }, | ||
| params[:attendance_status] | ||
| ), | ||
| include_blank: "All statuses", | ||
| class: "w-full rounded-lg border border-gray-300 px-3 py-2 text-gray-800 shadow-sm | ||
| focus:border-blue-500 focus:ring focus:ring-blue-200 focus:outline-none" %> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div class="w-full md:w-48"> | ||
| <%= label_tag :scholarship, "Scholarship", class: "block text-sm font-medium text-gray-700 mb-1" %> | ||
| <%= select_tag :scholarship, | ||
| options_for_select( | ||
| [ [ "All recipients", "yes" ], [ "Tasks complete", "complete" ], [ "Tasks not complete", "incomplete" ] ], | ||
| params[:scholarship] | ||
| ), | ||
| include_blank: "All registrants", | ||
| class: "w-full rounded-lg border border-gray-300 px-3 py-2 text-gray-800 shadow-sm | ||
| focus:border-blue-500 focus:ring focus:ring-blue-200 focus:outline-none" %> | ||
| </div> | ||
| <% end %> | ||
| <%# Row 2: state, locality, county, country %> | ||
| <div class="flex flex-col md:flex-row md:flex-wrap md:items-end gap-4"> | ||
| <% if @dashboard.states.any? %> | ||
| <div class="w-full md:w-48"> | ||
| <%= label_tag :state, "State", class: "block text-sm font-medium text-gray-700 mb-1" %> | ||
| <%= select_tag :state, | ||
| options_for_select(@dashboard.states, params[:state]), | ||
| include_blank: "All states", | ||
| class: "w-full rounded-lg border border-gray-300 px-3 py-2 text-gray-800 shadow-sm | ||
| focus:border-blue-500 focus:ring focus:ring-blue-200 focus:outline-none" %> | ||
| </div> | ||
| <% end %> | ||
|
|
||
| <% if @dashboard.states.any? %> | ||
| <div class="w-full md:w-48"> | ||
| <%= label_tag :state, "State", class: "block text-sm font-medium text-gray-700 mb-1" %> | ||
| <%= select_tag :state, | ||
| options_for_select(@dashboard.states, params[:state]), | ||
| include_blank: "All states", | ||
| class: "w-full rounded-lg border border-gray-300 px-3 py-2 text-gray-800 shadow-sm | ||
| focus:border-blue-500 focus:ring focus:ring-blue-200 focus:outline-none" %> | ||
| </div> | ||
| <% end %> | ||
| <% if @dashboard.localities.any? %> | ||
| <div class="w-full md:w-48"> | ||
| <%= label_tag :locality, "Locality", class: "block text-sm font-medium text-gray-700 mb-1" %> | ||
| <%= select_tag :locality, | ||
| options_for_select(@dashboard.localities, params[:locality]), | ||
| include_blank: "All localities", | ||
| class: "w-full rounded-lg border border-gray-300 px-3 py-2 text-gray-800 shadow-sm | ||
| focus:border-blue-500 focus:ring focus:ring-blue-200 focus:outline-none" %> | ||
| </div> | ||
| <% end %> | ||
|
|
||
| <% if @dashboard.counties.any? %> | ||
| <div class="w-full md:w-48"> | ||
| <%= label_tag :county, "County", class: "block text-sm font-medium text-gray-700 mb-1" %> | ||
| <%= select_tag :county, | ||
| options_for_select( | ||
| @dashboard.counties.map { |state, county| [ "#{state} - #{county}", "#{state}|#{county}" ] }, | ||
| params[:county] | ||
| ), | ||
| include_blank: "All counties", | ||
| class: "w-full rounded-lg border border-gray-300 px-3 py-2 text-gray-800 shadow-sm | ||
| focus:border-blue-500 focus:ring focus:ring-blue-200 focus:outline-none" %> | ||
| <% if @dashboard.counties.any? %> | ||
| <div class="w-full md:w-48"> | ||
| <%= label_tag :county, "County", class: "block text-sm font-medium text-gray-700 mb-1" %> | ||
| <%= select_tag :county, | ||
| options_for_select( | ||
| @dashboard.counties.map { |state, county| [ "#{state} - #{county}", "#{state}|#{county}" ] }, | ||
| params[:county] | ||
| ), | ||
| include_blank: "All counties", | ||
| class: "w-full rounded-lg border border-gray-300 px-3 py-2 text-gray-800 shadow-sm | ||
| focus:border-blue-500 focus:ring focus:ring-blue-200 focus:outline-none" %> | ||
| </div> | ||
| <% end %> | ||
|
|
||
| <% if @dashboard.countries.any? %> | ||
| <div class="w-full md:w-48"> | ||
| <%= label_tag :country, "Country", class: "block text-sm font-medium text-gray-700 mb-1" %> | ||
| <%= select_tag :country, | ||
| options_for_select(@dashboard.countries, params[:country]), | ||
| include_blank: "All countries", | ||
| class: "w-full rounded-lg border border-gray-300 px-3 py-2 text-gray-800 shadow-sm | ||
| focus:border-blue-500 focus:ring focus:ring-blue-200 focus:outline-none" %> | ||
| </div> | ||
| <% end %> | ||
|
|
||
| <div class="w-full md:w-auto md:ml-auto flex items-end justify-end"> | ||
| <%= link_to "Clear filters", registrants_event_path(@event), | ||
| class: "btn btn-utility-outline", | ||
| data: { action: "collection#clearAndSubmit" } %> | ||
| </div> | ||
| </div> | ||
| <% end %> | ||
|
|
||
| <div class="w-full md:w-auto flex justify-end"> | ||
| <%= link_to "Clear filters", registrants_event_path(@event), | ||
| class: "btn btn-utility-outline", | ||
| data: { action: "collection#clearAndSubmit" } %> | ||
| </div> | ||
| <% end %> | ||
| </div> |
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: Overlap is intentional — a registration with a linked org and a non-matching submitted agency name counts as both Linked and Pending, matching the per-row badges. Each filter option returns everyone in that state rather than a single exclusive bucket.