From 56a81f3defb5a656868bac3ab0b542844232f2fd Mon Sep 17 00:00:00 2001 From: mheggelund Date: Tue, 23 Jan 2024 10:00:42 +0100 Subject: [PATCH] refactor: Replace refetch key with refetchQueries. --- src/features/ModelTable/ModelTable.tsx | 4 +--- src/pages/Browse/Browse.tsx | 10 +++++++--- .../ModelPages/Compute/ComputeObject/ComputeObject.tsx | 5 ++++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/features/ModelTable/ModelTable.tsx b/src/features/ModelTable/ModelTable.tsx index 626b1a02..7676f3d1 100644 --- a/src/features/ModelTable/ModelTable.tsx +++ b/src/features/ModelTable/ModelTable.tsx @@ -16,12 +16,10 @@ import { useAccessToken } from '../../hooks/useAccessToken'; import * as Styled from './ModelTable.styled'; export const ModelTable = ({ - refetchKey, progress, activeUploadId, transforming, }: { - refetchKey: number; progress: number; activeUploadId: string; transforming: boolean; @@ -34,7 +32,7 @@ export const ModelTable = ({ const [toggle, setToggle] = useState(false); const [activeModel, setActiveModel] = useState(); const { isLoading, data } = useQuery({ - queryKey: ['analogue-models', refetchKey], + queryKey: ['analogue-models'], queryFn: () => AnalogueModelsService.getApiAnalogueModels(), enabled: !!token, }); diff --git a/src/pages/Browse/Browse.tsx b/src/pages/Browse/Browse.tsx index 5ef6654d..cf9c5689 100644 --- a/src/pages/Browse/Browse.tsx +++ b/src/pages/Browse/Browse.tsx @@ -21,6 +21,7 @@ import { UploadFileType, UploadsService, } from '../../api/generated'; +import { queryClient } from '../../auth/queryClient'; import { AddModelDialog } from '../../features/AddModel/AddModelDialog/AddModelDialog'; import { ModelTable } from '../../features/ModelTable/ModelTable'; import * as Styled from './Browse.styled'; @@ -48,7 +49,6 @@ export const Browse = () => { const [uploadId, setUploadId] = useState(''); const [isAddModelDialog, setAddModelDialog] = useState(false); const [uploadStatus, setUploadStatus] = useState(); - const [refetch, setRefetch] = useState(0); const [uploading, setUploading] = useState(false); const [transforming, setTransforming] = useState(false); @@ -67,6 +67,9 @@ export const Browse = () => { const createModel = useMutation({ mutationFn: AnalogueModelsService.postApiAnalogueModels, + onSuccess: () => { + queryClient.refetchQueries({ queryKey: ['analogue-models'] }); + }, }); const modelManifest = useMutation({ @@ -79,6 +82,9 @@ export const Browse = () => { const uploadFinished = useMutation({ mutationFn: UploadsService.postApiUploadsModelsComplete, + onSuccess: () => { + queryClient.refetchQueries({ queryKey: ['analogue-models'] }); + }, }); const convertModelFile = useMutation({ @@ -180,7 +186,6 @@ export const Browse = () => { if (createModel.error === null && modelUpload.success) { const id = modelUpload.data.analogueModelId; setModelId(id); - setRefetch(refetch + 1); setProgress(1); uploadMetadata(id, metadata); @@ -297,7 +302,6 @@ export const Browse = () => { { const computeObject = useMutation({ mutationFn: JobsService.postApiJobsComputeChannelEstimations, + onSuccess: () => { + queryClient.refetchQueries({ queryKey: ['model-cases'] }); + }, }); const runComputeObject = async (computeCaseId: string) => { @@ -45,7 +49,6 @@ export const ComputeObject = () => { const res = await computeObject.mutateAsync(requestBody); if (res.success) { - uppdateCaseList(); setAlertMessage('Started computing case'); } };