From c9f454854c7ff052a943498ef198eb1b631a1507 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Tue, 26 Nov 2024 09:46:20 +0800 Subject: [PATCH] use non mutating array .toReversed() instead of reversed() --- .../Pages/Infrastructure/Details/index.jsx | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Client/src/Pages/Infrastructure/Details/index.jsx b/Client/src/Pages/Infrastructure/Details/index.jsx index d3f10651f..801a0e672 100644 --- a/Client/src/Pages/Infrastructure/Details/index.jsx +++ b/Client/src/Pages/Infrastructure/Details/index.jsx @@ -206,9 +206,8 @@ const InfrastructureDetails = () => { (chartContainerHeight - totalChartContainerPadding - totalTypographyPadding) * 0.95; // end height calculations - const buildStatBoxes = (monitor) => { - let latestCheck = monitor?.checks[0] ?? null; - console.log(latestCheck); + const buildStatBoxes = (checks) => { + let latestCheck = checks[0] ?? null; if (latestCheck === null) return []; // Extract values from latest check @@ -270,8 +269,8 @@ const InfrastructureDetails = () => { ]; }; - const buildGaugeBoxConfigs = (monitor) => { - let latestCheck = monitor?.checks[0] ?? null; + const buildGaugeBoxConfigs = (checks) => { + let latestCheck = checks[0] ?? null; if (latestCheck === null) return []; // Extract values from latest check @@ -313,9 +312,8 @@ const InfrastructureDetails = () => { ]; }; - const buildTemps = (monitor) => { + const buildTemps = (checks) => { let numCores = 0; - const checks = monitor?.checks ?? null; if (checks === null) return []; for (const check of checks) { if (check.cpu.temperature.length > numCores) { @@ -346,17 +344,19 @@ const InfrastructureDetails = () => { } ); }); + // Slice to remove `createdAt` key return { tempKeys: Object.keys(temps[0]).slice(1), temps }; }; - const buildAreaChartConfigs = (monitor) => { - let latestCheck = monitor?.checks[0] ?? null; + const buildAreaChartConfigs = (checks) => { + let latestCheck = checks[0] ?? null; if (latestCheck === null) return []; - const tempData = buildTemps(monitor); + const reversedChecks = checks.toReversed(); + const tempData = buildTemps(reversedChecks); return [ { type: "memory", - data: monitor?.checks?.reverse() ?? [], + data: reversedChecks, dataKeys: ["memory.usage_percent"], heading: "Memory usage", strokeColor: theme.palette.primary.main, @@ -375,7 +375,7 @@ const InfrastructureDetails = () => { }, { type: "cpu", - data: monitor?.checks?.reverse() ?? [], + data: reversedChecks, dataKeys: ["cpu.usage_percent"], heading: "CPU usage", strokeColor: theme.palette.success.main, @@ -411,7 +411,7 @@ const InfrastructureDetails = () => { }, ...(latestCheck?.disk?.map((disk, idx) => ({ type: "disk", - data: monitor?.checks?.reverse() ?? [], + data: reversedChecks, diskIndex: idx, dataKeys: [`disk[${idx}].usage_percent`], heading: `Disk${idx} usage`, @@ -455,9 +455,9 @@ const InfrastructureDetails = () => { fetchData(); }, [authToken, monitorId, dateRange, navigate]); - const statBoxConfigs = buildStatBoxes(monitor); - const gaugeBoxConfigs = buildGaugeBoxConfigs(monitor); - const areaChartConfigs = buildAreaChartConfigs(monitor); + const statBoxConfigs = buildStatBoxes(monitor?.checks ?? []); + const gaugeBoxConfigs = buildGaugeBoxConfigs(monitor?.checks ?? []); + const areaChartConfigs = buildAreaChartConfigs(monitor?.checks ?? []); return (