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

Two filters are not applied to List when disableSyncWithLocation is true #9190

Closed
mikhail-fedosenko opened this issue Aug 17, 2023 · 5 comments · Fixed by #9283
Closed

Two filters are not applied to List when disableSyncWithLocation is true #9190

mikhail-fedosenko opened this issue Aug 17, 2023 · 5 comments · Fixed by #9283
Labels

Comments

@mikhail-fedosenko
Copy link

What you were expecting:
I have BooleanInput filter and QuickFilter in my filters for List:

[
  <BooleanInput
    label="Has Code tag"
    source={'hasCodeTag'}
    alwaysOn
    sx={{ mb: 1 }}
  />,
  <QuickFilter
    label="resources.posts.fields.commentable"
    source="commentable"
    defaultValue
  />,
];

The List has disableSyncWithLocation enabled.
When I apply "Commentable" filter first, then apply "Has Code tag" filter, the data provider getList method should receive both filter values: { commentable: true, hasCodeTag: true }.

What happened instead:
Data provider getList method receives only one filter value: { hasCodeTag: true }.

Steps to reproduce:

  1. Go to Posts list page.
  2. Click on "Filters", select "Commentable" filter.
  3. Click on "Has Code Tag" filter.
  4. Observe the console log.

Related code:
https://stackblitz.com/edit/github-4uscjv?file=src%2Fposts%2FPostList.tsx

PostList.tsx

const postFilter = [
  <BooleanInput
    label="Has Code tag"
    source={'hasCodeTag'}
    alwaysOn
    sx={{ mb: 1 }}
  />,
  <QuickFilter
    label="resources.posts.fields.commentable"
    source="commentable"
    defaultValue
  />,
];
  <List
     ...
    disableSyncWithLocation
  >

dataProvider.tsx

    beforeGetList: async (params, dataProvider) => {
      console.log('Filter is', params.filter);
      const { hasCodeTag, restFilters } = params.filter;
      params.filter = restFilters;
      return params;
    },

Environment

  • React-admin version: 4.13.0
  • React version: 17.0.2
  • Browser: Chrome 114.0.5735.198
@djhi
Copy link
Collaborator

djhi commented Aug 17, 2023

Reproduced, thanks

@djhi
Copy link
Collaborator

djhi commented Aug 17, 2023

Actually no, if I follow your steps, I can't reproduce. I get:

{hasCodeTag: true, commentable: true}

@mikhail-fedosenko
Copy link
Author

The order you apply filters is important - first apply a filter in Filters context menu ("Commentable"), then - "Has Code Tag".

If you apply "Commentable", then "Has Code Tag", then remove and re-apply "Commentable" the filtler value passed to the data provider will be correct.

@adguernier
Copy link
Contributor

Actually I can reproduce by following the steps order.

select "Commentable" filter logs

Filter is { commentable: true }

and then click on "Has Code Tag" filter logs

Filter is { hasCodeTag: true }

Doing this by reversing the steps order will produce the right behavior

Filter is { hasCodeTag: true, commentable: true }

@djhi
Copy link
Collaborator

djhi commented Aug 18, 2023

Indeed, must have done the reverse

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

Successfully merging a pull request may close this issue.

3 participants