Files
Checkmate/client/src/Utils/MonitorUtils.ts
T

28 lines
886 B
TypeScript
Raw Normal View History

2025-10-06 13:59:31 -07:00
import type { MonitorStatus } from "@/Types/Monitor";
2025-10-06 15:08:55 -07:00
import type { PaletteKey } from "./Theme/v2/theme";
export const getStatusPalette = (status: MonitorStatus): PaletteKey => {
const paletteMap: Record<MonitorStatus, PaletteKey> = {
up: "success",
down: "error",
initializing: "warning",
};
return paletteMap[status];
};
2025-10-06 13:59:31 -07:00
export const getStatusColor = (status: MonitorStatus, theme: any): string => {
const statusColors: Record<MonitorStatus, string> = {
up: theme.palette.success.lowContrast,
down: theme.palette.error.lowContrast,
initializing: theme.palette.warning.lowContrast,
};
return statusColors[status];
};
export const formatUrl = (url: string, maxLength: number = 55) => {
if (!url) return "";
const strippedUrl = url.replace(/^https?:\/\//, "");
return strippedUrl.length > maxLength
? `${strippedUrl.slice(0, maxLength)}…`
: strippedUrl;
};