use non mutating array .toReversed() instead of reversed()
This commit is contained in:
1 parent
bb2f2450fd
commit
c9f454854c
1 file changed
+16
-16
@@ -206,9 +206,8 @@ const InfrastructureDetails = () => {
|
|||||||
(chartContainerHeight - totalChartContainerPadding - totalTypographyPadding) * 0.95;
|
(chartContainerHeight - totalChartContainerPadding - totalTypographyPadding) * 0.95;
|
||||||
// end height calculations
|
// end height calculations
|
||||||
|
|
||||||
const buildStatBoxes = (monitor) => {
|
const buildStatBoxes = (checks) => {
|
||||||
let latestCheck = monitor?.checks[0] ?? null;
|
let latestCheck = checks[0] ?? null;
|
||||||
console.log(latestCheck);
|
|
||||||
if (latestCheck === null) return [];
|
if (latestCheck === null) return [];
|
||||||
|
|
||||||
// Extract values from latest check
|
// Extract values from latest check
|
||||||
@@ -270,8 +269,8 @@ const InfrastructureDetails = () => {
|
|||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
const buildGaugeBoxConfigs = (monitor) => {
|
const buildGaugeBoxConfigs = (checks) => {
|
||||||
let latestCheck = monitor?.checks[0] ?? null;
|
let latestCheck = checks[0] ?? null;
|
||||||
if (latestCheck === null) return [];
|
if (latestCheck === null) return [];
|
||||||
|
|
||||||
// Extract values from latest check
|
// Extract values from latest check
|
||||||
@@ -313,9 +312,8 @@ const InfrastructureDetails = () => {
|
|||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
const buildTemps = (monitor) => {
|
const buildTemps = (checks) => {
|
||||||
let numCores = 0;
|
let numCores = 0;
|
||||||
const checks = monitor?.checks ?? null;
|
|
||||||
if (checks === null) return [];
|
if (checks === null) return [];
|
||||||
for (const check of checks) {
|
for (const check of checks) {
|
||||||
if (check.cpu.temperature.length > numCores) {
|
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 };
|
return { tempKeys: Object.keys(temps[0]).slice(1), temps };
|
||||||
};
|
};
|
||||||
|
|
||||||
const buildAreaChartConfigs = (monitor) => {
|
const buildAreaChartConfigs = (checks) => {
|
||||||
let latestCheck = monitor?.checks[0] ?? null;
|
let latestCheck = checks[0] ?? null;
|
||||||
if (latestCheck === null) return [];
|
if (latestCheck === null) return [];
|
||||||
const tempData = buildTemps(monitor);
|
const reversedChecks = checks.toReversed();
|
||||||
|
const tempData = buildTemps(reversedChecks);
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
type: "memory",
|
type: "memory",
|
||||||
data: monitor?.checks?.reverse() ?? [],
|
data: reversedChecks,
|
||||||
dataKeys: ["memory.usage_percent"],
|
dataKeys: ["memory.usage_percent"],
|
||||||
heading: "Memory usage",
|
heading: "Memory usage",
|
||||||
strokeColor: theme.palette.primary.main,
|
strokeColor: theme.palette.primary.main,
|
||||||
@@ -375,7 +375,7 @@ const InfrastructureDetails = () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: "cpu",
|
type: "cpu",
|
||||||
data: monitor?.checks?.reverse() ?? [],
|
data: reversedChecks,
|
||||||
dataKeys: ["cpu.usage_percent"],
|
dataKeys: ["cpu.usage_percent"],
|
||||||
heading: "CPU usage",
|
heading: "CPU usage",
|
||||||
strokeColor: theme.palette.success.main,
|
strokeColor: theme.palette.success.main,
|
||||||
@@ -411,7 +411,7 @@ const InfrastructureDetails = () => {
|
|||||||
},
|
},
|
||||||
...(latestCheck?.disk?.map((disk, idx) => ({
|
...(latestCheck?.disk?.map((disk, idx) => ({
|
||||||
type: "disk",
|
type: "disk",
|
||||||
data: monitor?.checks?.reverse() ?? [],
|
data: reversedChecks,
|
||||||
diskIndex: idx,
|
diskIndex: idx,
|
||||||
dataKeys: [`disk[${idx}].usage_percent`],
|
dataKeys: [`disk[${idx}].usage_percent`],
|
||||||
heading: `Disk${idx} usage`,
|
heading: `Disk${idx} usage`,
|
||||||
@@ -455,9 +455,9 @@ const InfrastructureDetails = () => {
|
|||||||
fetchData();
|
fetchData();
|
||||||
}, [authToken, monitorId, dateRange, navigate]);
|
}, [authToken, monitorId, dateRange, navigate]);
|
||||||
|
|
||||||
const statBoxConfigs = buildStatBoxes(monitor);
|
const statBoxConfigs = buildStatBoxes(monitor?.checks ?? []);
|
||||||
const gaugeBoxConfigs = buildGaugeBoxConfigs(monitor);
|
const gaugeBoxConfigs = buildGaugeBoxConfigs(monitor?.checks ?? []);
|
||||||
const areaChartConfigs = buildAreaChartConfigs(monitor);
|
const areaChartConfigs = buildAreaChartConfigs(monitor?.checks ?? []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
|
|||||||
Reference in new issue
Block a user