Skip to content

Commit

Permalink
Fix jsonapi with keyset
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Jul 27, 2024
1 parent ef7c052 commit 8c21069
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
9 changes: 3 additions & 6 deletions gem/lib/pagy/extras/jsonapi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def pagy_skip_jsonapi?(vars)
# Override the Backend method
def pagy_get_page(vars)
return super if pagy_skip_jsonapi?(vars)
return if params[:page].nil?
return unless params[:page]

params[:page][vars[:page_param] || DEFAULT[:page_param]]
end
Expand All @@ -61,7 +61,7 @@ module LimitExtraOverride
# Override the LimitExtra::Backend method
def pagy_get_limit_param(vars)
return super if pagy_skip_jsonapi?(vars)
return if params[:page].nil?
return unless params[:page]

params[:page][vars[:limit_param] || DEFAULT[:limit_param]]
end
Expand All @@ -77,11 +77,8 @@ def pagy_set_query_params(page, vars, query_params)
return super unless vars[:jsonapi]

query_params['page'] ||= {}
query_params['page'][vars[:page_param].to_s] = page if page
query_params['page'][vars[:page_param].to_s] = page
query_params['page'][vars[:limit_param].to_s] = vars[:limit] if vars[:limit_extra]
# :nocov:
query_params.delete(:page) if query_params['page'].empty?
# :nocov:
end
end
UrlHelpers.prepend UrlHelperOverride
Expand Down
4 changes: 2 additions & 2 deletions test/pagy/extras/jsonapi_test.rb.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
pagy/extras/jsonapi___pagy_jsonapi_links_(keyset)_test_0002_sets_the_next_value_to_null_when_the_link_is_unavailable:
:keyset_result:
:first: "/foo?page%5Bsize%5D=50"
:first: "/foo?page%5Bsize%5D=50&page%5Blatest%5D"
:last:
:prev:
:next:
pagy/extras/jsonapi___pagy_jsonapi_links_(keyset)_test_0001_returns_the_ordered_links:
:keyset_result:
:first: "/foo?page%5Blatest%5D=eyJpZCI6MTB9&page%5Bsize%5D=10"
:first: "/foo?page%5Blatest%5D&page%5Bsize%5D=10"
:last:
:prev:
:next: "/foo?page%5Blatest%5D=eyJpZCI6MjB9&page%5Bsize%5D=10"
Expand Down

0 comments on commit 8c21069

Please sign in to comment.