From baa7c468bcf636c71f01078cf963dba4221dcac9 Mon Sep 17 00:00:00 2001 From: Maina Wycliffe Date: Tue, 10 Sep 2024 17:23:21 +0300 Subject: [PATCH] fix: fix issue with catalog page crashing after inactivity --- src/api/query-hooks/index.ts | 11 +++++++---- .../ConfigsListFilters/ConfigLabelsDropdown.tsx | 7 ++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/api/query-hooks/index.ts b/src/api/query-hooks/index.ts index 90df51031..ac7b1155f 100644 --- a/src/api/query-hooks/index.ts +++ b/src/api/query-hooks/index.ts @@ -1,7 +1,6 @@ import { tristateOutputToQueryFilterParam } from "@flanksource-ui/ui/Dropdowns/TristateReactSelect"; import { UseQueryOptions, useQuery } from "@tanstack/react-query"; import { isNull } from "lodash"; -import { CostsData } from "../../api/types/common"; import { toastError } from "../../components/Toast/toast"; import { getIncidentHistory } from "../services/IncidentsHistory"; import { getAllAgents } from "../services/agents"; @@ -30,6 +29,7 @@ import { getTopologyNameByID } from "../services/topology"; import { getPersons, getVersionInfo } from "../services/users"; +import { Analysis } from "../types/configs"; import { IncidentHistory } from "../types/incident"; import { ComponentTeamItem } from "../types/topology"; @@ -372,7 +372,10 @@ export function useGetConfigLabelsListQuery() { throw error; } return data ?? []; - } + }, + // 1 minute + cacheTime: 1000 * 60, + staleTime: 1000 * 60 }); } @@ -435,9 +438,9 @@ export function useIncidentsHistoryQuery( export function useConfigAnalysisQuery( configId: string, - options?: UseQueryOptions + options?: UseQueryOptions ) { - return useQuery( + return useQuery( ["config_analysis", configId], () => getConfigAnalysis(configId), options diff --git a/src/components/Configs/ConfigsListFilters/ConfigLabelsDropdown.tsx b/src/components/Configs/ConfigsListFilters/ConfigLabelsDropdown.tsx index a11f4094f..5ad4f55d6 100644 --- a/src/components/Configs/ConfigsListFilters/ConfigLabelsDropdown.tsx +++ b/src/components/Configs/ConfigsListFilters/ConfigLabelsDropdown.tsx @@ -15,7 +15,7 @@ export function ConfigLabelsDropdown({ searchParamKey = "labels" }: Props) { const { data, isLoading } = useGetConfigLabelsListQuery(); const labelItems = useMemo(() => { - if (data) { + if (data && Array.isArray(data)) { const options = data.map((tag) => ({ label: (
@@ -26,6 +26,11 @@ export function ConfigLabelsDropdown({ searchParamKey = "labels" }: Props) { value: `${tag.key}__:__${tag.value}` })); return [{ label: "All", value: "All" }, ...options]; + } else { + // Adding this console.error to help debug the issue I noticed happening + // inside the Saas, that's leading to the catalog page crashing + console.error("Invalid data for ConfigLabelsDropdown", data); + return [{ label: "All", value: "All" }]; } }, [data]);