8000 Prioritize filters with predicates in active filter labels (#7702) by ray-curran · Pull Request #7717 · activeadmin/activeadmin · GitHub
[go: up one dir, main page]

Skip to content

Prioritize filters with predicates in active filter labels (#7702) #7717

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion lib/active_admin/filters/active_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ def find_class
end

def filter
resource.filters[name.to_sym] || resource.filters[condition.key.to_sym]
resource.filters[condition.key.to_sym] ||
resource.filters[condition.key.remove("_#{condition.predicate.name}").to_sym] ||
resource.filters[name.to_sym]
end

def related_primary_key
Expand Down
18 changes: 18 additions & 0 deletions spec/unit/filters/active_filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,24 @@
resource.add_filter(:title_or_body_cont, label: label)
expect(subject.label).to eq("#{label} contains")
end

context "when an additional filter exists for one of the fields" do
it "should use the filter label as the label prefix" do
label = "#{user.first_name}'s Post"
resource.add_filter(:title_or_body_cont, label: label)
resource.add_filter(:title)
expect(subject.label).to eq("#{label} contains")
end
end

context "when a filter with a dropdown is searched" do
it "should use the filter label as the label prefix" do
label = "#{user.first_name}'s Post"
resource.add_filter(:title_or_body, filters: [:contains, :equals], label: label)
resource.add_filter(:title)
expect(subject.label).to eq("#{label} contains")
end
end
end
end

Expand Down
0