Skip to content

Commit

Permalink
refactor: Replace refetch key with refetchQueries.
Browse files Browse the repository at this point in the history
  • Loading branch information
mheggelund committed Jan 23, 2024
1 parent 7b6d62a commit 56a81f3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 1 addition & 3 deletions src/features/ModelTable/ModelTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,7 +32,7 @@ export const ModelTable = ({
const [toggle, setToggle] = useState<boolean>(false);
const [activeModel, setActiveModel] = useState<string>();
const { isLoading, data } = useQuery({
queryKey: ['analogue-models', refetchKey],
queryKey: ['analogue-models'],
queryFn: () => AnalogueModelsService.getApiAnalogueModels(),
enabled: !!token,
});
Expand Down
10 changes: 7 additions & 3 deletions src/pages/Browse/Browse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -48,7 +49,6 @@ export const Browse = () => {
const [uploadId, setUploadId] = useState<string>('');
const [isAddModelDialog, setAddModelDialog] = useState<boolean>(false);
const [uploadStatus, setUploadStatus] = useState<string>();
const [refetch, setRefetch] = useState<number>(0);
const [uploading, setUploading] = useState<boolean>(false);
const [transforming, setTransforming] = useState<boolean>(false);

Expand All @@ -67,6 +67,9 @@ export const Browse = () => {

const createModel = useMutation({
mutationFn: AnalogueModelsService.postApiAnalogueModels,
onSuccess: () => {
queryClient.refetchQueries({ queryKey: ['analogue-models'] });
},
});

const modelManifest = useMutation({
Expand All @@ -79,6 +82,9 @@ export const Browse = () => {

const uploadFinished = useMutation({
mutationFn: UploadsService.postApiUploadsModelsComplete,
onSuccess: () => {
queryClient.refetchQueries({ queryKey: ['analogue-models'] });
},
});

const convertModelFile = useMutation({
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -297,7 +302,6 @@ export const Browse = () => {
<Button onClick={toggleDialog}>Add new model</Button>
</div>
<ModelTable
refetchKey={refetch}
progress={progress}
activeUploadId={modelId}
transforming={transforming}
Expand Down
5 changes: 4 additions & 1 deletion src/pages/ModelPages/Compute/ComputeObject/ComputeObject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useMutation } from '@tanstack/react-query';
import { useState } from 'react';
import { useParams } from 'react-router-dom';
import { EstimateChannelCommand, JobsService } from '../../../../api/generated';
import { queryClient } from '../../../../auth/queryClient';
import { CaseGroup } from '../../../../features/Compute/CaseGroup/CaseGroup';
import { ComputeHeader } from '../../../../features/Compute/ComputeHeader/ComputeHeader';
import { useFetchCases } from '../../../../hooks/useFetchCases';
Expand Down Expand Up @@ -33,6 +34,9 @@ export const ComputeObject = () => {

const computeObject = useMutation({
mutationFn: JobsService.postApiJobsComputeChannelEstimations,
onSuccess: () => {
queryClient.refetchQueries({ queryKey: ['model-cases'] });
},
});

const runComputeObject = async (computeCaseId: string) => {
Expand All @@ -45,7 +49,6 @@ export const ComputeObject = () => {
const res = await computeObject.mutateAsync(requestBody);

if (res.success) {
uppdateCaseList();
setAlertMessage('Started computing case');
}
};
Expand Down

0 comments on commit 56a81f3

Please sign in to comment.