From 0d29e8be2e145c2b8a3b981277d8199517ad977e Mon Sep 17 00:00:00 2001 From: SupaJoon Date: Fri, 13 Oct 2023 11:35:44 -0400 Subject: [PATCH] EVG-21077: Don't access undefined when destructuring useSpruceConfig (#2100) --- src/hooks/useSpruceConfig.ts | 7 ++++--- src/pages/distroSettings/tabs/GeneralTab/GeneralTab.tsx | 4 ++-- src/pages/distroSettings/tabs/ProviderTab/ProviderTab.tsx | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/hooks/useSpruceConfig.ts b/src/hooks/useSpruceConfig.ts index 0bf1ede1e3..860c60c75a 100644 --- a/src/hooks/useSpruceConfig.ts +++ b/src/hooks/useSpruceConfig.ts @@ -5,11 +5,12 @@ import { } from "gql/generated/types"; import { SPRUCE_CONFIG } from "gql/queries"; -export const useSpruceConfig = () => { +export const useSpruceConfig = (): + | SpruceConfigQuery["spruceConfig"] + | undefined => { const { data } = useQuery( SPRUCE_CONFIG ); - const { spruceConfig } = data || {}; - return spruceConfig; + return data?.spruceConfig; }; diff --git a/src/pages/distroSettings/tabs/GeneralTab/GeneralTab.tsx b/src/pages/distroSettings/tabs/GeneralTab/GeneralTab.tsx index 5202d65971..5f337aff40 100644 --- a/src/pages/distroSettings/tabs/GeneralTab/GeneralTab.tsx +++ b/src/pages/distroSettings/tabs/GeneralTab/GeneralTab.tsx @@ -12,9 +12,9 @@ export const GeneralTab: React.FC = ({ minimumHosts, }) => { const { distroId } = useParams(); - const { containerPools } = useSpruceConfig(); + const spruceConfig = useSpruceConfig(); const containerPoolDistros = - containerPools?.pools?.map(({ distro }) => distro) ?? []; + spruceConfig?.containerPools?.pools?.map(({ distro }) => distro) ?? []; const isContainerDistro = containerPoolDistros.includes(distroId); diff --git a/src/pages/distroSettings/tabs/ProviderTab/ProviderTab.tsx b/src/pages/distroSettings/tabs/ProviderTab/ProviderTab.tsx index 6b3ac18a31..3aaec5d1ee 100644 --- a/src/pages/distroSettings/tabs/ProviderTab/ProviderTab.tsx +++ b/src/pages/distroSettings/tabs/ProviderTab/ProviderTab.tsx @@ -32,8 +32,8 @@ export const ProviderTab: React.FC = ({ distro, distroData }) => { ); const { awsRegions } = awsData || {}; - const { containerPools } = useSpruceConfig(); - const { pools } = containerPools || {}; + const spruceConfig = useSpruceConfig(); + const { pools } = spruceConfig?.containerPools || {}; const selectedPoolId = formData?.dockerProviderSettings?.containerPoolId; const selectedPool = pools?.find((p) => p.id === selectedPoolId) ?? null;