Skip to content

Commit

Permalink
Fix combining search filters and pagination
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
mamhoff committed Jul 30, 2024
1 parent 9e31b7a commit 075fe50
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
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 %>
Expand Down
15 changes: 15 additions & 0 deletions spec/features/admin/resources_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 075fe50

Please sign in to comment.