Skip to content

Commit

Permalink
Upgraded to TanstackQuery v5
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenthoms committed Nov 3, 2023
1 parent 70972ec commit bd91487
Show file tree
Hide file tree
Showing 18 changed files with 126 additions and 143 deletions.
98 changes: 24 additions & 74 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"@headlessui/react": "^1.7.8",
"@mui/base": "^5.0.0-beta.3",
"@mui/icons-material": "^5.14.9",
"@tanstack/react-query": "^4.24.10",
"@tanstack/react-query-devtools": "^4.24.12",
"@tanstack/react-query": "^5.0.5",
"@tanstack/react-query-devtools": "^5.4.2",
"@webviz/subsurface-viewer": "^0.3.1",
"@webviz/well-completions-plot": "^0.0.1-alpha.1",
"animate.css": "^4.1.1",
Expand Down
11 changes: 5 additions & 6 deletions frontend/src/framework/internal/EnsembleSetLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { QueryClient } from "@tanstack/react-query";

import { Ensemble } from "../Ensemble";
import { EnsembleIdent } from "../EnsembleIdent";
import { Parameter, ParameterType, ContinuousParameter, DiscreteParameter } from "../EnsembleParameters";
import { ContinuousParameter, DiscreteParameter, Parameter, ParameterType } from "../EnsembleParameters";
import { Sensitivity, SensitivityCase } from "../EnsembleSensitivities";
import { EnsembleSet } from "../EnsembleSet";

Expand All @@ -29,23 +29,23 @@ export async function loadEnsembleSetMetadataFromBackend(
queryKey: ["getEnsembleDetails", caseUuid, ensembleName],
queryFn: () => apiService.explore.getEnsembleDetails(caseUuid, ensembleName),
staleTime: STALE_TIME,
cacheTime: CACHE_TIME,
gcTime: CACHE_TIME,
});
ensembleDetailsPromiseArr.push(ensembleDetailsPromise);

const parametersPromise = queryClient.fetchQuery({
queryKey: ["getParameters", caseUuid, ensembleName],
queryFn: () => apiService.parameters.getParameters(caseUuid, ensembleName),
staleTime: STALE_TIME,
cacheTime: CACHE_TIME,
gcTime: CACHE_TIME,
});
parametersPromiseArr.push(parametersPromise);

const sensitivitiesPromise = queryClient.fetchQuery({
queryKey: ["getSensitivities", caseUuid, ensembleName],
queryFn: () => apiService.parameters.getSensitivities(caseUuid, ensembleName),
staleTime: STALE_TIME,
cacheTime: CACHE_TIME,
gcTime: CACHE_TIME,
});
sensitivitiesPromiseArr.push(sensitivitiesPromise);
}
Expand Down Expand Up @@ -141,8 +141,7 @@ function buildParameterArrFromApiResponse(apiParameterArr: EnsembleParameter_api
values: apiPar.values as number[],
};
retParameterArr.push(retPar);
}
else {
} else {
const retPar: DiscreteParameter = {
type: ParameterType.DISCRETE,
name: apiPar.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function useUserInfoQuery(userId: string): UseQueryResult<GraphUserPhoto_api> {
queryKey: ["getUserInfo", userId],
queryFn: () => apiService.graph.userInfo(`${userId.toUpperCase()}@equinor.com`),
staleTime: STALE_TIME,
cacheTime: CACHE_TIME,
gcTime: CACHE_TIME,
enabled: userId !== "",
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const SelectEnsemblesDialog: React.FC<SelectEnsemblesDialogProps> = (prop
return apiService.explore.getCases(selectedField);
},
enabled: fieldsQuery.isSuccess,
cacheTime: CACHE_TIME,
gcTime: CACHE_TIME,
staleTime: STALE_TIME,
});

Expand All @@ -97,7 +97,7 @@ export const SelectEnsemblesDialog: React.FC<SelectEnsemblesDialogProps> = (prop
return apiService.explore.getEnsembles(selectedCaseId);
},
enabled: casesQuery.isSuccess,
cacheTime: CACHE_TIME,
gcTime: CACHE_TIME,
staleTime: STALE_TIME,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";

import { QueryCache, QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { MutationCache, QueryCache, QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";

import { AuthState, useAuthProvider } from "./AuthProvider";
Expand All @@ -25,12 +25,12 @@ export const CustomQueryClientProvider: React.FC<{ children: React.ReactElement
refetchOnWindowFocus: false,
refetchOnMount: false,
refetchOnReconnect: true,
cacheTime: 0,
gcTime: 0,
},
},
queryCache: new QueryCache({
onError: async (error) => {
if (error && (error as QueryError).status === 401) {
onError: (error) => {
if (error && (error as unknown as QueryError).status === 401) {
authProvider.setAuthState(AuthState.NotLoggedIn);
}
},
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/modules/Grid3D/queryHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function useGridSurface(
apiService.grid.gridSurface(caseUuid ?? "", ensembleName ?? "", gridName ?? "", realization ?? ""),
select: transformGridSurface,
staleTime: STALE_TIME,
cacheTime: 0,
gcTime: 0,
enabled: caseUuid && ensembleName && gridName && realization ? true : false,
});
}
Expand All @@ -43,7 +43,7 @@ export function useGridParameter(
realization ?? ""
),
staleTime: STALE_TIME,
cacheTime: 0,
gcTime: 0,
enabled: caseUuid && ensembleName && gridName && parameterName && realization && !useStatistics ? true : false,
});
}
Expand All @@ -67,7 +67,7 @@ export function useStatisticalGridParameter(
realizations ?? []
),
staleTime: STALE_TIME,
cacheTime: 0,
gcTime: 0,
enabled: caseUuid && ensembleName && gridName && parameterName && realizations && useStatistics ? true : false,
});
}
Expand All @@ -77,7 +77,7 @@ export function useGridModelNames(caseUuid: string | null, ensembleName: string
queryKey: ["getGridModelNames", caseUuid, ensembleName],
queryFn: () => apiService.grid.getGridModelNames(caseUuid ?? "", ensembleName ?? ""),
staleTime: STALE_TIME,
cacheTime: CACHE_TIME,
gcTime: CACHE_TIME,
enabled: caseUuid && ensembleName ? true : false,
});
}
Expand All @@ -91,7 +91,7 @@ export function useGridParameterNames(
queryKey: ["getParameterNames", caseUuid, ensembleName, gridName],
queryFn: () => apiService.grid.getParameterNames(caseUuid ?? "", ensembleName ?? "", gridName ?? ""),
staleTime: STALE_TIME,
cacheTime: CACHE_TIME,
gcTime: CACHE_TIME,
enabled: caseUuid && ensembleName && gridName ? true : false,
});
}
Expand All @@ -101,7 +101,7 @@ export function useGetWellHeaders(caseUuid: string | undefined): UseQueryResult<
queryKey: ["getWellHeaders", caseUuid],
queryFn: () => apiService.well.getWellHeaders(caseUuid ?? ""),
staleTime: STALE_TIME,
cacheTime: STALE_TIME,
gcTime: STALE_TIME,
enabled: caseUuid ? true : false,
});
}
Expand All @@ -111,7 +111,7 @@ export function useGetFieldWellsTrajectories(caseUuid: string | undefined): UseQ
queryKey: ["getFieldWellsTrajectories", caseUuid],
queryFn: () => apiService.well.getFieldWellTrajectories(caseUuid ?? ""),
staleTime: STALE_TIME,
cacheTime: CACHE_TIME,
gcTime: CACHE_TIME,
enabled: caseUuid ? true : false,
});
}
Loading

0 comments on commit bd91487

Please sign in to comment.