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

Use ActiveRecord Enum labels in current filters status #7790

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

harunkumars
Copy link

Fixes Issue #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"

Sample before and after screenshots attached:
Before Fix:
before_fix_for_3157

After Fix:
after_fix_for_3157

@javierjulio javierjulio changed the title 3157 use enum labels in current filters search status Use ActiveRecord Enum labels in current filters status Mar 12, 2023
@javierjulio javierjulio force-pushed the 3157-use-enum-labels-in-current-filters-search-status branch from 17eada7 to 18135b2 Compare March 13, 2023 01:26
@codecov
Copy link

codecov bot commented Mar 13, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (25c74c7) 98.92% compared to head (0221992) 98.93%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7790   +/-   ##
=======================================
  Coverage   98.92%   98.93%           
=======================================
  Files         197      197           
  Lines        4950     4963   +13     
=======================================
+ Hits         4897     4910   +13     
  Misses         53       53           
Impacted Files Coverage Δ
lib/active_admin/filters/active_filter.rb 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@javierjulio javierjulio force-pushed the 3157-use-enum-labels-in-current-filters-search-status branch 2 times, most recently from 5eb6ba1 to ff3c597 Compare March 19, 2023 01:30
@javierjulio javierjulio force-pushed the 3157-use-enum-labels-in-current-filters-search-status branch from ff3c597 to 0221992 Compare March 19, 2023 01:39
@Aesthetikx
Copy link
Contributor

Great work on this @harunkumars, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants