-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Using multi-attribute Ransack filter not properly creating/pulling label for active filters sidebar content display #7702
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
Comments
This looks similar to #5885. The fix added the ability for the custom label when the condition has a predicate. So if you only need the single filter, including the predicate might help in the short term: ./app/admin/addresses.rb
The second issue you mentioned about the multi-attribute filter using the first attribute, 'city', would still be present if you were using both ./app/admin/addresses.rb
One solution might be to change this line and swap the order to prioritize the filter matching the condition key:
|
…in#7702) When there are filters for a single field and a multi-field ransack search with predicate, the multi-field label on the active filter should use the custom label from the filter input box. Reproduction steps: ./app/admin/posts.rb ``` ActiveAdmin.register Post do filter :title_or_body_contains, as: :string, label: 'Title or Body' filter :title, as: :string ... end ``` Navigate to the posts path for a user like `localhost:3000/admin/users/4/posts` Complete search in both fields, note that both active filters use the label "Title contains". The `title_or_body_contains` should use the label from the filter "Title or Body contains".
Thank you very much for your support and assistance! The issue still persists as the |
@corlissc Can you provide some code snippets to replicate the issue fully? |
@ray-curran, thanks for your response. I'm busy with a project at this current time, I will try to get you something in the next couple of weeks if I can find a free moment. Let me know if there is anything specific that you are looking for (format, etc...) that my original post didn't provide. In the meantime, I can provide a quick breakdown of my troubleshooting with a more complex filter that provides the issue at hand. Let me know if this provides you enough information or if you still need additional code, etc... Thank you again for your time and support. The Rails models:
ActiveAdmin Facilities config:
Given the above, while troubleshooting this is what within
The code within
|
…in#7702) When there are filters for a single field and a multi-field ransack search with predicate, the multi-field label on the active filter should use the custom label from the filter input box. Reproduction steps: ./app/admin/posts.rb ``` ActiveAdmin.register Post do filter :title_or_body_contains, as: :string, label: 'Title or Body' filter :title, as: :string ... end ``` Navigate to the posts path for a user like `localhost:3000/admin/users/4/posts` Complete search in both fields, note that both active filters use the label "Title contains". The `title_or_body_contains` should use the label from the filter "Title or Body contains".
@ray-curran - The pull request's code will provide the fix needed for the issue. Thanks! |
…in#7702) When there are filters for a single field and a multi-field ransack search with predicate, the multi-field label on the active filter should use the custom label from the filter input box. Reproduction steps: ./app/admin/posts.rb ``` ActiveAdmin.register Post do filter :title_or_body_contains, as: :string, label: 'Title or Body' filter :title, as: :string ... end ``` Navigate to the posts path for a user like `localhost:3000/admin/users/4/posts` Complete search in both fields, note that both active filters use the label "Title contains". The `title_or_body_contains` should use the label from the filter "Title or Body contains".
…in#7702) When there are filters for a single field and a multi-field ransack search with predicate, the multi-field label on the active filter should use the custom label from the filter input box. Reproduction steps: ./app/admin/posts.rb ``` ActiveAdmin.register Post do filter :title_or_body_contains, as: :string, label: 'Title or Body' filter :title, as: :string ... end ``` Navigate to the posts path for a user like `localhost:3000/admin/users/4/posts` Complete search in both fields, note that both active filters use the label "Title contains". The `title_or_body_contains` should use the label from the filter "Title or Body contains".
When utilizing Ransack's DSL to create an index filter for multiple attributes,
ActiveAdmin::Views::ActiveFiltersSidebarContent
doesn't properly create or pull the label to display within the active filters sidebar. Instead it pulls the first attribute specified to do a lookup within theActiveFilter#resource.filters
hash. This leads to misleading active filter data within the UI.For example with the following Rails model:
And a corresponding ActiveAdmin object with a filter searching across city and county:
Expected behavior
When the city_or_county filter is utilized, I expect the active filters sidebar content to include an item with the label configured for the city_or_county filter (i.e. City or county) by utilizing the entirety of the filter (each attribute, any association, etc...) in order to build or properly lookup the correct filter metadata
Actual behavior
The active filters sidebar content includes an item with only the name of the first attribute accounted for "City". Furthermore, if there was a custom label for the "city" filter, it would pull that filter's label.
How to reproduce
./app/models/address.rb
./app/admin/addresses.rb
Start a rails server and utilize the filter... If the server started at http://localhost:3000, hitting the following URL would exercise the filter and show the output http://localhost:3000/admin/addresses?q[city_or_county_contains]=ma&commit=Filter&order=id_desc
The text was updated successfully, but these errors were encountered: