import Box from "@mui/material/Box"; import Stack from "@mui/material/Stack"; import Typography from "@mui/material/Typography"; import { TriangleAlert } from "lucide-react"; import type { SxProps, Theme } from "@mui/material/styles"; import type { Monitor } from "@/Types/Monitor"; import type { StatusPage, StatusPageRange } from "@/Types/StatusPage"; import { getMonitorTypeLabel, STATUS_PAGE_RANGE_DAYS, STATUS_PAGE_RANGES, } from "@/Types/StatusPage"; import type { StatusPageThemeTokens } from "@/Pages/StatusPage/Status/themes/tokens"; import { ThemedHeatmap } from "@/Pages/StatusPage/Status/themes/shared/ThemedHeatmap"; import { ThemedHistogram } from "@/Pages/StatusPage/Status/themes/shared/ThemedHistogram"; import { IncidentModal } from "@/Pages/StatusPage/Status/themes/shared/IncidentModal"; 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 { formatPercentage } from "@/Utils/FormatUtils"; import { checksToCells, dailyBucketsToCells, type BarKind, type HeatCellKind, } from "@/Pages/StatusPage/Status/themes/shared/ChartCells"; import { LAYOUT } from "@/Utils/Theme/constants"; import { Icon } from "@/Components/design-elements"; import { useStatusPageTheme } from "@/Pages/StatusPage/Status/themes/StatusPageThemeProvider"; import { useMemo, useState } from "react"; import { useTranslation } from "react-i18next"; import { useTheme } from "@mui/material"; 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, severity?: number) => SxProps; histogram: SxProps; bar: (kind: BarKind, heightPct: number, severity?: 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; range: StatusPageRange; onRangeChange: (range: StatusPageRange) => void; bucketTimezone: string; checkTTLDays?: number; } export const BaseStatusPage = ({ statusPage, monitors, config, range, onRangeChange, bucketTimezone, checkTTLDays, }: Props) => { const theme = useTheme(); 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 [selectedMonitorId, setSelectedMonitorId] = useState(null); const [selectedDate, setSelectedDate] = useState(null); 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")} {STATUS_PAGE_RANGES.map((value) => ( onRangeChange(value)} sx={styles.chartSwitchButton(range === value)} > {t(`pages.statusPages.range.${value}`)} ))} {range !== "latest" && checkTTLDays && STATUS_PAGE_RANGE_DAYS[range] > checkTTLDays && ( {t("pages.statusPages.rangeExceedsRetention", { days: checkTTLDays })} )} )} {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); const cells = range === "latest" ? checksToCells(monitor.recentChecks ?? []) : dailyBucketsToCells( monitor.dailyChecks ?? [], STATUS_PAGE_RANGE_DAYS[range], bucketTimezone, t ); return ( {monitor.name} {t(statusBadgeKey[monitor.status])} {getMonitorTypeLabel(monitor.type, t)} {uptimePercentage} {monitor.url && ( {monitor.url} )} {showInfra && ( )} {showChart && (chartMode === "heatmap" ? ( { setSelectedMonitorId(monitor.id); setSelectedDate(date); }} /> ) : ( { setSelectedMonitorId(monitor.id); setSelectedDate(date); }} /> ))} ); })} {t("pages.statusPages.footer.poweredBy")}{" "} Checkmate { setSelectedMonitorId(null); setSelectedDate(null); }} /> ); };