diff --git a/app/controllers/admin/products_v3_controller.rb b/app/controllers/admin/products_v3_controller.rb index 1750083cea..ff5973fc49 100644 --- a/app/controllers/admin/products_v3_controller.rb +++ b/app/controllers/admin/products_v3_controller.rb @@ -43,8 +43,8 @@ module Admin def init_pagination_params # prority is given to element dataset (if present) over url params - @page = params[:_page].presence || 1 - @per_page = params[:_per_page].presence || 15 + @page = params[:page].presence || 1 + @per_page = params[:per_page].presence || 15 end def producers diff --git a/app/reflexes/products_reflex.rb b/app/reflexes/products_reflex.rb index 66a5ca17e7..9cad290331 100644 --- a/app/reflexes/products_reflex.rb +++ b/app/reflexes/products_reflex.rb @@ -5,10 +5,6 @@ class ProductsReflex < ApplicationReflex before_reflex :init_filters_params, :init_pagination_params - def fetch - fetch_and_render_products_with_flash - end - def change_per_page @per_page = element.value.to_i @page = 1 diff --git a/app/views/admin/products_v3/_content.html.haml b/app/views/admin/products_v3/_content.html.haml index b805747b71..b9a5625e84 100644 --- a/app/views/admin/products_v3/_content.html.haml +++ b/app/views/admin/products_v3/_content.html.haml @@ -13,7 +13,7 @@ = render partial: 'sort', locals: { pagy: pagy, search_term: search_term, producer_id: producer_id, category_id: category_id } = render partial: 'table', locals: { products: products } - if pagy.pages > 1 - = render partial: 'admin/shared/v3/pagy', locals: { pagy: pagy, reflex: "click->Products#fetch" } + = render partial: 'admin/shared/stimulus_pagination', locals: { pagy: pagy } - else #no-products = render partial: "no_products", locals: { search_term: search_term, producer_id: producer_id, category_id: category_id } diff --git a/app/views/admin/products_v3/_filters.html.haml b/app/views/admin/products_v3/_filters.html.haml index c8b173aea7..ec13f12c90 100644 --- a/app/views/admin/products_v3/_filters.html.haml +++ b/app/views/admin/products_v3/_filters.html.haml @@ -1,4 +1,7 @@ -%form{ id: "filters" } += form_with url: admin_products_path, id: "filters", method: :get, data: { remote: false, "search-target": "form" } do + = hidden_field_tag :page, @page, class: "page" + = hidden_field_tag :per_page, @per_page, class: "per-page" + .query .search-input = text_field_tag :search_term, search_term, placeholder: t('.search_products') diff --git a/app/views/admin/products_v3/_sort.html.haml b/app/views/admin/products_v3/_sort.html.haml index f0de4b76d4..848710fe58 100644 --- a/app/views/admin/products_v3/_sort.html.haml +++ b/app/views/admin/products_v3/_sort.html.haml @@ -2,8 +2,11 @@ %div = t(".pagination.total_html", total: pagy.count, from: pagy.from, to: pagy.to) - if search_term.present? || producer_id.present? || category_id.present? - %a{ href: "#", class: "button disruptive" } + %a{ href: url_for(per_page: @per_page, page: @page), class: "button disruptive" } = t(".pagination.clear_search") %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), class: "no-input per-page", data: { reflex: "change->products#change_per_page", controller: "tom-select", "tom-select-options-value": '{ "plugins": [] }'} + = select_tag :per_page, + options_for_select([15, 25, 50, 100].collect{|i| [t('.pagination.per_page.per_page', num: i), i]}, pagy.items), + class: "no-input per-page", + data: { controller: "tom-select search", action: "change->search#changePerPage", "tom-select-options-value": '{ "plugins": [] }'} diff --git a/app/views/admin/products_v3/_table.html.haml b/app/views/admin/products_v3/_table.html.haml index bf7154de84..4a34b81258 100644 --- a/app/views/admin/products_v3/_table.html.haml +++ b/app/views/admin/products_v3/_table.html.haml @@ -5,8 +5,8 @@ } } do |form| = render(partial: "admin/shared/flashes", locals: { flashes: }) if defined? flashes - = hidden_field_tag :_page, @page - = hidden_field_tag :_per_page, @per_page + = hidden_field_tag :page, @page + = hidden_field_tag :per_page, @per_page %table.products %colgroup diff --git a/app/views/admin/shared/v3/_pagy.html.haml b/app/views/admin/shared/v3/_pagy.html.haml deleted file mode 100644 index 6456fae45a..0000000000 --- a/app/views/admin/shared/v3/_pagy.html.haml +++ /dev/null @@ -1,15 +0,0 @@ -%nav.pagy_nav.pagination{"aria-label" => "pager", :role => "navigation"} - - if pagy.prev - %a.page.prev{ href: "#", id: "pagy-prev", "data-reflex": reflex, "data-perPage": pagy.items, "data-page": pagy.prev || 1, "aria-label": "previous"} - %i.icon-chevron-left - - pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36] - - if item.is_a?(Integer) # page link - %a.page{ href: "#", id:"pagy-#{item}", "data-reflex": reflex, "data-perPage": pagy.items, "data-page": item, "aria-label": "page #{item}"} - = item - - elsif item.is_a?(String) # current page - %span.page.current= item - - elsif item == :gap # page gap - %span.page.gap … - - if pagy.next - %a.page.next{ href: "#", id:"pagy-next", "data-reflex": reflex, "data-perPage": pagy.items, "data-page": pagy.next || pagy.last, "aria-label": "next"} - %i.icon-chevron-right diff --git a/config/locales/en.yml b/config/locales/en.yml index 17adb4de41..3c3c1d1c1d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -848,13 +848,6 @@ en: prompt: "This will permanently remove it from your list." confirmation_text: "Delete variant" cancellation_text: "Keep variant" - sort: - pagination: - total_html: "%{total} products found for your search criteria. Showing %{from} to %{to}." - per_page: - show: Show - per_page: "%{num} per page" - clear_search: Clear search filters: search_products: Search for products search_for_producers: Search for producers @@ -866,7 +859,13 @@ en: categories: label: Categories search: Search - content: + sort: + pagination: + total_html: "%{total} products found for your search criteria. Showing %{from} to %{to}." + per_page: + show: Show + per_page: "%{num} per page" + clear_search: Clear search no_products: no_products_found: No products found import_products: Import multiple products diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index 9622ce4a9d..9911ca78dc 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -43,7 +43,7 @@ describe 'As an admin, I can manage products', feature: :admin_style_v3 do expect(page).to have_selector ".pagination" expect_products_count_to_be 15 within ".pagination" do - click_link "2" + click_on "2" end expect(page).to have_content "Showing 16 to 16" # todo: remove unnecessary duplication @@ -86,7 +86,7 @@ describe 'As an admin, I can manage products', feature: :admin_style_v3 do visit admin_products_url within ".pagination" do - click_link "2" + click_on "2" end expect(page).to have_content "Showing 16 to 16" @@ -617,9 +617,8 @@ describe 'As an admin, I can manage products', feature: :admin_style_v3 do visit admin_products_url within ".pagination" do - click_link "2" + click_on "2" end - within row_containing_name("zucchini") do fill_in "Name", with: "zucchinis" end @@ -631,7 +630,6 @@ describe 'As an admin, I can manage products', feature: :admin_style_v3 do product_a.reload }.to change { product_a.name }.to("zucchinis") - pending "awaiting pagination to be loaded without SR" expect(page).to have_content "Showing 16 to 16" # todo: remove unnecessary duplication expect_page_to_be 2 expect_per_page_to_be 15 @@ -959,7 +957,7 @@ describe 'As an admin, I can manage products', feature: :admin_style_v3 do end def expect_page_to_be(page_number) - expect(page).to have_selector ".pagination span.page.current", text: page_number.to_s + expect(page).to have_selector ".pagination .page.current", text: page_number.to_s end def expect_per_page_to_be(per_page)