-
-
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
[RFR] Fix handling of deleted references #3216
Conversation
previousState, | ||
key | ||
) => { | ||
const idsToRemove = previousState[key].ids.filter(id => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ain't the total equal to the number of ids ?
If so, you could filter to get the kept id, and returns
{
ids: keptIds,
total: keptIds.length
}
If not the test should reflect that fact.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also refactor removeDeletedReference to use removeDeletedReferences.
previousState: State, | ||
key: string | ||
) => { | ||
const idsToRemove = previousState[key].ids.filter(id => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of filtering twice just to count the number of elements to filter out, why don't you just count once and then compare the length to the length of the original key?
const idsToKeep = previousState[key].ids.filter(
id => !removedIds.includes(id)
);
if (idsToKeep.length === previousState[key].ids.length) {
return previousState;
}
return {
...previousState,
[key]: {
ids: idsToKeep,
total: idsToKeep.length,
},
};
Problem
When a
<ReferenceManyField>
displays a<DataGrid>
with aDeleteButton
on each row, optimistically deleting a reference will set its row into loading state but won't actually remove it until the action is resolved.Solution
Handle the
DELETE
effects in theoneToMany
reducer by checking whether we have references related to the deleted item resource and removing the deleted item from them.