Skip to content

Commit 7798f72

Browse files
committed
refactor!(react-query): update react query to v5
Lots of breaking changes in v5. Codemods didn't work due to a ESM/CJS issue. This commit won't work due to the v5 changes coming at the same time and DM API v2
1 parent 6eebf85 commit 7798f72

File tree

47 files changed

+267
-240
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+267
-240
lines changed

components/CreateDatasetStorageSubscription.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const CreateDatasetStorageSubscription = ({
5050
},
5151
});
5252
enqueueSnackbar("Created product", { variant: "success" });
53-
queryClient.invalidateQueries(getGetProductsQueryKey());
53+
queryClient.invalidateQueries({ queryKey: getGetProductsQueryKey() });
5454
} catch (error) {
5555
enqueueError(error);
5656
captureException(error);

components/MolCard/DepictMolecule.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,12 @@ const getImage = async (molFile: string, { depictURL, ...depictParams }: DepictP
9494
};
9595

9696
const useGetImage = (molFile: string, depictParams: DepictParameters) =>
97-
useQuery(
98-
[`depict-mol-${molFile}-${Object.values(depictParams).join(",")}`],
99-
() => getImage(molFile, depictParams),
100-
{
101-
refetchOnWindowFocus: false,
102-
staleTime: Infinity,
103-
},
104-
);
97+
useQuery({
98+
queryKey: [`depict-mol-${molFile}-${Object.values(depictParams).join(",")}`],
99+
queryFn: () => getImage(molFile, depictParams),
100+
refetchOnWindowFocus: false,
101+
staleTime: Infinity,
102+
});
105103

106104
const LazyMolFileImage = (props: Parameters<typeof MolFileImage>[0]) => {
107105
const [wasSeen, ref] = useWasSeen();

components/instances/ArchiveInstance.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export const ArchiveInstance = ({ instanceId, archived }: ArchiveInstanceProps)
2424
setArchiving(true);
2525
await patchInstance({ instanceId, params: { archive: !archived } });
2626
await Promise.allSettled([
27-
queryClient.invalidateQueries(getGetInstanceQueryKey(instanceId)),
28-
queryClient.invalidateQueries(getGetInstancesQueryKey()),
27+
queryClient.invalidateQueries({ queryKey: getGetInstanceQueryKey(instanceId) }),
28+
queryClient.invalidateQueries({ queryKey: getGetInstancesQueryKey() }),
2929
]);
3030
setArchiving(false);
3131
};

components/instances/TerminateInstance.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ export const TerminateInstance = ({
5050
onDelete={async () => {
5151
try {
5252
await terminateInstance({ instanceId });
53-
queryClient.invalidateQueries(getGetInstancesQueryKey());
54-
queryClient.invalidateQueries(getGetInstancesQueryKey({ project_id: projectId }));
53+
queryClient.invalidateQueries({ queryKey: getGetInstancesQueryKey() });
54+
queryClient.invalidateQueries({
55+
queryKey: getGetInstancesQueryKey({ project_id: projectId }),
56+
});
5557

5658
enqueueSnackbar(`Instance has been ${done ? "deleted" : "terminated"}`, {
5759
variant: "success",

components/labels/Labels.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const Labels = ({ datasetId, datasetVersion }: LabelsProps) => {
5757
]),
5858
},
5959
});
60-
queryClient.invalidateQueries(getGetDatasetsQueryKey());
60+
queryClient.invalidateQueries({ queryKey: getGetDatasetsQueryKey() });
6161
} catch (error) {
6262
enqueueError(error);
6363
}

components/labels/NewLabelButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const NewLabelButton = ({ datasetId }: NewLabelButtonProps) => {
6363
]),
6464
},
6565
});
66-
await queryClient.invalidateQueries(getGetDatasetsQueryKey());
66+
await queryClient.invalidateQueries({ queryKey: getGetDatasetsQueryKey() });
6767
} catch (error) {
6868
enqueueError(error);
6969
} finally {

components/products/AdjustProjectProduct.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ export const AdjustProjectProduct = ({ product, allowance }: AdjustProjectProduc
4848
try {
4949
await adjustProduct({ productId: product.id, data: values });
5050
await Promise.allSettled([
51-
queryClient.invalidateQueries(getGetProductsQueryKey()),
52-
queryClient.invalidateQueries(getGetProductQueryKey(product.id)),
51+
queryClient.invalidateQueries({ queryKey: getGetProductsQueryKey() }),
52+
queryClient.invalidateQueries({ queryKey: getGetProductQueryKey(product.id) }),
5353
]);
5454
enqueueSnackbar("Updated product", { variant: "success" });
5555
} catch (error) {

components/products/DeleteProductButton.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ export const DeleteProductButton = ({
3939
try {
4040
await deleteProduct({ productId: product.id });
4141
await Promise.allSettled([
42-
queryClient.invalidateQueries(getGetProductsQueryKey()),
43-
queryClient.invalidateQueries(getGetProductQueryKey(product.id)),
44-
queryClient.invalidateQueries(
45-
unitId ? getGetProductsForUnitQueryKey(unitId) : undefined,
46-
),
42+
queryClient.invalidateQueries({ queryKey: getGetProductsQueryKey() }),
43+
queryClient.invalidateQueries({ queryKey: getGetProductQueryKey(product.id) }),
44+
queryClient.invalidateQueries({
45+
queryKey: unitId ? getGetProductsForUnitQueryKey(unitId) : undefined,
46+
}),
4747
]);
4848
enqueueSnackbar("Product deleted", { variant: "success" });
4949
} catch (error) {

components/projects/CreateProjectForm.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ export const CreateProjectForm = ({ modal, unitId, product }: CreateProjectFormP
102102
});
103103
enqueueSnackbar("Project created");
104104

105-
queryClient.invalidateQueries(getGetProjectsQueryKey());
106-
queryClient.invalidateQueries(getGetProductsQueryKey());
105+
queryClient.invalidateQueries({ queryKey: getGetProjectsQueryKey() });
106+
queryClient.invalidateQueries({ queryKey: getGetProductsQueryKey() });
107107
typeof unitId === "string" &&
108-
queryClient.invalidateQueries(getGetProductsForUnitQueryKey(unitId));
108+
queryClient.invalidateQueries({ queryKey: getGetProductsForUnitQueryKey(unitId) });
109109

110110
setCurrentProjectId(project_id);
111111
} catch (error) {

components/projects/EditProjectButton/PrivateProjectToggle.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface PrivateProjectToggleProps {
1616
}
1717

1818
export const PrivateProjectToggle = ({ projectId, isPrivate }: PrivateProjectToggleProps) => {
19-
const { mutateAsync: adjustProject, isLoading } = usePatchProject();
19+
const { mutateAsync: adjustProject, isPending } = usePatchProject();
2020
const { enqueueError, enqueueSnackbar } = useEnqueueError();
2121
const queryClient = useQueryClient();
2222

@@ -27,7 +27,7 @@ export const PrivateProjectToggle = ({ projectId, isPrivate }: PrivateProjectTog
2727
checked={isPrivate}
2828
// Disable the switch until all relevant requests have resolved
2929
disabled={
30-
isLoading ||
30+
isPending ||
3131
(!!projectId &&
3232
queryClient.getQueryState(getGetProjectQueryKey(projectId))?.fetchStatus ===
3333
"fetching")
@@ -41,8 +41,8 @@ export const PrivateProjectToggle = ({ projectId, isPrivate }: PrivateProjectTog
4141
private: checked,
4242
},
4343
});
44-
queryClient.invalidateQueries(getGetProjectsQueryKey());
45-
queryClient.invalidateQueries(getGetProjectQueryKey(projectId));
44+
queryClient.invalidateQueries({ queryKey: getGetProjectsQueryKey() });
45+
queryClient.invalidateQueries({ queryKey: getGetProjectQueryKey(projectId) });
4646

4747
if (checked) {
4848
enqueueSnackbar("The project has been made private", { variant: "success" });

0 commit comments

Comments
 (0)