React-admin: filterDefaultValues are shared between <List />

Created on 2 Jul 2018  路  5Comments  路  Source: marmelab/react-admin

What you were expecting:

When switching between resources in the menu, the filterDefaultValues prop should not be merged.

What happened instead:
The filter prop is shared and thus during navigation they are stacking between the different resources.

Steps to reproduce:

1) Create a <List> of A
selection_031

2) Create a <List> of B
image

3) Go to /A
This will trigger this query:
selection_032

4) Go to B
selection_033

A's filterDefaultValues were merged with B's

  • CodeSandbox

Demo: https://w7r6ypn47k.codesandbox.io/#/posts
Code: https://codesandbox.io/s/w7r6ypn47k

(Click on Comments)
selection_034

Environment

  • React-admin version: 2.0.4
  • Browser: Chrome
bug

Most helpful comment

Thanks for the codesandbox, it confirms the bug. Marking it as such.

@djhi you're right, obviously.

All 5 comments

@fzaninotto Maybe we should store list filters by resources ?

Thanks for the codesandbox, it confirms the bug. Marking it as such.

@djhi you're right, obviously.

I thought we still had list params in a reducer shared among resources but no, list params are already by resource.

After some digging it seems the issue lies in the resource reducer initialization but I can't figure out why yet.

It would certainly be interesting to let users put filters values to null from a URL.

instead of:
https://github.com/marmelab/react-admin/blob/a1b27c4c21d70e94954441b26ceeaf9e848034c6/packages/ra-core/src/controller/ListController.js#L145-L146

if we do it like this that would allow this behaviour

if (!query.filter.hasOwnProperty(name)) {
  query.filter[name] = filterDefaultValues[name];
} 

Our use case: we have a ReferenceManyField with a Preview button which is a component redirecting the user to the List view with a certain filter (call it A). But the filterDefaultValues of the List are in conflict with filter A. The user needs to remove filter B to see the same results that in ReferenceManyField.

Fixed by #2019. Will be available in 2.1.3

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ericwb picture ericwb  路  3Comments

kdabir picture kdabir  路  3Comments

samanmohamadi picture samanmohamadi  路  3Comments

mbj36 picture mbj36  路  3Comments

9747749366 picture 9747749366  路  3Comments