-
Notifications
You must be signed in to change notification settings - Fork 0
3157 use enum labels in current filters search status #1
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
base: master
Are you sure you want to change the base?
3157 use enum labels in current filters search status #1
Conversation
ff3c597 to
0221992
Compare
|
Just wanted to add this is very much still a desired feature for me! I explained another work around with Enumerize in my comment on this closed thread: activeadmin#3157 (comment) |
0221992 to
396d75b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR ensures that ActiveAdmin’s Current Search Status widget shows human-readable enum labels instead of raw enum values (and respects any custom filter collections).
- Enhanced
ActiveFilter#valuesto detect enums and map values to their labels (with fallbacks for custom collections). - Added unit tests around enum label display (including custom array/hash collections and multi-selection).
- Updated test model, migration, and ActiveAdmin registration templates to include
review_statusandreject_reasonenums.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| spec/unit/filters/active_filter_spec.rb | New specs for enum label resolution and custom collection fallback |
| spec/support/templates/models/store.rb | Added review_status and reject_reason enum definitions |
| spec/support/templates/migrations/create_stores.tt | Added integer columns for new enums in test migration |
| spec/support/templates/admin/stores.rb | Permits and filters by the new enum attributes in ActiveAdmin |
| lib/active_admin/filters/active_filter.rb | Updated values logic to humanize enum and custom collection values |
Comments suppressed due to low confidence (1)
spec/unit/filters/active_filter_spec.rb:308
- Add a similar multi-selection spec for native enum filters (e.g.,
review_status_in) to ensure multiple enum values are humanized correctly.
context "filtering by multiple selections" do
| end | ||
|
|
||
| def enum_attribute | ||
| resource_class.defined_enums[name] |
Copilot
AI
Jul 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defined_enums keys are strings, but name is a symbol. Change to resource_class.defined_enums[name.to_s] so enum lookups actually fire.
| resource_class.defined_enums[name] | |
| resource_class.defined_enums[name.to_s] |
| condition_values.map do |value| | ||
| # value(filter form's search params) will be a string, | ||
| # so let us transform the lookup object (e.g. for integer backed enums) | ||
| (hash.transform_values(&:to_s).key(value) || value).to_s.humanize |
Copilot
AI
Jul 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider moving hash.transform_values(&:to_s) outside the loop to avoid repeated transformations when mapping multiple values.
| condition_values.map do |value| | |
| # value(filter form's search params) will be a string, | |
| # so let us transform the lookup object (e.g. for integer backed enums) | |
| (hash.transform_values(&:to_s).key(value) || value).to_s.humanize | |
| transformed_hash = hash.transform_values(&:to_s) | |
| condition_values.map do |value| | |
| # value(filter form's search params) will be a string, | |
| # so let us transform the lookup object (e.g. for integer backed enums) | |
| (transformed_hash.key(value) || value).to_s.humanize |
Fixes Issue activeadmin#3157 - Display Enum labels for Active Filters in Current Search Status
ActiveAdmin::Filters::ActiveFilter#values controls the displayed value for active filters.
This currently does not have any special handling for Enums.
For e.g. with an enum definition like
enum status: [:inactive, :active], when filtering for :inactive status, the Current Search Status widget shows "Status is 0"This PR, uses ActiveRecord::Enum.defined_enums to translate the display value for the filter to the associated label for enums. The Current Search Status widget will now show "Status is Inactive"
If a custom collection is provided when registering the ActiveAdmin resource e.g.
filter :status, as: :select, collection: [[:not_active, 0], [:active, 1]]which specifies dropdown labels that are different from the enum labels, then the dropdown label from the custom collection is used. The Current Search Status widget will now show "Status is Not Active"