mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
Merge pull request #13255 from piyush828-design/pagy_upgrade
Upgrade pagy version to latest
This commit is contained in:
2
Gemfile
2
Gemfile
@@ -65,7 +65,7 @@ gem 'oauth2', '~> 1.4.7' # Used for Stripe Connect
|
||||
|
||||
gem 'datafoodconsortium-connector'
|
||||
gem 'jsonapi-serializer'
|
||||
gem 'pagy', '~> 5.1'
|
||||
gem 'pagy', '~> 9'
|
||||
|
||||
gem 'rswag-api'
|
||||
gem 'rswag-ui'
|
||||
|
||||
@@ -495,8 +495,7 @@ GEM
|
||||
validate_url
|
||||
webfinger (~> 2.0)
|
||||
orm_adapter (0.5.0)
|
||||
pagy (5.10.1)
|
||||
activesupport
|
||||
pagy (9.3.4)
|
||||
paper_trail (15.1.0)
|
||||
activerecord (>= 6.1)
|
||||
request_store (~> 1.4)
|
||||
@@ -940,7 +939,7 @@ DEPENDENCIES
|
||||
omniauth_openid_connect
|
||||
openid_connect
|
||||
order_management!
|
||||
pagy (~> 5.1)
|
||||
pagy (~> 9)
|
||||
paper_trail
|
||||
paranoia (~> 2.4)
|
||||
paypal-sdk-merchant (= 1.117.2)
|
||||
|
||||
@@ -138,7 +138,7 @@ module Admin
|
||||
def fetch_products
|
||||
product_query = OpenFoodNetwork::Permissions.new(spree_current_user)
|
||||
.editable_products.merge(product_scope).ransack(ransack_query).result
|
||||
@pagy, @products = pagy(product_query.order(:name), items: @per_page, page: @page,
|
||||
@pagy, @products = pagy(product_query.order(:name), limit: @per_page, page: @page,
|
||||
size: [1, 2, 2, 1])
|
||||
end
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ module Api
|
||||
|
||||
if pagination_required?
|
||||
@pagy, results = pagy(results,
|
||||
items: params[:per_page] || DEFAULT_PER_PAGE)
|
||||
limit: params[:per_page] || DEFAULT_PER_PAGE)
|
||||
end
|
||||
|
||||
serialized_products = ActiveModel::ArraySerializer.new(
|
||||
|
||||
@@ -12,7 +12,7 @@ module Api
|
||||
|
||||
if pagination_required?
|
||||
@pagy, orders = pagy(orders,
|
||||
items: params[:per_page] || default_per_page)
|
||||
limit: params[:per_page] || default_per_page)
|
||||
end
|
||||
|
||||
render json: {
|
||||
|
||||
@@ -78,7 +78,7 @@ module Api
|
||||
end
|
||||
|
||||
def render_paged_products(products, product_serializer = ::Api::Admin::ProductSerializer)
|
||||
@pagy, products = pagy(products, items: params[:per_page] || DEFAULT_PER_PAGE)
|
||||
@pagy, products = pagy(products, limit: params[:per_page] || DEFAULT_PER_PAGE)
|
||||
|
||||
serialized_products = ActiveModel::ArraySerializer.new(
|
||||
products,
|
||||
|
||||
@@ -18,7 +18,7 @@ module Api
|
||||
end
|
||||
|
||||
def index
|
||||
@pagy, customers = pagy(search_customers, pagy_options)
|
||||
@pagy, customers = pagy(search_customers, **pagy_options)
|
||||
|
||||
render json: Api::V1::CustomerSerializer.new(customers, pagination_options)
|
||||
end
|
||||
|
||||
@@ -17,7 +17,7 @@ module Spree
|
||||
|
||||
def index
|
||||
orders = SearchOrders.new(search_params, spree_current_user).orders
|
||||
@pagy, @orders = pagy(orders, items: params[:per_page] || 15)
|
||||
@pagy, @orders = pagy(orders, limit: params[:per_page] || 15)
|
||||
|
||||
update_search_results if searching?
|
||||
end
|
||||
|
||||
@@ -60,7 +60,7 @@ module Spree
|
||||
limit(params[:limit] || 100)
|
||||
else
|
||||
@search = Spree::User.ransack(params[:q])
|
||||
@pagy, @collection = pagy(@search.result, items: Spree::Config[:admin_products_per_page])
|
||||
@pagy, @collection = pagy(@search.result, limit: Spree::Config[:admin_products_per_page])
|
||||
@collection
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,7 +15,7 @@ module Spree
|
||||
params[:q] ||= {}
|
||||
params[:q][:s] ||= "name asc"
|
||||
@search = super.ransack(params[:q])
|
||||
@pagy, @zones = pagy(@search.result, items: Spree::Config[:orders_per_page])
|
||||
@pagy, @zones = pagy(@search.result, limit: Spree::Config[:orders_per_page])
|
||||
@zones
|
||||
end
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@ class ProductsRenderer
|
||||
else
|
||||
distributed_products.products_relation
|
||||
end
|
||||
|
||||
results = filter(results)
|
||||
# Scope results with variant_overrides
|
||||
paginate(results).each { |product| product_scoper.scope(product) }
|
||||
@@ -100,7 +99,7 @@ class ProductsRenderer
|
||||
_pagy, paginated_results = pagy_array(
|
||||
results,
|
||||
page: args[:page] || 1,
|
||||
items: args[:per_page] || DEFAULT_PER_PAGE
|
||||
limit: args[:per_page] || DEFAULT_PER_PAGE
|
||||
)
|
||||
|
||||
paginated_results
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
%form.with-dropdown
|
||||
= t(".pagination.per_page.show")
|
||||
= select_tag :per_page,
|
||||
options_for_select([15, 25, 50, 100].collect{|i| [t('.pagination.per_page.per_page', num: i), i]}, pagy&.items),
|
||||
options_for_select([15, 25, 50, 100].collect{|i| [t('.pagination.per_page.per_page', num: i), i]}, pagy&.limit),
|
||||
class: "no-input per-page",
|
||||
data: { controller: "tom-select search", action: "change->search#changePerPage", "tom-select-options-value": '{ "plugins": [] }'}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
- link = pagy_link_proc(pagy)
|
||||
- link = pagy_anchor(pagy)
|
||||
|
||||
%nav.pagy_nav.pagination{"aria-label" => "pager", :role => "navigation"}
|
||||
- if pagy.prev
|
||||
%span.page.prev!= link.call(pagy.prev, t(:previous), 'aria-label="previous"')
|
||||
%span.page.prev!= link.call(pagy.prev, t(:previous))
|
||||
- else
|
||||
%span.page.prev.disabled!= t(:previous)
|
||||
- pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
||||
@@ -14,6 +14,6 @@
|
||||
- elsif item == :gap # page gap
|
||||
%span.page.gap …
|
||||
- if pagy.next
|
||||
%span.page.next!= link.call(pagy.next, t(:next), 'aria-label="next"')
|
||||
%span.page.next!= link.call(pagy.next, t(:next))
|
||||
- else
|
||||
%span.page.next.disabled!= t(:next)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
- link = pagy_link_proc(pagy)
|
||||
- link = pagy_anchor(pagy)
|
||||
|
||||
.pagination{ "data-controller": "search" }
|
||||
- if pagy.prev
|
||||
@@ -6,9 +6,9 @@
|
||||
- if feature?(:admin_style_v3, spree_current_user)
|
||||
%i.icon-chevron-left{ data: { action: 'click->search#changePage', page: pagy.prev } }
|
||||
- else
|
||||
!= pagy_t('pagy.nav.prev')
|
||||
!= pagy_t('pagy.prev')
|
||||
- else
|
||||
%button.page.disabled{disabled: "disabled"}!= pagy_t('pagy.nav.prev')
|
||||
%button.page.disabled{disabled: "disabled"}!= pagy_t('pagy.prev')
|
||||
|
||||
- pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
||||
- if item.is_a?(Integer) # page link
|
||||
@@ -18,13 +18,13 @@
|
||||
%button.page.current.active= item
|
||||
|
||||
- elsif item == :gap # page gap
|
||||
%span.page.gap.pagination-ellipsis!= pagy_t('pagy.nav.gap')
|
||||
%span.page.gap.pagination-ellipsis!= pagy_t('pagy.gap')
|
||||
|
||||
- if pagy.next
|
||||
%button.page.next{ data: { action: 'click->search#changePage', page: pagy.next } }
|
||||
- if feature?(:admin_style_v3, spree_current_user)
|
||||
%i.icon-chevron-right{ data: { action: 'click->search#changePage', page: pagy.next } }
|
||||
- else
|
||||
!= pagy_t('pagy.nav.next')
|
||||
!= pagy_t('pagy.next')
|
||||
- else
|
||||
%button.page.disabled.pagination-next{disabled: "disabled"}!= pagy_t('pagy.nav.next')
|
||||
%button.page.disabled.pagination-next{disabled: "disabled"}!= pagy_t('pagy.next')
|
||||
|
||||
@@ -2,18 +2,19 @@
|
||||
|
||||
require 'pagy/extras/arel'
|
||||
require 'pagy/extras/array'
|
||||
require 'pagy/extras/items'
|
||||
require 'pagy/extras/limit'
|
||||
require 'pagy/extras/overflow'
|
||||
require 'pagy/extras/size'
|
||||
|
||||
# Pagy Variables
|
||||
# See https://ddnexus.github.io/pagy/api/pagy#variables
|
||||
Pagy::DEFAULT[:items] = 100
|
||||
Pagy::DEFAULT[:limit] = 100
|
||||
|
||||
# Items extra: Allow the client to request a custom number of items per page with an optional
|
||||
# limit extra: Allow the client to request a custom number of limit per page with an optional
|
||||
# selector UI
|
||||
# See https://ddnexus.github.io/pagy/extras/items
|
||||
Pagy::DEFAULT[:items_param] = :per_page
|
||||
Pagy::DEFAULT[:max_items] = 100
|
||||
# See https://ddnexus.github.io/pagy/extras/limit
|
||||
Pagy::DEFAULT[:limit_param] = :per_page
|
||||
Pagy::DEFAULT[:limit_max] = 100
|
||||
|
||||
# For handling requests for non-existant pages eg: page 35 when there are only 4 pages of results
|
||||
Pagy::DEFAULT[:overflow] = :empty_page
|
||||
|
||||
@@ -133,7 +133,7 @@ RSpec.describe "Customers", type: :request, swagger_doc: "v1.yaml", feature: :ap
|
||||
it "informs about invalid pages" do
|
||||
get "/api/v1/customers", params: { page: "0" }
|
||||
expect(json_response_ids).to eq nil
|
||||
expect(json_error_detail).to eq 'expected :page >= 1; got "0"'
|
||||
expect(json_error_detail).to eq "expected :page >= 1; got 0"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user