Skip to content

Commit

Permalink
feature: callable filter name and button_label (#3382)
Browse files Browse the repository at this point in the history
* feature: callable filter `name` and `button_label`

* Update lib/avo/filters/base_filter.rb

---------

Co-authored-by: Paul Bob <[email protected]>
  • Loading branch information
thiagoyoussef and Paul-Bob authored Nov 4, 2024
1 parent f9634c3 commit 29795fc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
10 changes: 9 additions & 1 deletion lib/avo/filters/base_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def apply_query(request, query, value)
end

def id
self.class.name.underscore.tr("/", "_")
name.underscore.tr("/", "_")
end

# Get the applied value this filter.
Expand Down Expand Up @@ -88,6 +88,14 @@ def visible_in_view(resource: nil, parent_resource: nil)
arguments: arguments
).handle
end

def name
Avo::ExecutionContext.new(target: self.class.name, arguments: @arguments).handle
end

def button_label
Avo::ExecutionContext.new(target: self.class.button_label, arguments: @arguments).handle
end
end
end
end
4 changes: 2 additions & 2 deletions spec/dummy/app/avo/filters/user_names_filter.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Avo::Filters::UserNamesFilter < Avo::Filters::TextFilter
self.name = "User names filter"
self.button_label = "Filter by user names"
self.name = -> { I18n.t("avo.filter_translations.user_names_filter.name") }
self.button_label = -> { I18n.t("avo.filter_translations.user_names_filter.button_label") }
self.empty_message = "Search by name"

def apply(request, query, value)
Expand Down
4 changes: 4 additions & 0 deletions spec/dummy/config/locales/avo.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,7 @@ en:
x_records_selected_from_page_html: <span class="font-bold text-gray-700">%{selected}</span> records selected on this page
yes_confirm: Yes, I'm sure
you_missed_something_check_form: You might have missed something. Please check the form.
filter_translations:
user_names_filter:
name: User names filter
button_label: Filter by user names

0 comments on commit 29795fc

Please sign in to comment.