diff --git a/app/controllers/admin/claims_controller.rb b/app/controllers/admin/claims_controller.rb index 6f26e3cb2a..9787b588ea 100644 --- a/app/controllers/admin/claims_controller.rb +++ b/app/controllers/admin/claims_controller.rb @@ -5,23 +5,15 @@ class Admin::ClaimsController < Admin::BaseAdminController def index @filter_form = Admin::ClaimsFilterForm.new( - team_member: params[:team_member], - policy: params[:policy], - status: params[:status] + filters: filter_params, + session: ) + @filter_form.save_to_session! - @total_claim_count = @filter_form.count @pagy, @claims = pagy(@filter_form.claims) respond_to do |format| - format.html { - claims_backlink_path!(admin_claims_path( - team_member: params[:team_member], - policy: params[:policy], - status: params[:status], - commit: params[:commit] - )) - } + format.html format.csv { # "Download report request file" button (doesn't use the filters) report_request_claims = Claim.includes(:decisions).awaiting_decision @@ -82,4 +74,10 @@ def claims_backlink_path!(source_path) def hold_params params.require(:hold).permit(:body).merge(claim: @claim) end + + def filter_params + params + .fetch(:filter, {}) + .permit(:team_member, :policy, :status, :reset) + end end diff --git a/app/forms/admin/claims_filter_form.rb b/app/forms/admin/claims_filter_form.rb index 524874e267..9e37bb314e 100644 --- a/app/forms/admin/claims_filter_form.rb +++ b/app/forms/admin/claims_filter_form.rb @@ -2,9 +2,40 @@ class Admin::ClaimsFilterForm include ActiveModel::Model include ActiveModel::Attributes - attribute :team_member, :string - attribute :policy, :string - attribute :status, :string + attribute :filters + attribute :session + + def initialize(args) + super + + session[:filter] ||= {} + end + + def team_member + return if reset? + + @team_member ||= filters[:team_member] || session[:filter]["team_member"] + end + + def policy + return if reset? + + @policy ||= filters[:policy] || session[:filter]["policy"] + end + + def status + return if reset? + + @status ||= filters[:status] || session[:filter]["status"] + end + + def filters_applied? + team_member.present? || policy.present? || status.present? + end + + def reset? + filters[:reset].present? + end def claims return @claims if @claims @@ -45,6 +76,47 @@ def count claims.count end + def policy_select_options + array = [OpenStruct.new(id: nil, name: "All")] + + array + Policies.all.map do |policy| + OpenStruct.new(id: policy.policy_type, name: policy.short_name) + end + end + + def status_select_options + [ + ["Awaiting decision - not on hold", nil], + ["Awaiting provider verification", "awaiting_provider_verification"], + ["Awaiting decision - on hold", "held"], + ["Awaiting decision - failed bank details", "failed_bank_validation"], + ["Approved awaiting QA", "approved_awaiting_qa"], + ["Approved awaiting payroll", "approved_awaiting_payroll"], + ["Automatically approved awaiting payroll", "automatically_approved_awaiting_payroll"], + ["Approved", "approved"], + ["Rejected", "rejected"] + ].map do |name, id| + OpenStruct.new(id:, name:) + end + end + + def team_member_select_options + array = [["All", nil], ["Unassigned", "unassigned"]] + array += DfeSignIn::User.options_for_select + + array.map do |name, id| + OpenStruct.new(id:, name:) + end + end + + def save_to_session! + session[:filter] = { + team_member:, + policy:, + status: + } + end + private def approved_awaiting_payroll diff --git a/app/helpers/admin/claims_helper.rb b/app/helpers/admin/claims_helper.rb index 37c76943d7..49e98b2c2b 100644 --- a/app/helpers/admin/claims_helper.rb +++ b/app/helpers/admin/claims_helper.rb @@ -189,21 +189,6 @@ def status(claim) end end - STATUS_FILTERS = [ - ["Awaiting provider verification", "awaiting_provider_verification"], - ["Awaiting decision - on hold", "held"], - ["Awaiting decision - failed bank details", "failed_bank_validation"], - ["Approved awaiting QA", "approved_awaiting_qa"], - ["Approved awaiting payroll", "approved_awaiting_payroll"], - ["Automatically approved awaiting payroll", "automatically_approved_awaiting_payroll"], - ["Approved", "approved"], - ["Rejected", "rejected"] - ] - - def claim_status_filters - STATUS_FILTERS - end - def index_status_filter(status) return "awaiting a decision" unless status.present? diff --git a/app/views/admin/claims/index.html.erb b/app/views/admin/claims/index.html.erb index 2d50ef1ff0..4802e5db41 100644 --- a/app/views/admin/claims/index.html.erb +++ b/app/views/admin/claims/index.html.erb @@ -18,34 +18,29 @@ <%= render "allocations_form" %> -

Filter claims

+

Filter claims

- <%= form_with url: admin_claims_path, method: :get do |form| %> -
+ <%= form_with model: @filter_form, scope: "filter", url: admin_claims_path(anchor: "filter"), method: :get, builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> +
- - <%= form.select :team_member, options_for_select(DfeSignIn::User.options_for_select.unshift(["Unassigned", "unassigned"]), params[:team_member]), {include_blank: "All"}, class: "govuk-select" %> + <%= f.govuk_collection_select :team_member, @filter_form.team_member_select_options, :id, :name, label: { text: "Team member" } %>
+
- - <%= form.select :policy, options_for_select(Policies.options_for_select, params[:policy]), {include_blank: "All"}, class: "govuk-select" %> + <%= f.govuk_collection_select :policy, @filter_form.policy_select_options, :id, :name %>
+
- - <%= form.select :status, options_for_select(claim_status_filters, params[:status]), {include_blank: "Awaiting decision - not on hold"}, class: "govuk-select" %> + <%= f.govuk_collection_select :status, @filter_form.status_select_options, :id, :name %>
+
- <%= form.submit "Apply filters", class: "govuk-button govuk-button--secondary admin-filter-group__button" %> - <% if params[:commit].present? %> - <%= link_to "Clear filters", admin_claims_path, class: "button-link admin-filter-group__button" %> + <%= f.govuk_submit "Apply filters", secondary: true, class: "admin-filter-group__button" %> + + <% if @filter_form.filters_applied? %> + <%= govuk_link_to "Clear filters", admin_claims_path(filter: {reset: true}, anchor: "filter"), class: "button-link admin-filter-group__button" %> <% else %> - <%= form.submit "Clear filters", type: "reset", class: "button-link admin-filter-group__button" %> + <%= f.submit "Clear filters", type: "reset", class: "button-link admin-filter-group__button" %> <% end %>
@@ -54,7 +49,7 @@ <% if @claims.any? %> <% claims_with_warning = Claim.approaching_decision_deadline.count + Claim.passed_decision_deadline.count %> -

<%= pluralize(@total_claim_count, "claim") %> <%= index_status_filter(params[:status]) %>

+

<%= pluralize(@filter_form.count, "claim") %> <%= index_status_filter(@filter_form.status) %>

diff --git a/spec/features/admin/admin_claims_filtering_spec.rb b/spec/features/admin/admin_claims_filtering_spec.rb index 926d988014..116d3ec608 100644 --- a/spec/features/admin/admin_claims_filtering_spec.rb +++ b/spec/features/admin/admin_claims_filtering_spec.rb @@ -57,7 +57,7 @@ expect(page).to have_selector("td[text()='FE']", count: 2) click_on "View claims" - select "Student Loans", from: "policy" + select "Student Loans", from: "filter-policy-field" click_on "Apply filters" student_loan_claims.each do |c| @@ -80,9 +80,9 @@ expect(page).to have_selector("td[text()='ECP']", count: 10) # Excludes payroll users and deleted users - expect(page).to have_select("team_member", options: ["All", "Unassigned", "#{user.given_name} #{user.family_name}", "Mary Wasu Wabi", "Valentino Ricci", "Mette Jørgensen"]) + expect(page).to have_select("filter-team-member-field", options: ["All", "Unassigned", "#{user.given_name} #{user.family_name}", "Mary Wasu Wabi", "Valentino Ricci", "Mette Jørgensen"]) - select "Mette Jørgensen", from: "team_member" + select "Mette Jørgensen", from: "filter-team-member-field" click_on "Apply filters" expect_page_to_show_claims( @@ -92,15 +92,15 @@ ) # Assigned to Mette - select "Mette Jørgensen", from: "team_member" - select "Approved", from: "Status:" + select "Mette Jørgensen", from: "filter-team-member-field" + select "Approved", from: "filter-status-field" click_on "Apply filters" expect(page).to have_content("1 claim approved") expect_page_to_show_claims(approved_claim) # Approved by Mary - select "Mary Wasu Wabi", from: "team_member" - select "Approved", from: "Status:" + select "Mary Wasu Wabi", from: "filter-team-member-field" + select "Approved", from: "filter-status-field" click_on "Apply filters" expect(page).to have_content("1 claim approved") expect(page).to have_content(approved_claim.reference) @@ -108,7 +108,7 @@ scenario "filter unassigned claims" do click_on "View claims" - select "Unassigned", from: "team_member" + select "Unassigned", from: "filter-team-member-field" click_on "Apply filters" expect(page).to have_selector("td[text()='STRI']", count: 2) @@ -129,36 +129,36 @@ further_education_claims_provider_verification_email_not_sent ) - select "Awaiting provider verification", from: "Status:" + select "Awaiting provider verification", from: "filter-status-field" click_button "Apply filters" expect_page_to_show_claims(further_education_claims_awaiting_provider_verification) - select "Awaiting decision - on hold", from: "Status:" + select "Awaiting decision - on hold", from: "filter-status-field" click_button "Apply filters" expect_page_to_show_claims(held_claims) - select "Awaiting decision - failed bank details", from: "Status:" + select "Awaiting decision - failed bank details", from: "filter-status-field" click_button "Apply filters" expect_page_to_show_claims(early_career_payments_claims_failed_bank_validation) - select "Approved awaiting QA", from: "Status:" + select "Approved awaiting QA", from: "filter-status-field" click_button "Apply filters" expect_page_to_show_claims(approved_awaiting_qa_claims) - select "Approved awaiting payroll", from: "Status:" + select "Approved awaiting payroll", from: "filter-status-field" click_button "Apply filters" expect_page_to_show_claims(auto_approved_awaiting_payroll_claims, approved_claim) - select "Automatically approved awaiting payroll", from: "Status:" + select "Automatically approved awaiting payroll", from: "filter-status-field" click_button "Apply filters" expect_page_to_show_claims(auto_approved_awaiting_payroll_claims) - select "Rejected", from: "Status:" + select "Rejected", from: "filter-status-field" click_button "Apply filters" expect_page_to_show_claims(rejected_claim) end diff --git a/spec/features/admin/admin_view_claim_further_education_payments_spec.rb b/spec/features/admin/admin_view_claim_further_education_payments_spec.rb index 469615e50f..05874b43c0 100644 --- a/spec/features/admin/admin_view_claim_further_education_payments_spec.rb +++ b/spec/features/admin/admin_view_claim_further_education_payments_spec.rb @@ -77,19 +77,21 @@ end scenario "Awaiting provider verification claim status" do - visit admin_claims_path(status: "awaiting_provider_verification") + visit admin_claims_path(filter: {status: "awaiting_provider_verification"}) find("a[href='#{admin_claim_tasks_path(claim_not_verified)}']").click expect(page).to have_content("Awaiting provider verification") visit admin_claims_path + click_link "Clear filters" find("a[href='#{admin_claim_tasks_path(claim_with_duplicates_no_provider_email_sent)}']").click expect(page).to have_content("Awaiting decision - not on hold") - visit admin_claims_path(status: "awaiting_provider_verification") + visit admin_claims_path(filter: {status: "awaiting_provider_verification"}) find("a[href='#{admin_claim_tasks_path(claim_with_duplicates_provider_email_sent)}']").click expect(page).to have_content("Awaiting provider verification") visit admin_claims_path + click_link "Clear filters" find("a[href='#{admin_claim_tasks_path(verified_claim)}']").click expect(page).to have_content("Awaiting decision - not on hold") end diff --git a/spec/helpers/admin/claims_helper_spec.rb b/spec/helpers/admin/claims_helper_spec.rb index dc65513444..43f7303c1c 100644 --- a/spec/helpers/admin/claims_helper_spec.rb +++ b/spec/helpers/admin/claims_helper_spec.rb @@ -542,14 +542,6 @@ end end - describe "#claim_status_filters" do - subject { helper.claim_status_filters } - - it "returns the list of status filters available" do - is_expected.to eq(described_class::STATUS_FILTERS) - end - end - describe "#index_status_filter" do subject { helper.index_status_filter(status) } diff --git a/spec/requests/admin/admin_claims_spec.rb b/spec/requests/admin/admin_claims_spec.rb index f7c6fce3de..1eed95cdb3 100644 --- a/spec/requests/admin/admin_claims_spec.rb +++ b/spec/requests/admin/admin_claims_spec.rb @@ -27,7 +27,7 @@ it "can filter by policy" do early_career_payments_claims = create_list(:claim, 3, :submitted, policy: Policies::EarlyCareerPayments) - get admin_claims_path, params: {policy: "early-career-payments"} + get admin_claims_path, params: {filter: {policy: "early-career-payments"}} early_career_payments_claims.each do |c| expect(response.body).to include(c.reference) @@ -75,7 +75,7 @@ c.save } - get admin_claims_path, params: {team_member: mette.id} + get admin_claims_path, params: {filter: {team_member: mette.id}} [ student_loans_claims_for_mette, diff --git a/spec/support/admin_view_claim_feature_shared_examples.rb b/spec/support/admin_view_claim_feature_shared_examples.rb index e8b54eb2f9..7a7e57068f 100644 --- a/spec/support/admin_view_claim_feature_shared_examples.rb +++ b/spec/support/admin_view_claim_feature_shared_examples.rb @@ -92,7 +92,7 @@ travel_to(@within_academic_year) do visit admin_claims_path - select "Approved awaiting payroll", from: "Status" + select "Approved awaiting payroll", from: "filter-status-field" click_on "Apply filters" find("a[href='#{admin_claim_tasks_path(approved_awaiting_payroll_claim)}']").click @@ -106,7 +106,7 @@ travel_to(@within_academic_year) do visit admin_claims_path - select "Approved", from: "Status" + select "Approved", from: "filter-status-field" click_on "Apply filters" find("a[href='#{admin_claim_tasks_path(approved_paid_claim)}']").click @@ -119,7 +119,7 @@ travel_to(@within_academic_year) do visit admin_claims_path - select "Rejected", from: "Status" + select "Rejected", from: "filter-status-field" click_on "Apply filters" find("a[href='#{admin_claim_tasks_path(rejected_claim)}']").click