diff --git a/src/components/BulkEditPane/BulkEditListResult/BulkEditInAppPreviewModal/BulkEditPreviewModalList.js b/src/components/BulkEditPane/BulkEditListResult/BulkEditInAppPreviewModal/BulkEditPreviewModalList.js index b34f687f..aab38695 100644 --- a/src/components/BulkEditPane/BulkEditListResult/BulkEditInAppPreviewModal/BulkEditPreviewModalList.js +++ b/src/components/BulkEditPane/BulkEditListResult/BulkEditInAppPreviewModal/BulkEditPreviewModalList.js @@ -50,8 +50,8 @@ export const BulkEditPreviewModalList = ({ } = usePagination(PAGINATION_CONFIG); const [previewLoaded, setPreviewLoaded] = useState(false); - const interval = previewLoaded ? 0 : 3000; - const { bulkDetails } = useBulkOperationDetails({ id: bulkOperationId, interval }); + const interval = previewLoaded ? 0 : 1; + const { bulkDetails } = useBulkOperationDetails({ id: bulkOperationId, interval, cacheTime: 0, staleTime: 0 }); const visibleColumnKeys = getVisibleColumnsKeys(visibleColumns); const enabled = isPreviewEnabled && bulkDetails?.status === JOB_STATUSES.REVIEW_CHANGES; diff --git a/src/hooks/api/useRecordsPreview.js b/src/hooks/api/useRecordsPreview.js index e53e59cb..fa15a223 100644 --- a/src/hooks/api/useRecordsPreview.js +++ b/src/hooks/api/useRecordsPreview.js @@ -33,6 +33,7 @@ export const useRecordsPreview = ({ { queryKey: [key, namespaceKey, id, step, limit, offset], cacheTime: 0, + staleTime: 0, keepPreviousData: true, queryFn: () => { return ky.get(`bulk-operations/${id}/preview`, { searchParams: { limit, offset, step } }).json(); diff --git a/src/hooks/useConfirmChanges.js b/src/hooks/useConfirmChanges.js index 0f0d1533..32558977 100644 --- a/src/hooks/useConfirmChanges.js +++ b/src/hooks/useConfirmChanges.js @@ -36,21 +36,26 @@ export const useConfirmChanges = ({ const totalRecords = bulkDetails?.totalNumOfRecords; + const resetStatusToDataModification = () => { + queryClient.setQueriesData( + BULK_OPERATION_DETAILS_KEY, + (preBulkOperation) => ({ ...preBulkOperation, status: JOB_STATUSES.DATA_MODIFICATION }), + ); + }; + const openPreviewModal = () => { setIsPreviewModalOpened(true); }; const closePreviewModal = () => { setIsPreviewModalOpened(false); + resetStatusToDataModification(); }; const confirmChanges = (payload) => { - // as backend reset a status to 'DATA_MODIFICATION' only after the job started - // we need to set it manually to show the preview modal without a delay - queryClient.setQueriesData( - BULK_OPERATION_DETAILS_KEY, - (preBulkOperation) => ({ ...preBulkOperation, status: JOB_STATUSES.DATA_MODIFICATION }), - ); + resetStatusToDataModification(); + + queryClient.removeQueries(PREVIEW_MODAL_KEY); setIsPreviewModalOpened(true); setIsPreviewLoading(true); @@ -63,8 +68,6 @@ export const useConfirmChanges = ({ })) .then((response) => { showErrorMessage(response); - - queryClient.invalidateQueries(PREVIEW_MODAL_KEY); }) .catch((error) => { showErrorMessage(error);