safe access of temp data, don't render charts without data

This commit is contained in:
Alex Holliday committed 2024-11-26 14:54:32 +08:00
1 parent 058ef1501e
commit 7fb51e5801
1 file changed
+18 -8
@@ -20,7 +20,6 @@ import {
TemperatureTooltip, TemperatureTooltip,
} from "../../../Components/Charts/Utils/chartUtils"; } from "../../../Components/Charts/Utils/chartUtils";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import Monitors from "../../Monitors/Home";
const BASE_BOX_PADDING_VERTICAL = 4; const BASE_BOX_PADDING_VERTICAL = 4;
const BASE_BOX_PADDING_HORIZONTAL = 8; const BASE_BOX_PADDING_HORIZONTAL = 8;
@@ -314,15 +313,15 @@ const InfrastructureDetails = () => {
const buildTemps = (checks) => { const buildTemps = (checks) => {
let numCores = 0; let numCores = 0;
if (checks === null) return []; if (checks === null) return { temps: [], tempKeys: [] };
for (const check of checks) { for (const check of checks) {
if (check.cpu.temperature.length > numCores) { if (check?.cpu?.temperature?.length > numCores) {
numCores = check.cpu.temperature.length; numCores = check.cpu.temperature.length;
break; break;
} }
} }
if (numCores === 0) return { temps: [], tempKeys: [] };
if (numCores === 0) return [];
const temps = checks.map((check) => { const temps = checks.map((check) => {
if (check.cpu.temperature.length > numCores) { if (check.cpu.temperature.length > numCores) {
@@ -401,7 +400,12 @@ const InfrastructureDetails = () => {
heading: "CPU Temperature", heading: "CPU Temperature",
yLabel: "Temperature", yLabel: "Temperature",
xTick: <TzTick />, xTick: <TzTick />,
yDomain: [0, 200], yDomain: [
Math.min(...tempData.temps.flatMap((t) => tempData.tempKeys.map((k) => t[k]))) *
0.9,
Math.max(...tempData.temps.flatMap((t) => tempData.tempKeys.map((k) => t[k]))) *
1.1,
],
toolTip: ( toolTip: (
<TemperatureTooltip <TemperatureTooltip
keys={tempData.tempKeys} keys={tempData.tempKeys}
@@ -532,7 +536,12 @@ const InfrastructureDetails = () => {
}, },
}} }}
> >
{areaChartConfigs.map((config) => ( {areaChartConfigs.map((config) => {
if (config?.data?.length === 0) {
return;
}
return (
<BaseBox key={`${config.type}-${config.diskIndex ?? ""}`}> <BaseBox key={`${config.type}-${config.diskIndex ?? ""}`}>
<Typography <Typography
component="h2" component="h2"
@@ -555,7 +564,8 @@ const InfrastructureDetails = () => {
gradientEndColor="#ffffff" gradientEndColor="#ffffff"
/> />
</BaseBox> </BaseBox>
))} );
})}
</Stack> </Stack>
</Stack> </Stack>
) : ( ) : (