From 737c8598d371ae9d0d019481ecbeb3168c0e2403 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Fri, 13 May 2022 13:51:43 -0400 Subject: [PATCH] fix(striker-ui): avoid crash in Memory when returned data is incomplete --- striker-ui/components/Memory.tsx | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/striker-ui/components/Memory.tsx b/striker-ui/components/Memory.tsx index 6c3d85cb..45de6186 100644 --- a/striker-ui/components/Memory.tsx +++ b/striker-ui/components/Memory.tsx @@ -1,12 +1,13 @@ import { useContext } from 'react'; import { Box } from '@mui/material'; import * as prettyBytes from 'pretty-bytes'; -import { Panel } from './Panels'; + +import { AnvilContext } from './AnvilContext'; import { AllocationBar } from './Bars'; -import { HeaderText, BodyText } from './Text'; +import { Panel } from './Panels'; import periodicFetch from '../lib/fetchers/periodicFetch'; -import { AnvilContext } from './AnvilContext'; import Spinner from './Spinner'; +import { HeaderText, BodyText } from './Text'; const Memory = (): JSX.Element => { const { uuid } = useContext(AnvilContext); @@ -14,46 +15,39 @@ const Memory = (): JSX.Element => { `${process.env.NEXT_PUBLIC_API_URL}/get_memory?anvil_uuid=${uuid}`, ); - const memoryData = - isLoading || !data ? { total: 0, allocated: 0, reserved: 0 } : data; + const { allocated = 0, total = 0, reserved = 0 } = data ?? {}; return ( {!isLoading ? ( <> - {' '} - +