-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
storeKey prop is not passed to useRecordSelection hook inside useListController #9740
Comments
Good catch! Would you mind opening a PR to fix it? |
Hi there, thx for the quick reply! I've thought for a while about the issue at hand and read through the linked related issues and wanted to add my two cents to it. First of all let me restate the issue to know if I undertood it well enough: When implementing row selection in lists, resource-bound global selection state was chosen for, among others, one main goal: keep selection accross navigations (mainly list view <-> edit view back and forth user experience) and be able to delete records from other views (mainly the edit view) and being able to deselect (if selected) that record so when the user goes back to the list all is consistent. Since then, a custom This independence cannot be applied to the selection state because it would break the stated main goal, since when deleting a record from its edit view there could be arbitrary keys in the store that would have to be updated, which is not possible or very hard to manage. Now with the problem stated, I think that the custom I would argue that the meaning of By using "the resource-derived storeKey otherwise", we avoid breaking react-admin's desired interactions with the store for selection related stuff. For normally managed lists, current behaviour is kept in all cases. For I've made a quick PR so we have some code to look at, and also to show that the changes seem to be limited to a couple files. |
@nbalaguer that seems like a sensible approach, thanks for taking the time to explain it. |
Fixed by #9742 |
English is not my native language, my apologies in advance for any weird grammar or implicit tone of the writing. I'll try my best 😃
What you were expecting:
I would expect the storeKey prop to work on both useListParams and useRecordSelction hooks.
What happened instead:
Right now the storeKey prop only gets passed to the useListParams hook.
Steps to reproduce:
Related code:
Prop is received
react-admin/packages/ra-core/src/controller/list/useListController.ts
Lines 35 to 46 in ec44ac5
Prop is forwared to useListParams
react-admin/packages/ra-core/src/controller/list/useListController.ts
Lines 65 to 73 in ec44ac5
Prop is NOT forwarded to useRecordSelection
react-admin/packages/ra-core/src/controller/list/useListController.ts
Line 75 in ec44ac5
storeKey is hardcoded based on the resource inside useRecordSelection
react-admin/packages/ra-core/src/controller/list/useRecordSelection.ts
Line 24 in ec44ac5
useListParams uses state to keep localParams when storeKey is false and the custom storeKey if provided, defaulting to a storeKey derived from the resource. useRecordSelection should do something similar.
Other information:
In this example, using 2 lists to display the same resource, one with storeKey set to false and the other with storeKey set to a custom string, you can see that when selecting a row in one list, the same row gets selected in the other list.
https://stackblitz.com/edit/github-asfjgd?file=src%2Fposts%2FPostList.tsx
Environment
The text was updated successfully, but these errors were encountered: