safe access of temp data, don't render charts without data
This commit is contained in:
1 parent
058ef1501e
commit
7fb51e5801
1 file changed
+40
-30
@@ -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,30 +536,36 @@ const InfrastructureDetails = () => {
|
|||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{areaChartConfigs.map((config) => (
|
{areaChartConfigs.map((config) => {
|
||||||
<BaseBox key={`${config.type}-${config.diskIndex ?? ""}`}>
|
if (config?.data?.length === 0) {
|
||||||
<Typography
|
return;
|
||||||
component="h2"
|
}
|
||||||
padding={theme.spacing(8)}
|
|
||||||
>
|
return (
|
||||||
{config.heading}
|
<BaseBox key={`${config.type}-${config.diskIndex ?? ""}`}>
|
||||||
</Typography>
|
<Typography
|
||||||
<AreaChart
|
component="h2"
|
||||||
height={areaChartHeight}
|
padding={theme.spacing(8)}
|
||||||
data={config.data}
|
>
|
||||||
dataKeys={config.dataKeys}
|
{config.heading}
|
||||||
xKey="createdAt"
|
</Typography>
|
||||||
yDomain={config.yDomain}
|
<AreaChart
|
||||||
customTooltip={config.toolTip}
|
height={areaChartHeight}
|
||||||
xTick={config.xTick}
|
data={config.data}
|
||||||
yTick={config.yTick}
|
dataKeys={config.dataKeys}
|
||||||
strokeColor={config.strokeColor}
|
xKey="createdAt"
|
||||||
gradient={true}
|
yDomain={config.yDomain}
|
||||||
gradientStartColor={config.gradientStartColor}
|
customTooltip={config.toolTip}
|
||||||
gradientEndColor="#ffffff"
|
xTick={config.xTick}
|
||||||
/>
|
yTick={config.yTick}
|
||||||
</BaseBox>
|
strokeColor={config.strokeColor}
|
||||||
))}
|
gradient={true}
|
||||||
|
gradientStartColor={config.gradientStartColor}
|
||||||
|
gradientEndColor="#ffffff"
|
||||||
|
/>
|
||||||
|
</BaseBox>
|
||||||
|
);
|
||||||
|
})}
|
||||||
</Stack>
|
</Stack>
|
||||||
</Stack>
|
</Stack>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
Reference in new issue
Block a user