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

[7.2-stable] Fix combining search filters and pagination #2982

Merged
merged 1 commit into from
Jul 30, 2024
Merged
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
Fix combining search filters and pagination
The `search_filter_params` method in Alchemy's Resource Controller
converts the permitted attributes to a Hash, stopping them from being
recognized as something like a nested Hash in our per page select. This
commit uses duck-typing in order to find out whether we're looking at a
nested Hash. This should work with both ActionController::Parameters and
with a Hash.

(cherry picked from commit e059c80)
mamhoff committed Jul 30, 2024
commit 431025cb3a4be3f96e63918208d7013325b994a0
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= form_tag url_for, method: :get, class: 'per-page-select-form' do |f| %>
<% search_filter_params.reject { |k, _| k == 'page' || k == 'per_page' }.each do |key, value| %>
<% if value.is_a? ActionController::Parameters %>
<% if value.respond_to?(:keys) %>
<% value.each do |k, v| %>
<%= hidden_field_tag "#{key}[#{k}]", v, id: nil %>
<% end %>
15 changes: 15 additions & 0 deletions spec/features/admin/resources_integration_spec.rb
Original file line number Diff line number Diff line change
@@ -105,6 +105,21 @@
expect(page).to_not have_content("today 1")
end
end

it "can combine filters and pagination", :js do
stub_alchemy_config(:items_per_page, 1)

visit "/admin/events?filter[start]=starting_today"

select("4", from: "per_page")

within "div#archive_all table.list tbody" do
expect(page).to have_selector("tr", count: 2)
expect(page).to have_content("today 1")
expect(page).to have_content("today 2")
expect(page).not_to have_content("yesterday")
end
end
end
end