revert to mapping twice
This commit is contained in:
1 parent
f0d60b737d
commit
4106a66523
1 file changed
+47
-33
@@ -125,7 +125,7 @@ function Infrastructure() {
|
|||||||
|
|
||||||
const { determineState } = useUtils();
|
const { determineState } = useUtils();
|
||||||
const { monitors, total: totalMonitors } = monitorState;
|
const { monitors, total: totalMonitors } = monitorState;
|
||||||
|
// do it here
|
||||||
function openDetails(id) {
|
function openDetails(id) {
|
||||||
navigate(`/infrastructure/${id}`);
|
navigate(`/infrastructure/${id}`);
|
||||||
}
|
}
|
||||||
@@ -133,6 +133,38 @@ function Infrastructure() {
|
|||||||
fetchMonitors();
|
fetchMonitors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const monitorsAsRows = monitors.map((monitor) => {
|
||||||
|
const processor =
|
||||||
|
((monitor.checks[0]?.cpu?.usage_frequency ?? 0) / 1000).toFixed(2) + " GHz";
|
||||||
|
const cpu = (monitor?.checks[0]?.cpu.usage_percent ?? 0) * 100;
|
||||||
|
const mem = (monitor?.checks[0]?.memory.usage_percent ?? 0) * 100;
|
||||||
|
const disk = (monitor?.checks[0]?.disk[0]?.usage_percent ?? 0) * 100;
|
||||||
|
const status = determineState(monitor);
|
||||||
|
const uptimePercentage = ((monitor?.uptimePercentage ?? 0) * 100)
|
||||||
|
.toFixed(2)
|
||||||
|
.toString();
|
||||||
|
const percentageColor =
|
||||||
|
monitor.uptimePercentage < 0.25
|
||||||
|
? theme.palette.percentage.uptimePoor
|
||||||
|
: monitor.uptimePercentage < 0.5
|
||||||
|
? theme.palette.percentage.uptimeFair
|
||||||
|
: monitor.uptimePercentage < 0.75
|
||||||
|
? theme.palette.percentage.uptimeGood
|
||||||
|
: theme.palette.percentage.uptimeExcellent;
|
||||||
|
return {
|
||||||
|
id: monitor._id,
|
||||||
|
name: monitor.name,
|
||||||
|
url: monitor.url,
|
||||||
|
processor,
|
||||||
|
cpu,
|
||||||
|
mem,
|
||||||
|
disk,
|
||||||
|
status,
|
||||||
|
uptimePercentage,
|
||||||
|
percentageColor,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack
|
<Stack
|
||||||
component="main"
|
component="main"
|
||||||
@@ -207,29 +239,11 @@ function Infrastructure() {
|
|||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{monitors.map((monitor) => {
|
{monitorsAsRows.map((row) => {
|
||||||
const processor =
|
|
||||||
((monitor.checks[0]?.cpu?.usage_frequency ?? 0) / 1000).toFixed(2) +
|
|
||||||
" GHz";
|
|
||||||
const cpu = (monitor?.checks[0]?.cpu.usage_percent ?? 0) * 100;
|
|
||||||
const mem = (monitor?.checks[0]?.memory.usage_percent ?? 0) * 100;
|
|
||||||
const disk = (monitor?.checks[0]?.disk[0]?.usage_percent ?? 0) * 100;
|
|
||||||
const status = determineState(monitor);
|
|
||||||
const uptimePercentage = ((monitor?.uptimePercentage ?? 0) * 100)
|
|
||||||
.toFixed(2)
|
|
||||||
.toString();
|
|
||||||
const percentageColor =
|
|
||||||
monitor.uptimePercentage < 0.25
|
|
||||||
? theme.palette.percentage.uptimePoor
|
|
||||||
: monitor.uptimePercentage < 0.5
|
|
||||||
? theme.palette.percentage.uptimeFair
|
|
||||||
: monitor.uptimePercentage < 0.75
|
|
||||||
? theme.palette.percentage.uptimeGood
|
|
||||||
: theme.palette.percentage.uptimeExcellent;
|
|
||||||
return (
|
return (
|
||||||
<TableRow
|
<TableRow
|
||||||
key={monitor._id}
|
key={row.id}
|
||||||
onClick={() => openDetails(monitor.id)}
|
onClick={() => openDetails(row.id)}
|
||||||
sx={{
|
sx={{
|
||||||
cursor: "pointer",
|
cursor: "pointer",
|
||||||
"&:hover": {
|
"&:hover": {
|
||||||
@@ -240,16 +254,16 @@ function Infrastructure() {
|
|||||||
{/* TODO iterate over column and get column id, applying row[column.id] */}
|
{/* TODO iterate over column and get column id, applying row[column.id] */}
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<Host
|
<Host
|
||||||
title={monitor.name}
|
title={row.name}
|
||||||
url={monitor.url}
|
url={row.url}
|
||||||
percentage={uptimePercentage}
|
percentage={row.uptimePercentage}
|
||||||
percentageColor={percentageColor}
|
percentageColor={row.percentageColor}
|
||||||
/>
|
/>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell align="center">
|
<TableCell align="center">
|
||||||
<StatusLabel
|
<StatusLabel
|
||||||
status={status}
|
status={row.status}
|
||||||
text={status}
|
text={row.status}
|
||||||
/* Use capitalize inside of Status Label */
|
/* Use capitalize inside of Status Label */
|
||||||
/* Update component so we don't need to pass text and status separately*/
|
/* Update component so we don't need to pass text and status separately*/
|
||||||
customStyles={{ textTransform: "capitalize" }}
|
customStyles={{ textTransform: "capitalize" }}
|
||||||
@@ -266,17 +280,17 @@ function Infrastructure() {
|
|||||||
width={20}
|
width={20}
|
||||||
height={20}
|
height={20}
|
||||||
/>
|
/>
|
||||||
{processor}
|
{row.processor}
|
||||||
</Stack>
|
</Stack>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell align="center">
|
<TableCell align="center">
|
||||||
<CustomGauge progress={cpu} />
|
<CustomGauge progress={row.cpu} />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell align="center">
|
<TableCell align="center">
|
||||||
<CustomGauge progress={mem} />
|
<CustomGauge progress={row.mem} />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell align="center">
|
<TableCell align="center">
|
||||||
<CustomGauge progress={disk} />
|
<CustomGauge progress={row.disk} />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell align="center">
|
<TableCell align="center">
|
||||||
{/* Get ActionsMenu from Monitor Table and create a component */}
|
{/* Get ActionsMenu from Monitor Table and create a component */}
|
||||||
@@ -288,7 +302,7 @@ function Infrastructure() {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<InfrastructureMenu
|
<InfrastructureMenu
|
||||||
monitor={monitor}
|
monitor={row}
|
||||||
isAdmin={isAdmin}
|
isAdmin={isAdmin}
|
||||||
updateCallback={handleActionMenuDelete}
|
updateCallback={handleActionMenuDelete}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in new issue
Block a user