import { useMemo, useState } from "react"; import Box from "@mui/material/Box"; import Stack from "@mui/material/Stack"; import { useTranslation } from "react-i18next"; import type { SxProps, Theme } from "@mui/material/styles"; import type { Monitor } from "@/Types/Monitor"; import type { StatusPage } from "@/Types/StatusPage"; import { getMonitorTypeLabel } from "@/Types/StatusPage"; import type { StatusPageThemeTokens } from "@/Pages/StatusPage/Status/themes/tokens"; import { ThemedHeatmap, type HeatCellKind, } from "@/Pages/StatusPage/Status/themes/shared/ThemedHeatmap"; import { ThemedHistogram, type BarKind, } from "@/Pages/StatusPage/Status/themes/shared/ThemedHistogram"; import { ThemedInfrastructure, type GaugeFillLevel, } from "@/Pages/StatusPage/Status/themes/shared/ThemedInfrastructure"; import { type OverallStatus, type OverallTone, monitorBadgeTone, resolveOverallStatus, statusBadgeKey, } from "@/Pages/StatusPage/Status/themes/shared/overallStatus"; import { useStatusPageTheme } from "@/Pages/StatusPage/Status/themes/StatusPageThemeProvider"; import { formatPercentage } from "@/Utils/FormatUtils"; type StatusPageMonitor = Monitor; export interface BaseStyles { page: SxProps; top: SxProps; chartSwitchWrap: SxProps; chartSwitch: SxProps; chartSwitchButton: (active: boolean) => SxProps; monitorList: SxProps; card: SxProps; cardRow: SxProps; cardLeft: SxProps; monitorName: SxProps; monitorMeta: SxProps; pill: SxProps; pillHardware: SxProps; monitorUrl: SxProps; badge: (tone: OverallTone) => SxProps; heatmap: SxProps; heatmapCell: (kind: HeatCellKind) => SxProps; histogram: SxProps; bar: (kind: BarKind, heightPct: number) => SxProps; chartStats: SxProps; infra: SxProps; infraEmpty: SxProps; gauge: SxProps; gaugeLabel: SxProps; gaugeValue: SxProps; gaugeBar: SxProps; gaugeFill: (level: GaugeFillLevel, widthPct: number) => SxProps; gaugeSub: SxProps; footer: SxProps; } export interface SlotProps { statusPage: StatusPage; logoSrc: string | null; overall: OverallStatus; monitorCount: number; styles: S; } export interface ThemeConfig { createStyles: (tokens: StatusPageThemeTokens, isDark: boolean) => S; HeaderSlot: React.ComponentType>; HeroSlot: React.ComponentType>; overallStatusOptions?: { iconSize?: number; allUpKey?: string }; } interface Props { statusPage: StatusPage; monitors: StatusPageMonitor[]; config: ThemeConfig; } export const BaseStatusPage = ({ statusPage, monitors, config }: Props) => { const { t } = useTranslation(); const { tokens, mode } = useStatusPageTheme(); const styles = useMemo( () => config.createStyles(tokens, mode === "dark"), [config, tokens, mode] ); const [chartMode, setChartMode] = useState<"heatmap" | "histogram">("heatmap"); const overall = resolveOverallStatus(monitors, t, config.overallStatusOptions); const logoSrc = statusPage.logo?.data ? `data:${statusPage.logo.contentType};base64,${statusPage.logo.data}` : null; const { HeaderSlot, HeroSlot } = config; return ( {statusPage.customCSS && } {statusPage.showCharts && ( setChartMode("heatmap")} sx={styles.chartSwitchButton(chartMode === "heatmap")} > {t("pages.statusPages.monitorsList.chartTypeHeatmap")} setChartMode("histogram")} sx={styles.chartSwitchButton(chartMode === "histogram")} > {t("pages.statusPages.monitorsList.chartTypeHistogram")} )} {monitors.map((monitor) => { const isHardware = monitor.type === "hardware"; const showInfra = isHardware && statusPage.showInfrastructure !== false; const showChart = !isHardware && statusPage.showCharts !== false; const badgeTone = monitorBadgeTone(monitor.status); const uptimePercentage = formatPercentage(monitor.uptimePercentage ?? 0); return ( {monitor.name} {t(statusBadgeKey[monitor.status])} {getMonitorTypeLabel(monitor.type, t)} {uptimePercentage} {monitor.url && ( {monitor.url} )} {showInfra && ( )} {showChart && (chartMode === "heatmap" ? ( ) : ( ))} ); })} {t("pages.statusPages.footer.poweredBy")}{" "} Checkmate ); };