Make requested changes
This commit is contained in:
1 parent
360e8ad2a0
commit
7b164e4df5
2 files changed
+37
-11
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
AlertTriangle,
|
AlertTriangle,
|
||||||
CircleCheck,
|
CircleCheck,
|
||||||
CircleX,
|
CircleX, Loader,
|
||||||
PauseCircle,
|
PauseCircle,
|
||||||
ShieldAlert,
|
ShieldAlert,
|
||||||
Wrench,
|
Wrench,
|
||||||
@@ -14,11 +14,25 @@ import { useTheme } from "@mui/material";
|
|||||||
import type { Theme } from "@mui/material";
|
import type { Theme } from "@mui/material";
|
||||||
import type { Monitor, MonitorStatus } from "@/Types/Monitor";
|
import type { Monitor, MonitorStatus } from "@/Types/Monitor";
|
||||||
|
|
||||||
|
interface StatusDisplay {
|
||||||
|
icon: JSX.Element;
|
||||||
|
msg?: string;
|
||||||
|
color?: string;
|
||||||
|
}
|
||||||
|
|
||||||
const getMonitorStatus = (monitors: Monitor[], theme: Theme, t: Function) => {
|
const getMonitorStatus = (monitors: Monitor[], theme: Theme, t: Function) => {
|
||||||
const monitorsStatus: Record<string, any> = {
|
const monitorsStatus: StatusDisplay = {
|
||||||
icon: <AlertTriangle size={24} />,
|
icon: <AlertTriangle size={24} />,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Handle empty monitors array
|
||||||
|
if (monitors.length === 0) {
|
||||||
|
monitorsStatus.msg = t("pages.statusPages.statusBar.noMonitors");
|
||||||
|
monitorsStatus.color = theme.palette.warning.main;
|
||||||
|
monitorsStatus.icon = <CircleX size={24} />;
|
||||||
|
return monitorsStatus;
|
||||||
|
}
|
||||||
|
|
||||||
const allOf = (...statuses: MonitorStatus[]) =>
|
const allOf = (...statuses: MonitorStatus[]) =>
|
||||||
monitors.every((m) => statuses.includes(m.status));
|
monitors.every((m) => statuses.includes(m.status));
|
||||||
const someOf = (...statuses: MonitorStatus[]) =>
|
const someOf = (...statuses: MonitorStatus[]) =>
|
||||||
@@ -33,7 +47,7 @@ const getMonitorStatus = (monitors: Monitor[], theme: Theme, t: Function) => {
|
|||||||
monitorsStatus.icon = <CircleCheck size={24} />;
|
monitorsStatus.icon = <CircleCheck size={24} />;
|
||||||
} else if (allOf("breached")) {
|
} else if (allOf("breached")) {
|
||||||
monitorsStatus.msg = t("pages.statusPages.statusBar.allBreached");
|
monitorsStatus.msg = t("pages.statusPages.statusBar.allBreached");
|
||||||
monitorsStatus.color = theme.palette.error.dark;
|
monitorsStatus.color = theme.palette.error.main;
|
||||||
monitorsStatus.icon = <ShieldAlert size={24} />;
|
monitorsStatus.icon = <ShieldAlert size={24} />;
|
||||||
} else if (allOf("maintenance")) {
|
} else if (allOf("maintenance")) {
|
||||||
monitorsStatus.msg = t("pages.statusPages.statusBar.allMaintenance");
|
monitorsStatus.msg = t("pages.statusPages.statusBar.allMaintenance");
|
||||||
@@ -47,15 +61,19 @@ const getMonitorStatus = (monitors: Monitor[], theme: Theme, t: Function) => {
|
|||||||
monitorsStatus.msg = t("pages.statusPages.statusBar.allPaused");
|
monitorsStatus.msg = t("pages.statusPages.statusBar.allPaused");
|
||||||
monitorsStatus.color = theme.palette.warning.main;
|
monitorsStatus.color = theme.palette.warning.main;
|
||||||
monitorsStatus.icon = <PauseCircle size={24} />;
|
monitorsStatus.icon = <PauseCircle size={24} />;
|
||||||
|
} else if (allOf("initializing")) {
|
||||||
|
monitorsStatus.msg = t("pages.statusPages.statusBar.allInitializing");
|
||||||
|
monitorsStatus.color = theme.palette.warning.main;
|
||||||
|
monitorsStatus.icon = <Loader size={24} />;
|
||||||
|
|
||||||
// Breached takes highest priority in mixed states
|
// Breached takes highest priority in mixed states
|
||||||
} else if (someOf("breached") && someOf("down")) {
|
} else if (someOf("breached") && someOf("down")) {
|
||||||
monitorsStatus.msg = t("pages.statusPages.statusBar.breachedAndDown");
|
monitorsStatus.msg = t("pages.statusPages.statusBar.breachedAndDown");
|
||||||
monitorsStatus.color = theme.palette.error.dark;
|
monitorsStatus.color = theme.palette.error.main;
|
||||||
monitorsStatus.icon = <ShieldAlert size={24} />;
|
monitorsStatus.icon = <ShieldAlert size={24} />;
|
||||||
} else if (someOf("breached")) {
|
} else if (someOf("breached")) {
|
||||||
monitorsStatus.msg = t("pages.statusPages.statusBar.breached");
|
monitorsStatus.msg = t("pages.statusPages.statusBar.breached");
|
||||||
monitorsStatus.color = theme.palette.error.dark;
|
monitorsStatus.color = theme.palette.error.main;
|
||||||
monitorsStatus.icon = <ShieldAlert size={24} />;
|
monitorsStatus.icon = <ShieldAlert size={24} />;
|
||||||
|
|
||||||
// Maintenance combinations
|
// Maintenance combinations
|
||||||
@@ -63,23 +81,28 @@ const getMonitorStatus = (monitors: Monitor[], theme: Theme, t: Function) => {
|
|||||||
monitorsStatus.msg = t("pages.statusPages.statusBar.maintenanceAndDown");
|
monitorsStatus.msg = t("pages.statusPages.statusBar.maintenanceAndDown");
|
||||||
monitorsStatus.color = theme.palette.error.main;
|
monitorsStatus.color = theme.palette.error.main;
|
||||||
monitorsStatus.icon = <Wrench size={24} />;
|
monitorsStatus.icon = <Wrench size={24} />;
|
||||||
} else if (someOf("maintenance") && noneOf("down", "breached")) {
|
} else if (someOf("maintenance") && noneOf("down")) {
|
||||||
monitorsStatus.msg = t("pages.statusPages.statusBar.maintenance");
|
monitorsStatus.msg = t("pages.statusPages.statusBar.maintenance");
|
||||||
monitorsStatus.color = theme.palette.warning.main;
|
monitorsStatus.color = theme.palette.warning.main;
|
||||||
monitorsStatus.icon = <Wrench size={24} />;
|
monitorsStatus.icon = <Wrench size={24} />;
|
||||||
|
|
||||||
// Degraded (some down, no maintenance/breached)
|
// Degraded (some down, no maintenance/breached)
|
||||||
} else if (someOf("down") && noneOf("maintenance", "breached")) {
|
} else if (someOf("down")) {
|
||||||
monitorsStatus.msg = t("pages.statusPages.statusBar.degraded");
|
monitorsStatus.msg = t("pages.statusPages.statusBar.degraded");
|
||||||
monitorsStatus.color = theme.palette.warning.main;
|
monitorsStatus.color = theme.palette.warning.main;
|
||||||
monitorsStatus.icon = <AlertTriangle size={24} />;
|
monitorsStatus.icon = <AlertTriangle size={24} />;
|
||||||
|
|
||||||
// Some Paused
|
// Some Paused
|
||||||
} else if (someOf("paused") && noneOf("down", "breached", "maintenance")) {
|
} else if (someOf("paused")) {
|
||||||
monitorsStatus.msg = t("pages.statusPages.statusBar.partiallyPaused");
|
monitorsStatus.msg = t("pages.statusPages.statusBar.partiallyPaused");
|
||||||
monitorsStatus.color = theme.palette.warning.main;
|
monitorsStatus.color = theme.palette.warning.main;
|
||||||
monitorsStatus.icon = <PauseCircle size={24} />;
|
monitorsStatus.icon = <PauseCircle size={24} />;
|
||||||
|
|
||||||
|
// Initializing
|
||||||
|
} else if (someOf("initializing")) {
|
||||||
|
monitorsStatus.msg = t("pages.statusPages.statusBar.initializing");
|
||||||
|
monitorsStatus.color = theme.palette.info.main;
|
||||||
|
monitorsStatus.icon = <Loader size={24} />;
|
||||||
} else {
|
} else {
|
||||||
monitorsStatus.msg = t("pages.statusPages.statusBar.unknown");
|
monitorsStatus.msg = t("pages.statusPages.statusBar.unknown");
|
||||||
monitorsStatus.color = theme.palette.warning.main;
|
monitorsStatus.color = theme.palette.warning.main;
|
||||||
|
|||||||
@@ -1208,17 +1208,20 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"statusBar": {
|
"statusBar": {
|
||||||
"allDown": "All systems are down",
|
|
||||||
"allMaintenance": "All systems are under maintenance",
|
|
||||||
"allUp": "All systems operational",
|
"allUp": "All systems operational",
|
||||||
"allPaused": "All systems are paused",
|
|
||||||
"allBreached": "All systems have been breached",
|
"allBreached": "All systems have been breached",
|
||||||
|
"allMaintenance": "All systems are under maintenance",
|
||||||
|
"allDown": "All systems are down",
|
||||||
|
"allPaused": "All systems are paused",
|
||||||
|
"allInitializing": "All systems are initializing",
|
||||||
"breachedAndDown": "Some systems are breached and down",
|
"breachedAndDown": "Some systems are breached and down",
|
||||||
"breached": "Some systems have been breached",
|
"breached": "Some systems have been breached",
|
||||||
"degraded": "Some systems are experiencing issues",
|
"degraded": "Some systems are experiencing issues",
|
||||||
"maintenanceAndDown": "Some systems are down during maintenance",
|
"maintenanceAndDown": "Some systems are down during maintenance",
|
||||||
"maintenance": "Some systems are under maintenance",
|
"maintenance": "Some systems are under maintenance",
|
||||||
"partiallyPaused": "Some systems are paused",
|
"partiallyPaused": "Some systems are paused",
|
||||||
|
"initializing": "Some systems are initializing",
|
||||||
|
"noMonitors": "No monitors have been configured",
|
||||||
"unknown": "Unable to determine system status"
|
"unknown": "Unable to determine system status"
|
||||||
},
|
},
|
||||||
"table": {
|
"table": {
|
||||||
|
|||||||
Reference in new issue
Block a user