-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Filter with an object as defaultValue is still visible after user click the remove filter button #9893
Labels
Comments
hmatthieu
changed the title
Filter is still visible after user click the remove filter button
Filter with an object as defaultValue is still visible after user click the remove filter button
Jun 2, 2024
reproduced, thanks 🙏 |
hmatthieu
added a commit
to hmatthieu/react-admin
that referenced
this issue
Jun 4, 2024
When filters with a complex object as defaultValue the "empty value" was not considered empty by the UI. This commit ensure we don't display empty filters on the UI. Refs: marmelab#9893
hmatthieu
added a commit
to hmatthieu/react-admin
that referenced
this issue
Jun 4, 2024
Add test to ensure correction. Refs: marmelab#9893
hmatthieu
added a commit
to hmatthieu/react-admin
that referenced
this issue
Jun 10, 2024
mjarosch
pushed a commit
to mjarosch/react-admin
that referenced
this issue
Jun 12, 2024
When filters with a complex object as defaultValue the "empty value" was not considered empty by the UI. This commit ensure we don't display empty filters on the UI. Refs: marmelab#9893
mjarosch
pushed a commit
to mjarosch/react-admin
that referenced
this issue
Jun 12, 2024
Add test to ensure correction. Refs: marmelab#9893
mjarosch
pushed a commit
to mjarosch/react-admin
that referenced
this issue
Jun 12, 2024
Closed by #9898 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What you were expecting:
When a user clicks the remove filter button, the filter should not be active anymore and should be hidden from the UI.
What happened instead:
The filter is not active but is still visible in the UI.
Steps to reproduce:
Pass an object to the
defaultValue
prop of afilters
List prop. In the react-admin simple example, you can replace inexamples/simple/src/posts/PostList.tsx:l56
with
See this live example:
https://stackblitz.com/edit/github-kh8m7q?file=src%2Fposts%2FPostList.tsx
Related code:
https://stackblitz.com/edit/github-kh8m7q?file=src%2Fposts%2FPostList.tsx
Other information:
At first, I thought it could be a design choice from React-Admin to not handle complex objects, but it's clear in the codebase that some logic is implemented to cover this use case. I would be happy to submit a merge request, but I want to first check if you agree that it's indeed a bug.
A quick note regarding why a complex object is beneficial: With a server that exposes database queries as an object, it's super easy to write filters that are passed from the UI to the database without any processing in between. express-restify-mongoose is a good example, as well as GQL.
How to fix
The issue comes from
packages/ra-ui-materialui/src/list/filter/FilterForm.tsx:getFilterFormValues()
, and how react-admin rebuilds the filter (See codebase comments from l256 to l260).When the user hides the filter, react-admin tries to reset the filter value, but this blank value is not compatible with how
getShownFilters:l119
chooses to display or not display a filter. This results in a misalignment between the filter state and the filter visibility.To maintain the same behavior but allow a better reset behavior, the developer could provide a reset value, or react-admin might use the defaultFilterValue. There are different options to avoid breaking anything, and I'm happy to have your feedback on this.
How to bypass
Currently, the best way I found is to define a simple filter defaultValue, catch this value in the data provider, and replace it with the complex filter.
Environment
The text was updated successfully, but these errors were encountered: