From c58dcc7c148449a905baff6d7d6f313683011623 Mon Sep 17 00:00:00 2001 From: Krishnan Subramanian Date: Thu, 29 Aug 2024 12:19:19 -0700 Subject: [PATCH 1/3] Fixing User management queries --- frontend/package-lock.json | 32 +++++++++---------- .../dashboard/ManageProfilesDashboard.tsx | 2 +- .../manageProfile/pages/EditUserDashboard.tsx | 7 ++-- .../manageProfile/pages/UserManagement.tsx | 7 ++-- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 37a030e3e..bbc276984 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -3835,11 +3835,11 @@ } }, "node_modules/axios": { - "version": "1.6.7", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.7.tgz", - "integrity": "sha512-/hDJGff6/c7u0hDkvkGxR/oy6CbCs8ziCsC7SqmhjfozqiJGc8Z11wrv9z9lYfY4K8l+H9TpjcMDX0xOZmx+RA==", + "version": "1.7.5", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.5.tgz", + "integrity": "sha512-fZu86yCo+svH3uqJ/yTdQ0QHpQu5oL+/QE+QPSv6BZSkDAoky9vytxp7u5qk83OJFS3kEBcesWni9WTZAv3tSw==", "dependencies": { - "follow-redirects": "^1.15.4", + "follow-redirects": "^1.15.6", "form-data": "^4.0.0", "proxy-from-env": "^1.1.0" } @@ -6797,12 +6797,12 @@ } }, "node_modules/micromatch": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", - "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", + "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", "dev": true, "dependencies": { - "braces": "^3.0.2", + "braces": "^3.0.3", "picomatch": "^2.3.1" }, "engines": { @@ -11850,11 +11850,11 @@ "dev": true }, "axios": { - "version": "1.6.7", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.7.tgz", - "integrity": "sha512-/hDJGff6/c7u0hDkvkGxR/oy6CbCs8ziCsC7SqmhjfozqiJGc8Z11wrv9z9lYfY4K8l+H9TpjcMDX0xOZmx+RA==", + "version": "1.7.5", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.5.tgz", + "integrity": "sha512-fZu86yCo+svH3uqJ/yTdQ0QHpQu5oL+/QE+QPSv6BZSkDAoky9vytxp7u5qk83OJFS3kEBcesWni9WTZAv3tSw==", "requires": { - "follow-redirects": "^1.15.4", + "follow-redirects": "^1.15.6", "form-data": "^4.0.0", "proxy-from-env": "^1.1.0" } @@ -14051,12 +14051,12 @@ "dev": true }, "micromatch": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", - "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", + "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", "dev": true, "requires": { - "braces": "^3.0.2", + "braces": "^3.0.3", "picomatch": "^2.3.1" } }, diff --git a/frontend/src/features/manageProfile/components/dashboard/ManageProfilesDashboard.tsx b/frontend/src/features/manageProfile/components/dashboard/ManageProfilesDashboard.tsx index e928f34f5..899fd397f 100644 --- a/frontend/src/features/manageProfile/components/dashboard/ManageProfilesDashboard.tsx +++ b/frontend/src/features/manageProfile/components/dashboard/ManageProfilesDashboard.tsx @@ -56,7 +56,7 @@ export const ManageProfilesDashboard = React.memo(() => { queryKey: ["companyInfo"], queryFn: getCompanyInfo, placeholderData: keepPreviousData, - staleTime: FIVE_MINUTES, + refetchInterval: FIVE_MINUTES }); const navigate = useNavigate(); diff --git a/frontend/src/features/manageProfile/pages/EditUserDashboard.tsx b/frontend/src/features/manageProfile/pages/EditUserDashboard.tsx index eb0f6ee9d..4919010fe 100644 --- a/frontend/src/features/manageProfile/pages/EditUserDashboard.tsx +++ b/frontend/src/features/manageProfile/pages/EditUserDashboard.tsx @@ -24,12 +24,13 @@ export const EditUserDashboard = React.memo(() => { const navigate = useNavigate(); const { userGUID } = useParams(); - const { data: userInfo, isPending } = useQuery({ + const { data: userInfo, isLoading } = useQuery({ queryKey: ["userByuserGUID", userGUID], queryFn: () => getCompanyUserByUserGUID(userGUID as string), retry: false, + refetchOnWindowFocus: false, enabled: true, - staleTime: Infinity, + gcTime: 0 // Disable saving in cache - Always fetch for latest data. }); const onClickBreadcrumb = () => { @@ -98,7 +99,7 @@ export const EditUserDashboard = React.memo(() => { Edit User - {!isPending && } + {!isLoading && } ); }); diff --git a/frontend/src/features/manageProfile/pages/UserManagement.tsx b/frontend/src/features/manageProfile/pages/UserManagement.tsx index ad0ea33b9..12c3713ac 100644 --- a/frontend/src/features/manageProfile/pages/UserManagement.tsx +++ b/frontend/src/features/manageProfile/pages/UserManagement.tsx @@ -1,5 +1,5 @@ import { Box } from "@mui/material"; -import { useQuery } from "@tanstack/react-query"; +import { keepPreviousData, useQuery } from "@tanstack/react-query"; import { RowSelectionState } from "@tanstack/table-core"; import { useCallback, useContext, useEffect, useState } from "react"; import { useAuth } from "react-oidc-context"; @@ -14,7 +14,6 @@ import { SnackBarContext } from "../../../App"; import { DeleteConfirmationDialog } from "../../../common/components/dialog/DeleteConfirmationDialog"; import { NoRecordsFound } from "../../../common/components/table/NoRecordsFound"; import { TrashButton } from "../../../common/components/buttons/TrashButton"; -import { ONE_HOUR } from "../../../common/constants/constants"; import { defaultTableInitialStateOptions, defaultTableOptions, @@ -41,7 +40,9 @@ export const UserManagement = () => { const query = useQuery({ queryKey: ["companyUsers"], queryFn: getCompanyUsers, - staleTime: ONE_HOUR, + placeholderData: keepPreviousData, + refetchOnWindowFocus: false, + retry: 1, }); const { data, isError, isLoading } = query; const { setSnackBar } = useContext(SnackBarContext); From 7de5ff213734b549ae41c0c5a7ec9df04aa2cd43 Mon Sep 17 00:00:00 2001 From: Krishnan Subramanian Date: Thu, 29 Aug 2024 12:28:49 -0700 Subject: [PATCH 2/3] isLoading to isPending --- .../src/features/manageProfile/pages/EditUserDashboard.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/features/manageProfile/pages/EditUserDashboard.tsx b/frontend/src/features/manageProfile/pages/EditUserDashboard.tsx index 4919010fe..661f6e886 100644 --- a/frontend/src/features/manageProfile/pages/EditUserDashboard.tsx +++ b/frontend/src/features/manageProfile/pages/EditUserDashboard.tsx @@ -24,7 +24,7 @@ export const EditUserDashboard = React.memo(() => { const navigate = useNavigate(); const { userGUID } = useParams(); - const { data: userInfo, isLoading } = useQuery({ + const { data: userInfo, isPending } = useQuery({ queryKey: ["userByuserGUID", userGUID], queryFn: () => getCompanyUserByUserGUID(userGUID as string), retry: false, @@ -99,7 +99,7 @@ export const EditUserDashboard = React.memo(() => { Edit User - {!isLoading && } + {!isPending && } ); }); From acb2f46c32682d703c48cdc4dda341de1fe8d4c1 Mon Sep 17 00:00:00 2001 From: Krishnan Subramanian Date: Thu, 29 Aug 2024 12:40:31 -0700 Subject: [PATCH 3/3] Correct vehicles query --- frontend/src/features/manageVehicles/hooks/vehicles.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/src/features/manageVehicles/hooks/vehicles.ts b/frontend/src/features/manageVehicles/hooks/vehicles.ts index 6d9ada6ba..500a0a218 100644 --- a/frontend/src/features/manageVehicles/hooks/vehicles.ts +++ b/frontend/src/features/manageVehicles/hooks/vehicles.ts @@ -32,5 +32,6 @@ export const useVehicleByIdQuery = ( refetchOnMount: "always", // always fetch when component is mounted refetchOnWindowFocus: false, // prevent unnecessary multiple queries on page showing up in foreground enabled: Boolean(companyId) && Boolean(vehicleId), // does not perform the query at all if company or vehicle id is empty + gcTime: 0, // Do not store in cache - Refetch always }); };