Skip to content

Commit

Permalink
fix: maintain per_page param in associations (#3490)
Browse files Browse the repository at this point in the history
* fix: maintain `per_page` param in associations

* add test

* lint

* more lint
  • Loading branch information
Paul-Bob authored Dec 4, 2024
1 parent 05693d0 commit 9c756d4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
12 changes: 6 additions & 6 deletions app/controllers/avo/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,14 @@ def set_index_params

# Pagination
@index_params[:page] = params[:page] || page_from_session || 1
@index_params[:per_page] = Avo.configuration.per_page

if cookies[:per_page].present?
@index_params[:per_page] = cookies[:per_page]
end
@index_params[:per_page] = cookies[:per_page] || Avo.configuration.per_page

if @parent_record.present?
@index_params[:per_page] = Avo.configuration.via_per_page
per_page_key = "#{@record.to_global_id}.has_many.#{@resource.class.to_s.parameterize}.per_page"
session[per_page_key] = params[:per_page] || session[per_page_key]
per_page_from_session = session[per_page_key]

@index_params[:per_page] = per_page_from_session || Avo.configuration.via_per_page
end

if params[:per_page].present?
Expand Down
22 changes: 22 additions & 0 deletions spec/system/avo/tabs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,26 @@
expect(page).to have_css('a.current[role="link"][aria-disabled="true"][aria-current="page"]', text: "2")
expect(page).to have_text "Displaying items 9-9 of 9 in total"
end

it "keeps the per_page on association when back is used" do
visit avo.resources_user_path user

find('a[data-selected="false"][data-tabs-tab-name-param="Projects"]').click
within("#has_and_belongs_to_many_field_show_projects") do
expect(page).to have_text "Displaying items 1-8 of 9 in total"
find("select#per_page.appearance-none").select("24")
end

expect(page).to have_text "Displaying 9 items"
expect(find("select#per_page.appearance-none").find("option[selected]").text).to eq("24")

find_all('a[aria-label="View project"]')[0].click
wait_for_loaded

page.go_back
wait_for_loaded

expect(page).to have_text "Displaying 9 items"
expect(find("select#per_page.appearance-none").find("option[selected]").text).to eq("24")
end
end

0 comments on commit 9c756d4

Please sign in to comment.