From f825c2bbdb7b7c715c8c6c4a1948a18a85a2466f Mon Sep 17 00:00:00 2001 From: Mark Whitaker Date: Thu, 19 Dec 2024 11:26:54 +0000 Subject: [PATCH] Use Pagy on caseworker admin allocation pages Replaces the uses of the Kaminari gem for pagination with Pagy on the caseworker allocation pages. This is more complex than the change to the provider claims pages due to the way claims data is fetched from the API. Pagination is currently done by the API, so it is necessary to make changes there too. Similar to the previous commit it is necessary to create a new Pagy object in the CaseWorkers::Admin::AllocationsController based on pagination data received from the API. This also fixes a bug(?) where the `sort_and_paginate` method was never being called in that controller. --- .rubocop_todo.yml | 5 +++-- .../case_workers/admin/allocations_controller.rb | 9 ++++++++- .../admin/allocations/_re_allocation.html.haml | 2 +- app/views/case_workers/admin/allocations/new.html.haml | 3 ++- .../case_workers/admin/allocations_controller_spec.rb | 9 +++++---- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b3829242d2..ee9e186f67 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 1000` -# on 2024-11-28 09:38:38 UTC using RuboCop version 1.69.0. +# on 2024-12-19 12:25:56 UTC using RuboCop version 1.69.2. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -244,10 +244,11 @@ Metrics/AbcSize: - 'spec/support/seed_helpers.rb' - 'spec/support/validation_helpers.rb' -# Offense count: 19 +# Offense count: 20 # Configuration parameters: CountComments, Max, CountAsOne. Metrics/ClassLength: Exclude: + - 'app/controllers/case_workers/claims_controller.rb' - 'app/controllers/external_users/claims_controller.rb' - 'app/interfaces/api/entities/search_result.rb' - 'app/interfaces/api/v1/dropdown_data.rb' diff --git a/app/controllers/case_workers/admin/allocations_controller.rb b/app/controllers/case_workers/admin/allocations_controller.rb index c00574f9b1..65dcf08afb 100644 --- a/app/controllers/case_workers/admin/allocations_controller.rb +++ b/app/controllers/case_workers/admin/allocations_controller.rb @@ -7,6 +7,7 @@ class AllocationsController < CaseWorkers::Admin::ApplicationController before_action :set_claims, only: %i[new create] before_action :set_summary_values, only: [:new], if: :summary_from_previous_request? before_action :process_claim_ids, only: [:create], if: :quantity_allocation? + before_action :sort_and_paginate def new @allocation = Allocation.new @@ -88,7 +89,13 @@ def search_claims(states = nil) end def sort_and_paginate - @claims = @claims.sort_using(sort_column, sort_direction).page(current_page).per(page_size) + @claims = @claims.sort_using(sort_column, sort_direction) unless @claims.remote? + @pagy = Pagy.new( + count: @claims.total_count, + limit: @claims.limit_value, + page: @claims.current_page, + pages: @claims.total_pages + ) end def allocation_params diff --git a/app/views/case_workers/admin/allocations/_re_allocation.html.haml b/app/views/case_workers/admin/allocations/_re_allocation.html.haml index 2f1c6d5c77..54479f4e00 100644 --- a/app/views/case_workers/admin/allocations/_re_allocation.html.haml +++ b/app/views/case_workers/admin/allocations/_re_allocation.html.haml @@ -35,7 +35,7 @@ .govuk-grid-column-one-half = t('.re_allocation') .govuk-grid-column-one-half.claim-count{ class: 'govuk-!-text-align-right' } - = t('.number_of_claims', claim_count: @claims.total_count) + = pagy_info(@pagy).html_safe = govuk_table_thead do = govuk_table_row do diff --git a/app/views/case_workers/admin/allocations/new.html.haml b/app/views/case_workers/admin/allocations/new.html.haml index 4d203f581e..db4c8b5dde 100644 --- a/app/views/case_workers/admin/allocations/new.html.haml +++ b/app/views/case_workers/admin/allocations/new.html.haml @@ -13,4 +13,5 @@ .js-re-allocation-page = render partial: 're_allocation' - = paginate @claims + %nav.pagination.app-pagintion--inline + = pagy_nav(@pagy).html_safe diff --git a/spec/controllers/case_workers/admin/allocations_controller_spec.rb b/spec/controllers/case_workers/admin/allocations_controller_spec.rb index d9c0dafb49..90cda475b8 100644 --- a/spec/controllers/case_workers/admin/allocations_controller_spec.rb +++ b/spec/controllers/case_workers/admin/allocations_controller_spec.rb @@ -2,15 +2,16 @@ RSpec.describe CaseWorkers::Admin::AllocationsController do before(:all) do - # create(:graduated_fee_type, code: 'GTRL') #use seeded case types 'real' fee type codes - # load '#{Rails.root}/db/seeds/case_types.rb' @case_worker = create(:case_worker) @admin = create(:case_worker, :admin) end after(:all) { clean_database } - before { sign_in @admin.user } + before do + sign_in @admin.user + allow(claims_collection).to receive_messages(total_count: 15, total_pages: 2, limit_value: 10, current_page: 1) + end let(:tab) { nil } # default tab is 'unallocated' when tab not provided @@ -30,7 +31,7 @@ direction: 'asc', scheme: 'agfs', filter: 'all', - page: 0, + page: 1, limit: 25, search: nil, value_band_id: 0