You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Components that implement a ListContext don't include a default exporter like useListController does.
<ExportButton> starts by calling dataProvider.getList(), which is wrong in many situations. For instance, when used as a child of <ReferenceArrayField>, the entire data is already fetched and should not be refetched.
Solution
Add support for an exporter prop in <ArrayField>, <ReferenceArrayField> and <ReferenceManyField>, and pass it down to the controller
Add a default exporter to useReferenceArrayFieldController, useReferenceManyFieldController, and useList
Add a new field in ListContext: async getData() => Record[], that each controller must define according to its internal logic. It should return the entire list data regardless of pagination.
Update <ExportButton> to use this getData if present in the context instead of dataProvider.getList
Note that this change should also allow a "Select All" feature (cf #9043)
Environment
React-admin version: 4.11
Last version that did not exhibit the issue (if applicable): N/A
React version: 17
Browser: Chrome
The text was updated successfully, but these errors were encountered:
What you were expecting
<ExportButton>
should just work when used as a child of<ArrayField>
,<ReferenceManyField>
, or<ReferenceArrayField>
What happened instead
The button is rendered, it calls
dataProvider.getList()
, but does not trigger a file download on the client.Steps to reproduce:
https://stackblitz.com/edit/github-juchmy?file=src%2Fposts%2FPostEdit.tsx
In the simple example, in the PostEdit.tsx, add an
<ExportButton>
as child of<ReferenceManyField>
:Then browse to a post detail (e.g. https://githubjuchmy-lbmb--8080--9c8944bc.local-credentialless.webcontainer.io/#/posts/1/3) and click on the export button.
Analysis
There are 2 problems:
ListContext
don't include a defaultexporter
likeuseListController
does.<ExportButton>
starts by callingdataProvider.getList()
, which is wrong in many situations. For instance, when used as a child of<ReferenceArrayField>
, the entire data is already fetched and should not be refetched.Solution
exporter
prop in<ArrayField>
,<ReferenceArrayField>
and<ReferenceManyField>
, and pass it down to the controllerexporter
touseReferenceArrayFieldController
,useReferenceManyFieldController
, anduseList
ListContext
:async getData() => Record[]
, that each controller must define according to its internal logic. It should return the entire list data regardless of pagination.<ExportButton>
to use thisgetData
if present in the context instead ofdataProvider.getList
Note that this change should also allow a "Select All" feature (cf #9043)
Environment
The text was updated successfully, but these errors were encountered: