react-admin icon indicating copy to clipboard operation
react-admin copied to clipboard

Dynamic filter support in ReferenceInput

Open tarun-khanna opened this issue 6 years ago • 0 comments

What you were expecting: Changing the filter value in ReferenceInput should make query with new filters.

What happened instead: Changing filters doesn't work, instead the query uses the same old filter value.

Steps to reproduce: Change filter of ReferenceInput at runtime by setTimeOut or by another formInput value, and pass the new filter to ReferenceInput.

Related code: https://codesandbox.io/s/cold-star-f2rfi

Go to comment edit page, and check the console logs printed in dataProvider. The filter for ReferenceInput of Posts was changed after 2 seconds, still the latest query in dataProvider has old filter in params.

const [filter, setFilter] = React.useState({ category: "tech" });
  React.useEffect(() => {
    setTimeout(() => {
      setFilter({ category: "lifestyle" });
    }, 2000);
  }, []);
<ReferenceInput
  source="post_id"
  reference="posts"
  perPage={15}
  sort={{ field: "title", order: "ASC" }}
  fullWidth
  filter={filter}
>
  <AutocompleteInput
    matchSuggestion={(filterValue, suggestion) => true}
    optionText={<OptionRenderer />}
    inputText={inputText}
  />
</ReferenceInput>

Other information: I have also raised a PR on my approach to solve this issue. Here is the link. https://github.com/marmelab/react-admin/pull/4508

Environment

  • React-admin version: 3.2.1
  • React version: 16.12.0
  • Browser: Chrome

tarun-khanna avatar Mar 11 '20 15:03 tarun-khanna