Skip to content

Commit

Permalink
fix: Pagy::OverflowError (#3528)
Browse files Browse the repository at this point in the history
* fix: pagy overflow when reset filters

* fix: Pagy::OverflowError

* revert page 1 on filters reset
  • Loading branch information
Paul-Bob authored Dec 16, 2024
1 parent 42630ec commit 2585b4f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/avo/concerns/pagination.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ def apply_pagination(index_params:, query:, **args)

data_turbo_frame = "data-turbo-frame=\"#{CGI.escapeHTML(params[:turbo_frame]) if params[:turbo_frame]}\""

# Perform pagination and fallback to first page on Pagy::OverflowError
begin
perform_pagination(index_params:, query:, data_turbo_frame:, extra_pagy_params:, **args)
rescue Pagy::OverflowError
index_params[:page] = 1
perform_pagination(index_params:, query:, data_turbo_frame:, extra_pagy_params:, **args)
end
end

private

def perform_pagination(index_params:, query:, data_turbo_frame:, extra_pagy_params:, **args)
send PAGINATION_METHOD[pagination_type.to_sym],
query,
**args,
Expand All @@ -49,8 +61,6 @@ def apply_pagination(index_params:, query:, **args)
size: pagination_hash[:size]
end

private

def pagination_hash
@pagination ||= PAGINATION_DEFAULTS.merge(Avo.configuration.pagination).merge Avo::ExecutionContext.new(
target: pagination,
Expand Down

0 comments on commit 2585b4f

Please sign in to comment.