add safety checks and simple empty view for details page

This commit is contained in:
Alex Holliday committed 2024-11-23 12:00:35 +08:00
1 parent 707836f86a
commit 55cf4e0cc8
1 file changed
+26 -15
@@ -16,6 +16,7 @@ import {
InfrastructureTooltip, InfrastructureTooltip,
} from "../../../Components/Charts/Utils/chartUtils"; } from "../../../Components/Charts/Utils/chartUtils";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { DateRangeIcon } from "@mui/x-date-pickers";
const BASE_BOX_PADDING_VERTICAL = 4; const BASE_BOX_PADDING_VERTICAL = 4;
const BASE_BOX_PADDING_HORIZONTAL = 8; const BASE_BOX_PADDING_HORIZONTAL = 8;
@@ -106,6 +107,7 @@ StatBox.propTypes = {
*/ */
const GaugeBox = ({ value, heading, metricOne, valueOne, metricTwo, valueTwo }) => { const GaugeBox = ({ value, heading, metricOne, valueOne, metricTwo, valueTwo }) => {
const theme = useTheme(); const theme = useTheme();
return ( return (
<BaseBox> <BaseBox>
<Stack <Stack
@@ -195,19 +197,20 @@ const InfrastructureDetails = () => {
numToDisplay: 50, numToDisplay: 50,
normalize: true, normalize: true,
}); });
setMonitor(response.data.data); setMonitor(response.data.data);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} }
}; };
fetchData(); fetchData();
}, []); }, [authToken, monitorId, dateRange]);
const statBoxConfigs = [ const statBoxConfigs = [
{ {
id: 0, id: 0,
heading: "CPU", heading: "CPU",
subHeading: `${monitor?.checks[0]?.cpu?.physical_core} cores`, subHeading: `${monitor?.checks[0]?.cpu?.physical_core ?? 0} cores`,
}, },
{ {
id: 1, id: 1,
@@ -230,26 +233,26 @@ const InfrastructureDetails = () => {
const gaugeBoxConfigs = [ const gaugeBoxConfigs = [
{ {
type: "memory", type: "memory",
value: monitor?.checks[0]?.memory?.usage_percent * 100, value: monitor?.checks[0]?.memory?.usage_percent ?? 0 * 100,
heading: "Memory Usage", heading: "Memory Usage",
metricOne: "Used", metricOne: "Used",
valueOne: formatBytes(monitor?.checks[0]?.memory?.used_bytes), valueOne: formatBytes(monitor?.checks[0]?.memory?.used_bytes ?? 0),
metricTwo: "Total", metricTwo: "Total",
valueTwo: formatBytes(monitor?.checks[0]?.memory?.total_bytes), valueTwo: formatBytes(monitor?.checks[0]?.memory?.total_bytes ?? 0),
}, },
{ {
type: "cpu", type: "cpu",
value: monitor?.checks[0]?.cpu?.usage_percent * 100, value: monitor?.checks[0]?.cpu?.usage_percent ?? 0 * 100,
heading: "CPU Usage", heading: "CPU Usage",
metricOne: "Cores", metricOne: "Cores",
valueOne: monitor?.checks[0]?.cpu?.physical_core, valueOne: monitor?.checks[0]?.cpu?.physical_core ?? 0,
metricTwo: "Frequency", metricTwo: "Frequency",
valueTwo: `${(monitor?.checks[0]?.cpu?.frequency / 1000).toFixed(2)} Ghz`, valueTwo: `${(monitor?.checks[0]?.cpu?.frequency ?? 0 / 1000).toFixed(2)} Ghz`,
}, },
...(monitor?.checks[0]?.disk ?? []).map((disk, idx) => ({ ...(monitor?.checks?.[0]?.disk ?? []).map((disk, idx) => ({
type: "disk", type: "disk",
diskIndex: idx, diskIndex: idx,
value: disk.usage_percent * 100, value: disk.usage_percent * 100 ?? 0,
heading: `Disk${idx} usage`, heading: `Disk${idx} usage`,
metricOne: "Used", metricOne: "Used",
valueOne: formatBytes(disk.total_bytes - disk.free_bytes), valueOne: formatBytes(disk.total_bytes - disk.free_bytes),
@@ -284,9 +287,9 @@ const InfrastructureDetails = () => {
]; ];
return ( return (
monitor && ( <Box>
<Box> <Breadcrumbs list={navList} />
<Breadcrumbs list={navList} /> {monitor?.checks?.length > 0 ? (
<Stack <Stack
direction="column" direction="column"
gap={theme.spacing(10)} gap={theme.spacing(10)}
@@ -392,8 +395,16 @@ const InfrastructureDetails = () => {
))} ))}
</Stack> </Stack>
</Stack> </Stack>
</Box> ) : (
) <Stack
direction="column"
gap={theme.spacing(10)}
mt={theme.spacing(10)}
>
<Typography variant="h2">Hang tight, there's no data yet</Typography>
</Stack>
)}
</Box>
); );
}; };