Introduce separate selection states for lists with distinct storeKey#10953
Conversation
|
This is just a draft to make sure the solution is applicable for the framework. Btw, is there any chance to get this feature in minor release? |
|
can you explain why you need to introduce the notion of namespace, which seems to overlap with the storeKey feature? |
|
It's maybe more like storeKey, i just named it like this... Do you suggest to pass List's storeKey to useRecordSelection instead of adding separate & independent key for selection state? |
Exactly |
|
@fzaninotto ok, will do. |
|
Why will it be a breaking change? You only need to make the |
|
Any existing usage of List with non-empty |
|
So you're right, it's a breaking change, but one that we're willing to accept given =i see no use case for two lists with different store keys that would require an identical selection. You can continue on |
|
Ok. What about storing selection state in 2 separate keys ( @fzaninotto , can you please have a look at the question above? |
storeKey in useRecordSelection
…me storeKey selection state
|
@fzaninotto as far as I can understand the requirements for the PR it seems to be ready for the review. |
slax57
left a comment
There was a problem hiding this comment.
Sorry we're taking some time to review your PR but the team is fairly busy ATM 😅 .
Still, we appreciate your work and your will to contribute! 💪
|
@slax57 , i've pushed my changes to resolve your comment about keeping the list of storeKeys in a separate store. Regarding the
I'm ready to remove it and always delete from all store keys if we want to use this behaviour as a default one (w/o ability to customize the behaviour from the code outside RA). |
slax57
left a comment
There was a problem hiding this comment.
@mikhail-fedosenko Thank you for working on that new iteration.
I re-read the whole discussion, and in the end, I think I agree with you.
The behavior that probably makes most sense is to have each selection state be independent from one another by default (i.e. have fromAllStoreKeys set to false by default).
The only exception being the case when the records are deleted, in which case it makes sense to remove their ids from all selection states tied to this resource (i.e. have fromAllStoreKeys set to true for that particular use case).
I need to re-discuss this with @fzaninotto, we'll be in touch.
The CI tests found a breaking change (see below), and I also found some minor issues, but other than that you code looks good to me!
Thanks again!
|
UPDATE: @fzaninotto also agrees with your POV. So I confirm you can keep the |
|
@slax57 , updated the docs, reverted the BC in If you'd like to have more detailed examples in the docs about new |
storeKey in useRecordSelectionstoreKey
Problem
It's not possible to create distinct List views that use separate record selection states.
Previous discussion was started in PR: #10951
Solution
Store selected IDs under in aRecord<string, Identifier[]>structure inuseRecordSelection. List component passes thestoreKeytouseRecordSelection. If storeKey is non-empty, then it's used as a key in the selection object. Delete controllers pass the flag to unselect deleted records from all storedKeys.Reached the following solution after the discussion:
Store the selected IDs as an array in a store, the store key will include passed
storeKey.Also, store the list of used storeKeys per resource in an additional store (1 list of storeKeys per resource).
When the code asks to remove selected IDs it can pass a boolean flag to remove the selection from all store keys, thus, the
useRecordSelectionwill remove selections from all storeKeys stored in that 2nd store.How To Test
Run the story for record selections states with different storyKeys:
http://localhost:9010/?path=/story/ra-ui-materialui-list-list--record-selection
Additional Checks
masterfor a bugfix or a documentation fix, ornextfor a feature