Skip to content

Commit

Permalink
Use Pagy on caseworker admin allocation pages
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mpw5 committed Dec 20, 2024
1 parent 6866272 commit f825c2b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
5 changes: 3 additions & 2 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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'
Expand Down
9 changes: 8 additions & 1 deletion app/controllers/case_workers/admin/allocations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion app/views/case_workers/admin/allocations/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
.js-re-allocation-page
= render partial: 're_allocation'

= paginate @claims
%nav.pagination.app-pagintion--inline
= pagy_nav(@pagy).html_safe
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -30,7 +31,7 @@
direction: 'asc',
scheme: 'agfs',
filter: 'all',
page: 0,
page: 1,
limit: 25,
search: nil,
value_band_id: 0
Expand Down

0 comments on commit f825c2b

Please sign in to comment.