Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: maintain per_page param in associations #3490

Merged
merged 4 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading