9018 fix batch delete follow ups (#9166)

Follow ups on #9018
This commit is contained in:
Raphaël Bosi
2024-12-20 11:41:09 +01:00
committed by GitHub
parent 2437572a5c
commit 1acf845101
19 changed files with 93 additions and 47 deletions

View File

@ -1,6 +1,5 @@
import { useApolloClient } from '@apollo/client';
import { triggerUpdateRecordOptimisticEffect } from '@/apollo/optimistic-effect/utils/triggerUpdateRecordOptimisticEffect';
import { triggerUpdateRecordOptimisticEffectByBatch } from '@/apollo/optimistic-effect/utils/triggerUpdateRecordOptimisticEffectByBatch';
import { apiConfigState } from '@/client-config/states/apiConfigState';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
@ -145,6 +144,9 @@ export const useDeleteManyRecords = ({
},
})
.catch((error: Error) => {
const cachedRecordsWithConnection: RecordGqlNode[] = [];
const optimisticRecordsWithConnection: RecordGqlNode[] = [];
cachedRecords.forEach((cachedRecord) => {
if (isUndefinedOrNull(cachedRecord?.id)) {
return;
@ -183,16 +185,21 @@ export const useDeleteManyRecords = ({
!optimisticRecordWithConnection ||
!cachedRecordWithConnection
) {
return null;
return;
}
triggerUpdateRecordOptimisticEffect({
cache: apolloClient.cache,
objectMetadataItem,
currentRecord: optimisticRecordWithConnection,
updatedRecord: cachedRecordWithConnection,
objectMetadataItems,
});
cachedRecordsWithConnection.push(cachedRecordWithConnection);
optimisticRecordsWithConnection.push(
optimisticRecordWithConnection,
);
});
triggerUpdateRecordOptimisticEffectByBatch({
cache: apolloClient.cache,
objectMetadataItem,
currentRecords: optimisticRecordsWithConnection,
updatedRecords: cachedRecordsWithConnection,
objectMetadataItems,
});
throw error;

View File

@ -230,7 +230,6 @@ export const RecordIndexContainer = () => {
objectNamePlural={objectNamePlural}
viewBarId={recordIndexId}
/>
<RecordIndexTableContainerEffect />
</SpreadsheetImportProvider>
<RecordIndexFiltersToContextStoreEffect />
{recordIndexViewType === ViewType.Table && (