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

Fix: Filter badge fields #3071

Closed
wants to merge 2 commits into from
Closed
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
15 changes: 13 additions & 2 deletions lib/avo/fields/badge_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,24 @@ module Fields
class BadgeField < BaseField
attr_reader :options

def initialize(id, **args, &block)
super(id, **args, &block)
def initialize(id, **args, &)
super

hide_on [:edit, :new]

default_options = {info: :info, success: :success, danger: :danger, warning: :warning, neutral: :neutral}
@options = args[:options].present? ? default_options.merge(args[:options]) : default_options
@enum = args[:enum]

if @enum
@options_for_filter = options.transform_values do |value|
if value.is_a? Array
value.map { |v| @enum[v.to_s] }
else
@enum[value.to_s] || -1
end
end
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/avo/fields/base_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def hidden_in_reflection?
end

def options_for_filter
options
@options_for_filter || options
end

def updatable
Expand Down
Loading