fix: fix record deletion optimistic effect (#3683)

* fix: fix record deletion optimistic effect

* fix: fix renamed method after rebase

* Re-add evict

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Thaïs
2024-01-30 05:33:28 -03:00
committed by GitHub
parent e951fb70f8
commit 49f33bbe2e
6 changed files with 52 additions and 42 deletions

View File

@ -29,7 +29,7 @@ export const triggerCreateRecordsOptimisticEffect = ({
[objectMetadataItem.namePlural]: (
cachedConnection,
{
INVALIDATE: _INVALIDATE,
DELETE: _DELETE,
readField,
storeFieldName: _storeFieldName,
toReference,
@ -97,7 +97,7 @@ export const triggerCreateRecordsOptimisticEffect = ({
cachedEdges?.length === variables.first &&
nextCachedEdges.length < variables.first
) {
return INVALIDATE;
return DELETE;
}
if (nextCachedEdges.length > variables.first) {

View File

@ -21,7 +21,7 @@ export const triggerDeleteRecordsOptimisticEffect = ({
fields: {
[objectMetadataItem.namePlural]: (
cachedConnection,
{ INVALIDATE, readField, storeFieldName },
{ DELETE, readField, storeFieldName },
) => {
if (
!isCachedObjectConnection(
@ -49,12 +49,14 @@ export const triggerDeleteRecordsOptimisticEffect = ({
return nodeId && !recordIds.includes(nodeId);
}) || [];
if (nextCachedEdges.length === cachedEdges?.length)
return cachedConnection;
if (
isDefined(variables?.first) &&
cachedEdges?.length === variables.first &&
nextCachedEdges.length < variables.first
cachedEdges?.length === variables.first
) {
return INVALIDATE;
return DELETE;
}
return { ...cachedConnection, edges: nextCachedEdges };

View File

@ -28,7 +28,7 @@ export const triggerUpdateRecordOptimisticEffect = ({
fields: {
[objectMetadataItem.namePlural]: (
cachedConnection,
{ INVALIDATE, readField, storeFieldName, toReference },
{ DELETE, readField, storeFieldName, toReference },
) => {
if (
!isCachedObjectConnection(
@ -93,7 +93,7 @@ export const triggerUpdateRecordOptimisticEffect = ({
cachedEdges?.length === variables.first &&
nextCachedEdges.length < variables.first
) {
return INVALIDATE;
return DELETE;
}
// If next edges length exceeds the required limit,