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

Make ReferenceManyField compatible with filters #8642

Closed
nicgirault opened this issue Feb 12, 2023 · 3 comments · Fixed by #8800
Closed

Make ReferenceManyField compatible with filters #8642

nicgirault opened this issue Feb 12, 2023 · 3 comments · Fixed by #8800
Assignees
Labels

Comments

@nicgirault
Copy link
Contributor

Is your feature request related to a problem? Please describe.

Today there is not guidance and support for filters within a ReferenceManyField. I am having difficulties trying to integrate react-admin filter system within a ReferenceManyField component.

Describe the solution you'd like

Digging into the source code of the List component, it looks like the react-admin way to setup filters in ReferenceManyField would be to write something like:

<ReferenceManyField
  reference="comments"
  target="postId"
  pagination={<Pagination />}
>
  <ListToolbar
    filters={commentFilters}
    actions={
      <TopToolbar>
        <FilterButton />
      </TopToolbar>
    }
  />
  <Datagrid bulkActionButtons={false}>
  ...
  </Datagrid>
</ReferenceManyField>

But this generates infinite loop when writing within a filter input (probably due to the fact that reference many field context is not exactly similar to the list context, especially in terms of URL sync settings).

Note 1: Today, ReferenceManyField pagination state is not storable in the URL and this feature request might be related to this subject: could a solution be to be able to specify a "urlKey" props to the ReferenceManyField component so that all the state of this field can be stored in URL without conflicting with possible other components?

Note 2: I am not quite sure to understand why react-admin needs to implement a useReferenceManyFieldController: why ReferenceManyField component can't directly use a useListController hook instead?

@slax57
Copy link
Contributor

slax57 commented Feb 13, 2023

Hi @nicgirault , and thank you for your suggestion.

I'm not sure I caught exactly what you are asking for. Would you like us to document how to add a FilterForm inside a ReferenceManyField, or would you like to add support for a filters prop to it (just like with List)?

Also, I'm not sure what you expect with the URL: do you expect the URL to be updated when you change the filters or not?

@nicgirault
Copy link
Contributor Author

Thanks for your answer.

Both would be good solutions for me. Being able to have a filters prop would probably be simpler to use, but might require more work.

I would expect the URL to be updated when I change filter and pagination but I guess this should be configurable.

@slax57
Copy link
Contributor

slax57 commented Feb 13, 2023

Thank you for your answer.
I was mainly asking to better understand what kind change you had in mind, to clarify the enhancement request, and indeed estimate its complexity.

However, in any case, our policy regarding new features is that we only develop them if we require them for one of our projects, or if there is a high demand for this feature from the community.

Of course, you also have the ability to open a PR yourself if you are willing to give it a try. We would gladly welcome it.

Thus, I'm leaving this feature request open to see how things go, but we won't work on it for now.

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