[BUG] Handle optimistic cache deletion operation (#9914)
# Introduction This PR is highly related to previous optimistic cache refactor: https://github.com/twentyhq/twenty/pull/9881 Here we've added some logic within the `triggerUpdateRelationsOptimisticEffect` which will now run if given recordInput `deletedAt` field is defined. If deletion, we will iterate over all the fields searching for `RELATION` for which deletion might implies necessity to detach the relation ## Known troubleshooting ( also on main )  We might have to refactor the `prefillRecord` to spread and overrides`inputValue` over defaultOne as inputValue could be a partial one for more info please a look to # Conclusion Any suggestions are welcomed ! fixes https://github.com/twentyhq/twenty/issues/9580 --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
import { DeleteManyRecordsProps } from '@/object-record/hooks/useDeleteManyRecords';
|
||||
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
|
||||
import { renderHook, waitFor } from '@testing-library/react';
|
||||
import { act } from 'react';
|
||||
@ -75,13 +76,12 @@ describe('useDeleteMultipleRecordsAction', () => {
|
||||
result.current.ConfirmationModal?.props?.onConfirmClick();
|
||||
});
|
||||
|
||||
const expectedParams: DeleteManyRecordsProps = {
|
||||
recordIdsToDelete: [peopleMock[0].id, peopleMock[1].id],
|
||||
};
|
||||
await waitFor(() => {
|
||||
expect(resetTableRowSelectionMock).toHaveBeenCalled();
|
||||
|
||||
expect(deleteManyRecordsMock).toHaveBeenCalledWith([
|
||||
peopleMock[0].id,
|
||||
peopleMock[1].id,
|
||||
]);
|
||||
expect(deleteManyRecordsMock).toHaveBeenCalledWith(expectedParams);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -73,7 +73,9 @@ export const useDeleteMultipleRecordsAction: ActionHookWithObjectMetadataItem =
|
||||
|
||||
resetTableRowSelection();
|
||||
|
||||
await deleteManyRecords(recordIdsToDelete);
|
||||
await deleteManyRecords({
|
||||
recordIdsToDelete,
|
||||
});
|
||||
}, [deleteManyRecords, fetchAllRecordIds, resetTableRowSelection]);
|
||||
|
||||
const isRemoteObject = objectMetadataItem.isRemote;
|
||||
|
||||
@ -4,11 +4,13 @@ import { ActionMenuContext } from '@/action-menu/contexts/ActionMenuContext';
|
||||
import { useDestroyOneRecord } from '@/object-record/hooks/useDestroyOneRecord';
|
||||
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
|
||||
import { useRecordTable } from '@/object-record/record-table/hooks/useRecordTable';
|
||||
import { AppPath } from '@/types/AppPath';
|
||||
import { ConfirmationModal } from '@/ui/layout/modal/components/ConfirmationModal';
|
||||
import { useRightDrawer } from '@/ui/layout/right-drawer/hooks/useRightDrawer';
|
||||
import { useCallback, useContext, useState } from 'react';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { isDefined } from 'twenty-ui';
|
||||
import { useNavigateApp } from '~/hooks/useNavigateApp';
|
||||
|
||||
export const useDestroySingleRecordAction: ActionHookWithObjectMetadataItem = ({
|
||||
objectMetadataItem,
|
||||
@ -18,6 +20,8 @@ export const useDestroySingleRecordAction: ActionHookWithObjectMetadataItem = ({
|
||||
const [isDestroyRecordsModalOpen, setIsDestroyRecordsModalOpen] =
|
||||
useState(false);
|
||||
|
||||
const navigateApp = useNavigateApp();
|
||||
|
||||
const { resetTableRowSelection } = useRecordTable({
|
||||
recordTableId: objectMetadataItem.namePlural,
|
||||
});
|
||||
@ -34,7 +38,16 @@ export const useDestroySingleRecordAction: ActionHookWithObjectMetadataItem = ({
|
||||
resetTableRowSelection();
|
||||
|
||||
await destroyOneRecord(recordId);
|
||||
}, [resetTableRowSelection, destroyOneRecord, recordId]);
|
||||
navigateApp(AppPath.RecordIndexPage, {
|
||||
objectNamePlural: objectMetadataItem.namePlural,
|
||||
});
|
||||
}, [
|
||||
resetTableRowSelection,
|
||||
destroyOneRecord,
|
||||
recordId,
|
||||
navigateApp,
|
||||
objectMetadataItem.namePlural,
|
||||
]);
|
||||
|
||||
const isRemoteObject = objectMetadataItem.isRemote;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user