8000 Prioritize filters with predicates in active filter labels (#7702) · activeadmin/activeadmin@ee720aa · GitHub
[go: up one dir, main page]

Skip to content

Commit ee720aa

Browse files
committed
Prioritize filters with predicates in active filter labels (#7702)
When there are filters for a single field and a multi-field ransack search with predicate, the multi-field label on the active filter should use the custom label from the filter input box. Reproduction steps: ./app/admin/posts.rb ``` ActiveAdmin.register Post do filter :title_or_body_contains, as: :string, label: 'Title or Body' filter :title, as: :string ... end ``` Navigate to the posts path for a user like `localhost:3000/admin/users/4/posts` Complete search in both fields, note that both active filters use the label "Title contains". The `title_or_body_contains` should use the label from the filter "Title or Body contains".
1 parent b36701b commit ee720aa

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/active_admin/filters/active_filter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def find_class
9898
end
9999

100100
def filter
101-
resource.filters[name.to_sym] || resource.filters[condition.key.to_sym]
101+
resource.filters[condition.key.to_sym] || resource.filters[name.to_sym]
102102
end
103103

104104
def related_primary_key

spec/unit/filters/active_filter_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,15 @@
190190
resource.add_filter(:title_or_body_cont, label: label)
191191
expect(subject.label).to eq("#{label} contains")
192192
end
193+
194+
context "when an additional filter exists for one of the fields" do
195+
it "should use the filter label as the label prefix" do
196+
label = "#{user.first_name}'s Post"
197+
resource.add_filter(:title_or_body_cont, label: label)
198+
resource.add_filter(:title)
199+
expect(subject.label).to eq("#{label} contains")
200+
end
201+
end
193202
end
194203
end
195204

0 commit comments

Comments
 (0)
0