Skip to content

Commit

Permalink
EVG-21077: Don't access undefined when destructuring useSpruceConfig (e…
Browse files Browse the repository at this point in the history
  • Loading branch information
SupaJoon authored Oct 13, 2023
1 parent 07a2fdc commit 0d29e8b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/hooks/useSpruceConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SpruceConfigQuery, SpruceConfigQueryVariables>(
SPRUCE_CONFIG
);

const { spruceConfig } = data || {};
return spruceConfig;
return data?.spruceConfig;
};
4 changes: 2 additions & 2 deletions src/pages/distroSettings/tabs/GeneralTab/GeneralTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export const GeneralTab: React.FC<TabProps> = ({
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);

Expand Down
4 changes: 2 additions & 2 deletions src/pages/distroSettings/tabs/ProviderTab/ProviderTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export const ProviderTab: React.FC<TabProps> = ({ 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;
Expand Down

0 comments on commit 0d29e8b

Please sign in to comment.