From 4c04294f713edca02e961f3c6fc6b3fa4a5f756c Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 30 Apr 2026 14:42:19 -0700 Subject: [PATCH] extract duplicate code, add slot components --- client/src/Pages/StatusPage/Status/index.tsx | 70 ++++-- .../Status/themes/bold/BoldHeader.tsx | 20 ++ .../Status/themes/bold/BoldHero.tsx | 32 +++ .../Status/themes/bold/BoldStatusPage.tsx | 207 ---------------- .../themes/editorial/EditorialHeader.tsx | 36 +++ .../Status/themes/editorial/EditorialHero.tsx | 46 ++++ .../themes/editorial/EditorialStatusPage.tsx | 224 ------------------ .../Status/themes/editorial/styles.ts | 5 +- .../Status/themes/modern/ModernHeader.tsx | 24 ++ .../Status/themes/modern/ModernHero.tsx | 34 +++ .../Status/themes/refined/RefinedHeader.tsx | 29 +++ .../Status/themes/refined/RefinedHero.tsx | 34 +++ .../themes/refined/RefinedStatusPage.tsx | 210 ---------------- .../Status/themes/refined/styles.ts | 5 +- .../BaseStatusPage.tsx} | 131 ++++++---- 15 files changed, 397 insertions(+), 710 deletions(-) create mode 100644 client/src/Pages/StatusPage/Status/themes/bold/BoldHeader.tsx create mode 100644 client/src/Pages/StatusPage/Status/themes/bold/BoldHero.tsx delete mode 100644 client/src/Pages/StatusPage/Status/themes/bold/BoldStatusPage.tsx create mode 100644 client/src/Pages/StatusPage/Status/themes/editorial/EditorialHeader.tsx create mode 100644 client/src/Pages/StatusPage/Status/themes/editorial/EditorialHero.tsx delete mode 100644 client/src/Pages/StatusPage/Status/themes/editorial/EditorialStatusPage.tsx create mode 100644 client/src/Pages/StatusPage/Status/themes/modern/ModernHeader.tsx create mode 100644 client/src/Pages/StatusPage/Status/themes/modern/ModernHero.tsx create mode 100644 client/src/Pages/StatusPage/Status/themes/refined/RefinedHeader.tsx create mode 100644 client/src/Pages/StatusPage/Status/themes/refined/RefinedHero.tsx delete mode 100644 client/src/Pages/StatusPage/Status/themes/refined/RefinedStatusPage.tsx rename client/src/Pages/StatusPage/Status/themes/{modern/ModernStatusPage.tsx => shared/BaseStatusPage.tsx} (59%) diff --git a/client/src/Pages/StatusPage/Status/index.tsx b/client/src/Pages/StatusPage/Status/index.tsx index a3a535ace..59ba4f21b 100644 --- a/client/src/Pages/StatusPage/Status/index.tsx +++ b/client/src/Pages/StatusPage/Status/index.tsx @@ -8,35 +8,56 @@ import { useTranslation } from "react-i18next"; import { useIsAdmin } from "@/Hooks/useIsAdmin"; import { useLocation, useParams } from "react-router-dom"; import { useGet } from "@/Hooks/UseApi"; -import type { Monitor } from "@/Types/Monitor"; import { resolveStatusPageTheme } from "@/Types/StatusPage"; import { PUBLIC_STATUS_PAGE_PREFIX, - type StatusPage, type StatusPageResponse, type StatusPageTheme, } from "@/Types/StatusPage"; -import { HeaderStatusPageControls } from "./Components/HeaderStatusPageControls"; -import { StatusPageThemeProvider } from "./themes/StatusPageThemeProvider"; -import { RefinedStatusPage } from "./themes/refined/RefinedStatusPage"; -import { ModernStatusPage } from "./themes/modern/ModernStatusPage"; -import { BoldStatusPage } from "./themes/bold/BoldStatusPage"; -import { EditorialStatusPage } from "./themes/editorial/EditorialStatusPage"; -import { BrowserFrame } from "./themes/BrowserFrame"; +import { HeaderStatusPageControls } from "@/Pages/StatusPage/Status/Components/HeaderStatusPageControls"; +import { StatusPageThemeProvider } from "@/Pages/StatusPage/Status/themes/StatusPageThemeProvider"; +import { + BaseStatusPage, + type ThemeConfig, +} from "@/Pages/StatusPage/Status/themes/shared/BaseStatusPage"; +import { BrowserFrame } from "@/Pages/StatusPage/Status/themes/BrowserFrame"; +import { refinedStyles } from "@/Pages/StatusPage/Status/themes/refined/styles"; +import { RefinedHeader } from "@/Pages/StatusPage/Status/themes/refined/RefinedHeader"; +import { RefinedHero } from "@/Pages/StatusPage/Status/themes/refined/RefinedHero"; +import { modernStyles } from "@/Pages/StatusPage/Status/themes/modern/styles"; +import { ModernHeader } from "@/Pages/StatusPage/Status/themes/modern/ModernHeader"; +import { ModernHero } from "@/Pages/StatusPage/Status/themes/modern/ModernHero"; +import { boldStyles } from "@/Pages/StatusPage/Status/themes/bold/styles"; +import { BoldHeader } from "@/Pages/StatusPage/Status/themes/bold/BoldHeader"; +import { BoldHero } from "@/Pages/StatusPage/Status/themes/bold/BoldHero"; +import { editorialStyles } from "@/Pages/StatusPage/Status/themes/editorial/styles"; +import { EditorialHeader } from "@/Pages/StatusPage/Status/themes/editorial/EditorialHeader"; +import { EditorialHero } from "@/Pages/StatusPage/Status/themes/editorial/EditorialHero"; -type ThemedRendererProps = { - statusPage: StatusPage; - monitors: (Monitor & { checks?: Monitor["recentChecks"] })[]; -}; - -const THEMED_RENDERERS: Record< - StatusPageTheme, - React.ComponentType -> = { - refined: RefinedStatusPage, - modern: ModernStatusPage, - bold: BoldStatusPage, - editorial: EditorialStatusPage, +const THEME_CONFIGS: Record> = { + refined: { + createStyles: refinedStyles, + HeaderSlot: RefinedHeader, + HeroSlot: RefinedHero, + }, + modern: { + createStyles: modernStyles, + HeaderSlot: ModernHeader, + HeroSlot: ModernHero, + overallStatusOptions: { iconSize: 20 }, + }, + bold: { + createStyles: boldStyles, + HeaderSlot: BoldHeader, + HeroSlot: BoldHero, + overallStatusOptions: { iconSize: 18 }, + }, + editorial: { + createStyles: editorialStyles, + HeaderSlot: EditorialHeader, + HeroSlot: EditorialHero, + overallStatusOptions: { allUpKey: "pages.statusPages.editorial.allUp" }, + }, }; const StatusPageView = () => { @@ -90,11 +111,12 @@ const StatusPageView = () => { ); } - const ThemedRenderer = THEMED_RENDERERS[resolveStatusPageTheme(statusPage.theme)]; + const themeConfig = THEME_CONFIGS[resolveStatusPageTheme(statusPage.theme)]; const themedRenderer = ( - ); diff --git a/client/src/Pages/StatusPage/Status/themes/bold/BoldHeader.tsx b/client/src/Pages/StatusPage/Status/themes/bold/BoldHeader.tsx new file mode 100644 index 000000000..7b483b474 --- /dev/null +++ b/client/src/Pages/StatusPage/Status/themes/bold/BoldHeader.tsx @@ -0,0 +1,20 @@ +import Box from "@mui/material/Box"; +import { monoFirstChar } from "@/Pages/StatusPage/Status/themes/shared/overallStatus"; +import type { SlotProps } from "@/Pages/StatusPage/Status/themes/shared/BaseStatusPage"; +import type { BoldStyles } from "@/Pages/StatusPage/Status/themes/bold/styles"; + +export const BoldHeader = ({ statusPage, logoSrc, styles }: SlotProps) => ( + + {logoSrc ? ( + + ) : ( + {monoFirstChar(statusPage.companyName)} + )} + {statusPage.companyName} + +); diff --git a/client/src/Pages/StatusPage/Status/themes/bold/BoldHero.tsx b/client/src/Pages/StatusPage/Status/themes/bold/BoldHero.tsx new file mode 100644 index 000000000..3d378ddaf --- /dev/null +++ b/client/src/Pages/StatusPage/Status/themes/bold/BoldHero.tsx @@ -0,0 +1,32 @@ +import Box from "@mui/material/Box"; +import { useTranslation } from "react-i18next"; +import type { SlotProps } from "@/Pages/StatusPage/Status/themes/shared/BaseStatusPage"; +import type { BoldStyles } from "@/Pages/StatusPage/Status/themes/bold/styles"; + +export const BoldHero = ({ overall, monitorCount, styles }: SlotProps) => { + const { t } = useTranslation(); + return ( + + + + {overall.icon} + + {overall.message} + + + {t("pages.statusPages.statusBar.monitoringSummary", { + count: monitorCount, + })} + + + ); +}; diff --git a/client/src/Pages/StatusPage/Status/themes/bold/BoldStatusPage.tsx b/client/src/Pages/StatusPage/Status/themes/bold/BoldStatusPage.tsx deleted file mode 100644 index 32959a2ed..000000000 --- a/client/src/Pages/StatusPage/Status/themes/bold/BoldStatusPage.tsx +++ /dev/null @@ -1,207 +0,0 @@ -import { useMemo, useState } from "react"; -import Box from "@mui/material/Box"; -import Stack from "@mui/material/Stack"; -import { useTranslation } from "react-i18next"; -import type { Monitor } from "@/Types/Monitor"; -import type { StatusPage } from "@/Types/StatusPage"; -import { getMonitorTypeLabel } from "@/Types/StatusPage"; -import { ThemedHeatmap } from "../shared/ThemedHeatmap"; -import { ThemedHistogram } from "../shared/ThemedHistogram"; -import { ThemedInfrastructure } from "../shared/ThemedInfrastructure"; -import { - monitorBadgeTone, - monoFirstChar, - resolveOverallStatus, - statusBadgeKey, -} from "../shared/overallStatus"; -import { useStatusPageTheme } from "../StatusPageThemeProvider"; -import { boldStyles } from "./styles"; - -type StatusPageMonitor = Monitor & { checks?: Monitor["recentChecks"] }; - -interface Props { - statusPage: StatusPage; - monitors: StatusPageMonitor[]; -} - -export const BoldStatusPage = ({ statusPage, monitors }: Props) => { - const { t } = useTranslation(); - const { tokens, mode } = useStatusPageTheme(); - const styles = useMemo(() => boldStyles(tokens, mode === "dark"), [tokens, mode]); - const [chartMode, setChartMode] = useState<"heatmap" | "histogram">("heatmap"); - - const overall = resolveOverallStatus(monitors, t, { iconSize: 18 }); - const logoSrc = statusPage.logo?.data - ? `data:${statusPage.logo.contentType};base64,${statusPage.logo.data}` - : null; - - return ( - - - - {logoSrc ? ( - - ) : ( - {monoFirstChar(statusPage.companyName)} - )} - {statusPage.companyName} - - - - - - - {overall.icon} - - {overall.message} - - - {t("pages.statusPages.statusBar.monitoringSummary", { - count: monitors.length, - })} - - - - {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); - - return ( - - - - {monitor.name} - - - {getMonitorTypeLabel(monitor.type, t)} - - {monitor.url && ( - - {monitor.url} - - )} - - - - {t(statusBadgeKey[monitor.status])} - - - - {showInfra && ( - - )} - {showChart && - (chartMode === "heatmap" ? ( - - ) : ( - - ))} - - ); - })} - - - - {t("pages.statusPages.footer.poweredBy")}{" "} - - Checkmate - - - - ); -}; diff --git a/client/src/Pages/StatusPage/Status/themes/editorial/EditorialHeader.tsx b/client/src/Pages/StatusPage/Status/themes/editorial/EditorialHeader.tsx new file mode 100644 index 000000000..56a2a9af2 --- /dev/null +++ b/client/src/Pages/StatusPage/Status/themes/editorial/EditorialHeader.tsx @@ -0,0 +1,36 @@ +import Box from "@mui/material/Box"; +import { useTranslation } from "react-i18next"; +import type { SlotProps } from "@/Pages/StatusPage/Status/themes/shared/BaseStatusPage"; +import type { EditorialStyles } from "@/Pages/StatusPage/Status/themes/editorial/styles"; + +export const EditorialHeader = ({ + statusPage, + logoSrc, + styles, +}: SlotProps) => { + const { t } = useTranslation(); + return ( + + {logoSrc && ( + + )} + + {statusPage.companyName} + + + {t("pages.statusPages.editorial.reportTitle")} + + + ); +}; diff --git a/client/src/Pages/StatusPage/Status/themes/editorial/EditorialHero.tsx b/client/src/Pages/StatusPage/Status/themes/editorial/EditorialHero.tsx new file mode 100644 index 000000000..cd6a06406 --- /dev/null +++ b/client/src/Pages/StatusPage/Status/themes/editorial/EditorialHero.tsx @@ -0,0 +1,46 @@ +import { useMemo } from "react"; +import Box from "@mui/material/Box"; +import { useTranslation } from "react-i18next"; +import type { SlotProps } from "@/Pages/StatusPage/Status/themes/shared/BaseStatusPage"; +import type { EditorialStyles } from "@/Pages/StatusPage/Status/themes/editorial/styles"; + +export const EditorialHero = ({ + overall, + monitorCount, + styles, +}: SlotProps) => { + const { t } = useTranslation(); + const todayLabel = useMemo( + () => + new Date().toLocaleDateString(undefined, { + year: "numeric", + month: "long", + day: "numeric", + }), + [] + ); + + return ( + <> + + + {overall.message} + + + {todayLabel} ·{" "} + {t("pages.statusPages.statusBar.monitoringSummary", { + count: monitorCount, + })} + + + ); +}; diff --git a/client/src/Pages/StatusPage/Status/themes/editorial/EditorialStatusPage.tsx b/client/src/Pages/StatusPage/Status/themes/editorial/EditorialStatusPage.tsx deleted file mode 100644 index ee8fa6f99..000000000 --- a/client/src/Pages/StatusPage/Status/themes/editorial/EditorialStatusPage.tsx +++ /dev/null @@ -1,224 +0,0 @@ -import { useMemo, useState } from "react"; -import Box from "@mui/material/Box"; -import Stack from "@mui/material/Stack"; -import { useTranslation } from "react-i18next"; -import type { Monitor } from "@/Types/Monitor"; -import type { StatusPage } from "@/Types/StatusPage"; -import { getMonitorTypeLabel } from "@/Types/StatusPage"; -import { ThemedHeatmap } from "../shared/ThemedHeatmap"; -import { ThemedHistogram } from "../shared/ThemedHistogram"; -import { ThemedInfrastructure } from "../shared/ThemedInfrastructure"; -import { - monitorBadgeTone, - resolveOverallStatus, - statusBadgeKey, -} from "../shared/overallStatus"; -import { useStatusPageTheme } from "../StatusPageThemeProvider"; -import { editorialStyles } from "./styles"; - -type StatusPageMonitor = Monitor & { checks?: Monitor["recentChecks"] }; - -interface Props { - statusPage: StatusPage; - monitors: StatusPageMonitor[]; -} - -export const EditorialStatusPage = ({ statusPage, monitors }: Props) => { - const { t } = useTranslation(); - const { tokens } = useStatusPageTheme(); - const styles = useMemo(() => editorialStyles(tokens), [tokens]); - const [chartMode, setChartMode] = useState<"heatmap" | "histogram">("heatmap"); - - const todayLabel = useMemo( - () => - new Date().toLocaleDateString(undefined, { - year: "numeric", - month: "long", - day: "numeric", - }), - [] - ); - - const overall = resolveOverallStatus(monitors, t, { - allUpKey: "pages.statusPages.editorial.allUp", - }); - const logoSrc = statusPage.logo?.data - ? `data:${statusPage.logo.contentType};base64,${statusPage.logo.data}` - : null; - - return ( - - - - {logoSrc && ( - - )} - - {statusPage.companyName} - - - {t("pages.statusPages.editorial.reportTitle")} - - - - - - - {overall.message} - - - {todayLabel} ·{" "} - {t("pages.statusPages.statusBar.monitoringSummary", { - count: monitors.length, - })} - - - {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); - - return ( - - - - {monitor.name} - - - {getMonitorTypeLabel(monitor.type, t)} - - {monitor.url && ( - - {monitor.url} - - )} - - - - {t(statusBadgeKey[monitor.status])} - - - - {showInfra && ( - - )} - {showChart && - (chartMode === "heatmap" ? ( - - ) : ( - - ))} - - ); - })} - - - - {t("pages.statusPages.footer.poweredBy")}{" "} - - Checkmate - - - - ); -}; diff --git a/client/src/Pages/StatusPage/Status/themes/editorial/styles.ts b/client/src/Pages/StatusPage/Status/themes/editorial/styles.ts index 9c7e1cee0..57128180e 100644 --- a/client/src/Pages/StatusPage/Status/themes/editorial/styles.ts +++ b/client/src/Pages/StatusPage/Status/themes/editorial/styles.ts @@ -51,7 +51,10 @@ export interface EditorialStyles { footer: SxProps; } -export const editorialStyles = (tokens: StatusPageThemeTokens): EditorialStyles => { +export const editorialStyles = ( + tokens: StatusPageThemeTokens, + _isDark: boolean +): EditorialStyles => { const heatCellBg: Record = { fast: tokens.up, med: `color-mix(in srgb, ${tokens.up} 60%, ${tokens.bg})`, diff --git a/client/src/Pages/StatusPage/Status/themes/modern/ModernHeader.tsx b/client/src/Pages/StatusPage/Status/themes/modern/ModernHeader.tsx new file mode 100644 index 000000000..c7f01bc4e --- /dev/null +++ b/client/src/Pages/StatusPage/Status/themes/modern/ModernHeader.tsx @@ -0,0 +1,24 @@ +import Box from "@mui/material/Box"; +import { monoFirstChar } from "@/Pages/StatusPage/Status/themes/shared/overallStatus"; +import type { SlotProps } from "@/Pages/StatusPage/Status/themes/shared/BaseStatusPage"; +import type { ModernStyles } from "@/Pages/StatusPage/Status/themes/modern/styles"; + +export const ModernHeader = ({ + statusPage, + logoSrc, + styles, +}: SlotProps) => ( + + {logoSrc ? ( + + ) : ( + {monoFirstChar(statusPage.companyName)} + )} + {statusPage.companyName} + +); diff --git a/client/src/Pages/StatusPage/Status/themes/modern/ModernHero.tsx b/client/src/Pages/StatusPage/Status/themes/modern/ModernHero.tsx new file mode 100644 index 000000000..a7cf93bc7 --- /dev/null +++ b/client/src/Pages/StatusPage/Status/themes/modern/ModernHero.tsx @@ -0,0 +1,34 @@ +import Box from "@mui/material/Box"; +import { useTranslation } from "react-i18next"; +import type { SlotProps } from "@/Pages/StatusPage/Status/themes/shared/BaseStatusPage"; +import type { ModernStyles } from "@/Pages/StatusPage/Status/themes/modern/styles"; + +export const ModernHero = ({ + overall, + monitorCount, + styles, +}: SlotProps) => { + const { t } = useTranslation(); + return ( + + + + + {overall.message} + + + {t("pages.statusPages.statusBar.monitoringSummary", { + count: monitorCount, + })} + + + {overall.icon} + + ); +}; diff --git a/client/src/Pages/StatusPage/Status/themes/refined/RefinedHeader.tsx b/client/src/Pages/StatusPage/Status/themes/refined/RefinedHeader.tsx new file mode 100644 index 000000000..43e164f71 --- /dev/null +++ b/client/src/Pages/StatusPage/Status/themes/refined/RefinedHeader.tsx @@ -0,0 +1,29 @@ +import Box from "@mui/material/Box"; +import { monoFirstChar } from "@/Pages/StatusPage/Status/themes/shared/overallStatus"; +import type { SlotProps } from "@/Pages/StatusPage/Status/themes/shared/BaseStatusPage"; +import type { RefinedStyles } from "@/Pages/StatusPage/Status/themes/refined/styles"; + +export const RefinedHeader = ({ + statusPage, + logoSrc, + styles, +}: SlotProps) => ( + + {logoSrc ? ( + + ) : ( + {monoFirstChar(statusPage.companyName)} + )} + + {statusPage.companyName} + + +); diff --git a/client/src/Pages/StatusPage/Status/themes/refined/RefinedHero.tsx b/client/src/Pages/StatusPage/Status/themes/refined/RefinedHero.tsx new file mode 100644 index 000000000..c9a59ad77 --- /dev/null +++ b/client/src/Pages/StatusPage/Status/themes/refined/RefinedHero.tsx @@ -0,0 +1,34 @@ +import Box from "@mui/material/Box"; +import { useTranslation } from "react-i18next"; +import type { SlotProps } from "@/Pages/StatusPage/Status/themes/shared/BaseStatusPage"; +import type { RefinedStyles } from "@/Pages/StatusPage/Status/themes/refined/styles"; + +export const RefinedHero = ({ + overall, + monitorCount, + styles, +}: SlotProps) => { + const { t } = useTranslation(); + return ( + + + + + {overall.message} + + + {t("pages.statusPages.statusBar.monitoringSummary", { + count: monitorCount, + })} + + + {overall.icon} + + ); +}; diff --git a/client/src/Pages/StatusPage/Status/themes/refined/RefinedStatusPage.tsx b/client/src/Pages/StatusPage/Status/themes/refined/RefinedStatusPage.tsx deleted file mode 100644 index 5c5055b4c..000000000 --- a/client/src/Pages/StatusPage/Status/themes/refined/RefinedStatusPage.tsx +++ /dev/null @@ -1,210 +0,0 @@ -import { useMemo, useState } from "react"; -import Box from "@mui/material/Box"; -import Stack from "@mui/material/Stack"; -import { useTranslation } from "react-i18next"; -import type { Monitor } from "@/Types/Monitor"; -import type { StatusPage } from "@/Types/StatusPage"; -import { getMonitorTypeLabel } from "@/Types/StatusPage"; -import { ThemedHeatmap } from "../shared/ThemedHeatmap"; -import { ThemedHistogram } from "../shared/ThemedHistogram"; -import { ThemedInfrastructure } from "../shared/ThemedInfrastructure"; -import { - monitorBadgeTone, - monoFirstChar, - resolveOverallStatus, - statusBadgeKey, -} from "../shared/overallStatus"; -import { useStatusPageTheme } from "../StatusPageThemeProvider"; -import { refinedStyles } from "./styles"; - -type StatusPageMonitor = Monitor & { checks?: Monitor["recentChecks"] }; - -interface Props { - statusPage: StatusPage; - monitors: StatusPageMonitor[]; -} - -export const RefinedStatusPage = ({ statusPage, monitors }: Props) => { - const { t } = useTranslation(); - const { tokens } = useStatusPageTheme(); - const styles = useMemo(() => refinedStyles(tokens), [tokens]); - const [chartMode, setChartMode] = useState<"heatmap" | "histogram">("heatmap"); - - const overall = resolveOverallStatus(monitors, t); - const logoSrc = statusPage.logo?.data - ? `data:${statusPage.logo.contentType};base64,${statusPage.logo.data}` - : null; - - return ( - - - - {logoSrc ? ( - - ) : ( - {monoFirstChar(statusPage.companyName)} - )} - - {statusPage.companyName} - - - - - - - - - {overall.message} - - - {t("pages.statusPages.statusBar.monitoringSummary", { - count: monitors.length, - })} - - - {overall.icon} - - - {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); - - return ( - - - - {monitor.name} - - - {getMonitorTypeLabel(monitor.type, t)} - - {monitor.url && ( - - {monitor.url} - - )} - - - - {t(statusBadgeKey[monitor.status])} - - - - {showInfra && ( - - )} - {showChart && - (chartMode === "heatmap" ? ( - - ) : ( - - ))} - - ); - })} - - - - {t("pages.statusPages.footer.poweredBy")}{" "} - - Checkmate - - - - ); -}; diff --git a/client/src/Pages/StatusPage/Status/themes/refined/styles.ts b/client/src/Pages/StatusPage/Status/themes/refined/styles.ts index dfcf95d93..a6a52c021 100644 --- a/client/src/Pages/StatusPage/Status/themes/refined/styles.ts +++ b/client/src/Pages/StatusPage/Status/themes/refined/styles.ts @@ -63,7 +63,10 @@ const pillBase = { fontWeight: 600, }; -export const refinedStyles = (tokens: StatusPageThemeTokens): RefinedStyles => { +export const refinedStyles = ( + tokens: StatusPageThemeTokens, + _isDark: boolean +): RefinedStyles => { const heatCellBg: Record = { fast: tokens.up, med: `color-mix(in srgb, ${tokens.up} 60%, #ffffff 40%)`, diff --git a/client/src/Pages/StatusPage/Status/themes/modern/ModernStatusPage.tsx b/client/src/Pages/StatusPage/Status/themes/shared/BaseStatusPage.tsx similarity index 59% rename from client/src/Pages/StatusPage/Status/themes/modern/ModernStatusPage.tsx rename to client/src/Pages/StatusPage/Status/themes/shared/BaseStatusPage.tsx index 461c5e0f5..71aa85a89 100644 --- a/client/src/Pages/StatusPage/Status/themes/modern/ModernStatusPage.tsx +++ b/client/src/Pages/StatusPage/Status/themes/shared/BaseStatusPage.tsx @@ -2,80 +2,125 @@ 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 { ThemedHeatmap } from "../shared/ThemedHeatmap"; -import { ThemedHistogram } from "../shared/ThemedHistogram"; -import { ThemedInfrastructure } from "../shared/ThemedInfrastructure"; +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, - monoFirstChar, resolveOverallStatus, statusBadgeKey, -} from "../shared/overallStatus"; -import { useStatusPageTheme } from "../StatusPageThemeProvider"; -import { modernStyles } from "./styles"; +} from "@/Pages/StatusPage/Status/themes/shared/overallStatus"; +import { useStatusPageTheme } from "@/Pages/StatusPage/Status/themes/StatusPageThemeProvider"; type StatusPageMonitor = Monitor & { checks?: Monitor["recentChecks"] }; +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 ModernStatusPage = ({ statusPage, monitors }: Props) => { +export const BaseStatusPage = ({ statusPage, monitors, config }: Props) => { const { t } = useTranslation(); const { tokens, mode } = useStatusPageTheme(); - const styles = useMemo(() => modernStyles(tokens, mode === "dark"), [tokens, mode]); + const styles = useMemo( + () => config.createStyles(tokens, mode === "dark"), + [config, tokens, mode] + ); const [chartMode, setChartMode] = useState<"heatmap" | "histogram">("heatmap"); - const overall = resolveOverallStatus(monitors, t, { iconSize: 20 }); + 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 ( - - {logoSrc ? ( - - ) : ( - {monoFirstChar(statusPage.companyName)} - )} - {statusPage.companyName} - + - - - - - {overall.message} - - - {t("pages.statusPages.statusBar.monitoringSummary", { - count: monitors.length, - })} - - - {overall.icon} - + {statusPage.showCharts && (