2026-01-23 23:54:58 +00:00
|
|
|
import Box from "@mui/material/Box";
|
2026-02-20 18:13:39 +00:00
|
|
|
import { BaseBox } from "@/Components/design-elements";
|
2026-01-23 23:54:58 +00:00
|
|
|
import Typography from "@mui/material/Typography";
|
|
|
|
|
|
|
|
|
|
import type { MonitorStatus } from "@/Types/Monitor";
|
|
|
|
|
import type { SxProps } from "@mui/material/styles";
|
|
|
|
|
import { getStatusPalette, getValuePalette } from "@/Utils/MonitorUtils";
|
|
|
|
|
import { useTheme } from "@mui/material/styles";
|
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
|
|
|
|
|
|
export const ValueTypes = ["positive", "negative", "neutral"] as const;
|
|
|
|
|
export type ValueType = (typeof ValueTypes)[number];
|
|
|
|
|
|
2026-02-11 20:11:22 +00:00
|
|
|
export const StatusLabel = ({ status, sx }: { status: MonitorStatus; sx?: SxProps }) => {
|
2026-01-23 23:54:58 +00:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
const theme = useTheme();
|
|
|
|
|
const palette = getStatusPalette(status);
|
|
|
|
|
|
2026-02-11 20:11:22 +00:00
|
|
|
const determineStatus = (status: MonitorStatus): string => {
|
|
|
|
|
if (status === "up") {
|
2026-01-23 23:54:58 +00:00
|
|
|
return t("pages.common.monitors.status.up");
|
2026-02-11 20:11:22 +00:00
|
|
|
} else if (status === "down") {
|
2026-01-23 23:54:58 +00:00
|
|
|
return t("pages.common.monitors.status.down");
|
2026-02-14 22:52:14 +00:00
|
|
|
} else if (status === "breached") {
|
|
|
|
|
return t("pages.common.monitors.status.breached");
|
2026-02-11 20:11:22 +00:00
|
|
|
} else if (status === "maintenance") {
|
|
|
|
|
return t("pages.common.monitors.status.maintenance");
|
|
|
|
|
} else if (status === "paused") {
|
|
|
|
|
return t("pages.common.monitors.status.paused");
|
|
|
|
|
} else if (status === "initializing") {
|
|
|
|
|
return t("pages.common.monitors.status.initializing");
|
2026-01-23 23:54:58 +00:00
|
|
|
}
|
2026-02-11 20:11:22 +00:00
|
|
|
|
2026-01-23 23:54:58 +00:00
|
|
|
return t("pages.common.monitors.status.initializing");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<BaseBox
|
|
|
|
|
sx={{
|
|
|
|
|
display: "inline-flex",
|
|
|
|
|
flexDirection: "row",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
padding: theme.spacing(3, 5),
|
|
|
|
|
color: theme.palette[palette].main,
|
|
|
|
|
borderColor:
|
|
|
|
|
theme.palette.mode === "dark"
|
|
|
|
|
? "rgba(255, 255, 255, 0.08)"
|
|
|
|
|
: "rgba(0, 0, 0, 0.08)",
|
|
|
|
|
...sx,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Box
|
|
|
|
|
width={7}
|
|
|
|
|
height={7}
|
|
|
|
|
bgcolor={theme.palette[palette].light}
|
|
|
|
|
borderRadius="50%"
|
|
|
|
|
marginRight="5px"
|
|
|
|
|
/>
|
2026-02-11 20:11:22 +00:00
|
|
|
<Typography textTransform={"capitalize"}>{determineStatus(status)}</Typography>
|
2026-01-23 23:54:58 +00:00
|
|
|
</BaseBox>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const ValueLabel = ({ value, text }: { value: ValueType; text: string }) => {
|
|
|
|
|
const theme = useTheme();
|
|
|
|
|
const palette = getValuePalette(value);
|
|
|
|
|
const transformedText = text.charAt(0).toUpperCase() + text.slice(1).toLowerCase();
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<BaseBox
|
|
|
|
|
sx={{
|
|
|
|
|
display: "inline-flex",
|
|
|
|
|
flexDirection: "row",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
padding: theme.spacing(3, 5),
|
|
|
|
|
color: theme.palette[palette].main,
|
|
|
|
|
borderColor:
|
|
|
|
|
theme.palette.mode === "dark"
|
|
|
|
|
? "rgba(255, 255, 255, 0.08)"
|
|
|
|
|
: "rgba(0, 0, 0, 0.08)",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Box
|
|
|
|
|
width={7}
|
|
|
|
|
height={7}
|
|
|
|
|
bgcolor={theme.palette[palette].light}
|
|
|
|
|
borderRadius="50%"
|
|
|
|
|
marginRight="5px"
|
|
|
|
|
/>
|
2026-02-01 01:54:18 +00:00
|
|
|
<Typography>{transformedText}</Typography>
|
2026-01-23 23:54:58 +00:00
|
|
|
</BaseBox>
|
|
|
|
|
);
|
|
|
|
|
};
|
2026-05-20 10:45:36 -07:00
|
|
|
|
|
|
|
|
export const ColoredLabel = ({ text, color }: { text: string; color: string }) => {
|
|
|
|
|
const theme = useTheme();
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<BaseBox
|
|
|
|
|
sx={{
|
2026-05-20 11:36:03 -07:00
|
|
|
width: "fit-content",
|
2026-05-20 10:45:36 -07:00
|
|
|
padding: theme.spacing(1, 3),
|
|
|
|
|
color: color,
|
|
|
|
|
borderColor: color,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Typography>{text}</Typography>
|
|
|
|
|
</BaseBox>
|
|
|
|
|
);
|
|
|
|
|
};
|