From 163f5ec1ecaf731b856185a477710c6c5949963d Mon Sep 17 00:00:00 2001 From: gorkem-bwl Date: Mon, 27 Apr 2026 18:21:31 -0400 Subject: [PATCH] refactor(status-page): convert refined theme to MUI sx + theme tokens The reviewer's feedback on this PR is that the themes ship hardcoded class names against per-theme CSS files instead of following the project's MUI sx + theme.spacing()/palette pattern. This commit handles the refined theme as a proof of concept; the other three follow. What changed - New src/Pages/StatusPage/Status/themes/refined/styles.ts: a single function (tokens, isDark) -> sx recipes that mirror every rule in the deleted refined.css. All values are derived from the tokens already declared in tokens.ts so the colour/spacing source of truth doesn't change. - RefinedStatusPage.tsx: drops the className= attributes and the import "./refined.css" in favour of sx={styles.x} drawn from the recipe map. Hardcoded class strings gone. - refined.css: deleted (was 420 lines). - Shared themed components (ThemedHeatmap, ThemedHistogram, ThemedInfrastructure): grew an opt-in sx-based API alongside the existing classPrefix one. The new API is what refined uses; bold / modern / editorial keep working unchanged on the legacy classPrefix path until they are migrated, after which the legacy code path is removed. Verified - tsc --noEmit clean - prettier clean - Pre-existing vite build error on this branch (flag-icons resolve, unrelated) is untouched Next - Convert the bold, modern and editorial themes the same way and remove the legacy classPrefix branch from the shared components. --- .../themes/refined/RefinedStatusPage.tsx | 122 +++-- .../Status/themes/refined/refined.css | 420 ------------------ .../Status/themes/refined/styles.ts | 352 +++++++++++++++ .../Status/themes/shared/ThemedHeatmap.tsx | 31 +- .../Status/themes/shared/ThemedHistogram.tsx | 59 ++- .../themes/shared/ThemedInfrastructure.tsx | 62 ++- 6 files changed, 553 insertions(+), 493 deletions(-) delete mode 100644 client/src/Pages/StatusPage/Status/themes/refined/refined.css create mode 100644 client/src/Pages/StatusPage/Status/themes/refined/styles.ts diff --git a/client/src/Pages/StatusPage/Status/themes/refined/RefinedStatusPage.tsx b/client/src/Pages/StatusPage/Status/themes/refined/RefinedStatusPage.tsx index 5be6eab21..ef4f73596 100644 --- a/client/src/Pages/StatusPage/Status/themes/refined/RefinedStatusPage.tsx +++ b/client/src/Pages/StatusPage/Status/themes/refined/RefinedStatusPage.tsx @@ -14,7 +14,8 @@ import { resolveOverallStatus, statusBadgeKey, } from "../shared/overallStatus"; -import "./refined.css"; +import { useStatusPageTheme } from "../StatusPageThemeProvider"; +import { refinedStyles } from "./styles"; type StatusPageMonitor = Monitor & { checks?: Monitor["recentChecks"] }; @@ -23,10 +24,10 @@ interface Props { monitors: StatusPageMonitor[]; } -const PREFIX = "rf"; - export const RefinedStatusPage = ({ statusPage, monitors }: Props) => { const { t } = useTranslation(); + const { tokens, mode } = useStatusPageTheme(); + const styles = refinedStyles(tokens, mode === "dark"); const [chartMode, setChartMode] = useState<"heatmap" | "histogram">("heatmap"); const overall = resolveOverallStatus(monitors, t); @@ -35,72 +36,85 @@ export const RefinedStatusPage = ({ statusPage, monitors }: Props) => { : null; return ( - + - + {logoSrc ? ( ) : ( - - {monoFirstChar(statusPage.companyName)} - + {monoFirstChar(statusPage.companyName)} )} - {statusPage.companyName} + + {statusPage.companyName} + - - - -

{overall.message}

-

+ + + + + {overall.message} + + {t("pages.statusPages.statusBar.monitoringSummary", { count: monitors.length, })} -

+
- {overall.icon} + {overall.icon}
{statusPage.showCharts && ( - + - - + )} {monitors.map((monitor) => { const isHardware = monitor.type === "hardware"; @@ -112,48 +126,68 @@ export const RefinedStatusPage = ({ statusPage, monitors }: Props) => { - - - {monitor.name} - - + + {monitor.name} + + {getMonitorTypeLabel(monitor.type, t)} - + {monitor.url && ( - {monitor.url} - + )} - + {t(statusBadgeKey[monitor.status])} - +
{showInfra && ( any, + gaugeSubSx: styles.gaugeSub, + }} /> )} {showChart && (chartMode === "heatmap" ? ( any} /> ) : ( any} + statsSx={styles.chartStats} /> ))}
@@ -163,7 +197,7 @@ export const RefinedStatusPage = ({ statusPage, monitors }: Props) => { {t("pages.statusPages.footer.poweredBy")}{" "} button { - border: 0; - background: transparent; - font: - inherit, - -apple-system, - sans-serif; - font-size: 11px; - padding: 5px 14px; - cursor: pointer; - color: var(--sp-text-muted); - border-radius: 5px; - transition: - background 0.15s ease, - color 0.15s ease; - font-weight: 500; -} -[data-status-theme="refined"] .rf-chart-switch > button:hover { - color: var(--sp-text); -} -[data-status-theme="refined"] .rf-chart-switch > button.rf-active { - color: var(--sp-up); - background: var(--sp-up-soft); - font-weight: 600; -} - -/* --- monitor card list --- */ -[data-status-theme="refined"] .rf-monitor-list { - list-style: none; - margin: 0; - padding: 0; - display: flex; - flex-direction: column; - gap: 12px; -} -[data-status-theme="refined"] .rf-card { - background: var(--sp-surface); - border: 1px solid var(--sp-border); - border-radius: var(--sp-radius); - box-shadow: var( - --sp-shadow, - 0 1px 2px rgba(10, 16, 32, 0.06), - 0 6px 18px rgba(10, 16, 32, 0.08) - ); - overflow: hidden; - position: relative; - transition: - transform 0.15s, - box-shadow 0.15s; -} -[data-status-theme="refined"] .rf-card:hover { - transform: translateY(-1px); - box-shadow: - 0 2px 4px rgba(16, 24, 40, 0.06), - 0 10px 24px rgba(16, 24, 40, 0.06); -} - -[data-status-theme="refined"] .rf-card-row { - display: grid; - grid-template-columns: 1fr auto; - align-items: center; - gap: 16px; - padding: 16px 20px; -} -[data-status-theme="refined"] .rf-card-left { - min-width: 0; -} -[data-status-theme="refined"] .rf-monitor-name { - font-weight: 600; - font-size: 14px; - letter-spacing: -0.005em; - color: var(--sp-text); - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; -} -[data-status-theme="refined"] .rf-monitor-meta { - display: flex; - gap: 10px; - align-items: center; - margin-top: 4px; - flex-wrap: wrap; -} -[data-status-theme="refined"] .rf-pill { - font-size: 10px; - text-transform: uppercase; - letter-spacing: 0.08em; - color: var(--sp-text-muted); - border: 1px solid var(--sp-border); - padding: 2px 8px; - border-radius: 999px; - font-weight: 600; -} -[data-status-theme="refined"] .rf-pill-hardware { - color: #1d4ed8; - border-color: rgba(29, 78, 216, 0.3); - background: rgba(29, 78, 216, 0.06); -} -[data-status-theme="refined"][data-status-mode="dark"] .rf-pill-hardware { - color: #60a5fa; - border-color: rgba(96, 165, 250, 0.3); - background: rgba(96, 165, 250, 0.1); -} -[data-status-theme="refined"] .rf-monitor-url { - font-size: 12px; - color: var(--sp-text-muted); - font-family: ui-monospace, Menlo, monospace; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; - max-width: 280px; -} - -[data-status-theme="refined"] .rf-badge { - font-size: 11px; - font-weight: 600; - padding: 4px 10px; - border-radius: 999px; - white-space: nowrap; -} -[data-status-theme="refined"] .rf-badge-up { - background: var(--sp-up-soft); - color: var(--sp-up); -} -[data-status-theme="refined"] .rf-badge-warn { - background: var(--sp-warn-soft); - color: var(--sp-warn); -} -[data-status-theme="refined"] .rf-badge-down { - background: var(--sp-down-soft); - color: var(--sp-down); -} - -/* --- heatmap --- */ -[data-status-theme="refined"] .rf-heatmap { - padding: 0 20px 16px; - display: grid; - grid-template-columns: repeat(25, 1fr); - gap: 3px; - height: 42px; -} -[data-status-theme="refined"] .rf-heatmap-cell { - border-radius: 2px; - background: var(--sp-up); - transition: transform 0.15s; -} -[data-status-theme="refined"] .rf-heatmap-cell:hover { - transform: scaleY(1.15); -} -[data-status-theme="refined"] .rf-heatmap-cell.rf-fast { - background: var(--sp-up); -} -[data-status-theme="refined"] .rf-heatmap-cell.rf-med { - background: color-mix(in srgb, var(--sp-up) 60%, #ffffff 40%); -} -[data-status-theme="refined"] .rf-heatmap-cell.rf-slow { - background: var(--sp-warn); -} -[data-status-theme="refined"] .rf-heatmap-cell.rf-down { - background: var(--sp-down); -} -[data-status-theme="refined"] .rf-heatmap-cell.rf-empty { - background: var(--sp-border); - opacity: 0.4; -} - -/* --- histogram --- */ -[data-status-theme="refined"] .rf-histogram { - padding: 0 20px; - display: grid; - grid-template-columns: repeat(25, 1fr); - gap: 3px; - align-items: flex-end; - height: 42px; -} -[data-status-theme="refined"] .rf-bar { - background: var(--sp-up); - border-radius: 2px; - min-height: 3px; -} -[data-status-theme="refined"] .rf-bar.rf-down { - background: var(--sp-down); -} -[data-status-theme="refined"] .rf-bar.rf-empty { - background: var(--sp-border); - opacity: 0.4; -} -[data-status-theme="refined"] .rf-chart-stats { - padding: 0 20px 16px; - font-size: 11px; - color: var(--sp-text-muted); - font-variant-numeric: tabular-nums; -} - -/* --- infrastructure gauges --- */ -[data-status-theme="refined"] .rf-infra { - padding: 14px 20px 18px; - display: grid; - grid-template-columns: repeat(3, 1fr); - gap: 12px; -} -@media (max-width: 720px) { - [data-status-theme="refined"] .rf-infra { - grid-template-columns: 1fr; - } -} -[data-status-theme="refined"] .rf-infra-empty { - padding: 14px 20px 18px; - color: var(--sp-text-muted); - font-size: 13px; -} -[data-status-theme="refined"] .rf-gauge { - border: 1px solid var(--sp-border); - border-radius: 10px; - padding: 12px 14px; - background: var(--sp-bg); -} -[data-status-theme="refined"] .rf-gauge-label { - font-size: 11px; - color: var(--sp-text-muted); - text-transform: uppercase; - letter-spacing: 0.08em; - font-weight: 600; -} -[data-status-theme="refined"] .rf-gauge-value { - font-size: 20px; - font-weight: 600; - letter-spacing: -0.01em; - margin-top: 2px; - font-variant-numeric: tabular-nums; - color: var(--sp-text); -} -[data-status-theme="refined"] .rf-gauge-bar { - height: 4px; - background: var(--sp-border); - border-radius: 2px; - overflow: hidden; - margin-top: 8px; -} -[data-status-theme="refined"] .rf-gauge-fill { - display: block; - height: 100%; - background: var(--sp-up); - border-radius: 2px; - transition: width 0.6s; -} -[data-status-theme="refined"] .rf-gauge-fill.rf-warm { - background: var(--sp-warn); -} -[data-status-theme="refined"] .rf-gauge-fill.rf-hot { - background: var(--sp-down); -} -[data-status-theme="refined"] .rf-gauge-sub { - font-size: 11px; - color: var(--sp-text-muted); - margin-top: 6px; - font-variant-numeric: tabular-nums; -} - -/* --- footer --- */ -[data-status-theme="refined"] .rf-footer { - text-align: center; - color: var(--sp-text-muted); - font-size: 12px; - margin-top: 40px; -} -[data-status-theme="refined"] .rf-footer a { - color: var(--sp-up); - text-decoration: underline; - text-underline-offset: 3px; - font-weight: 600; -} -[data-status-theme="refined"] .rf-footer a:hover { - color: var(--sp-up-strong, var(--sp-up)); -} diff --git a/client/src/Pages/StatusPage/Status/themes/refined/styles.ts b/client/src/Pages/StatusPage/Status/themes/refined/styles.ts new file mode 100644 index 000000000..39bc9bf56 --- /dev/null +++ b/client/src/Pages/StatusPage/Status/themes/refined/styles.ts @@ -0,0 +1,352 @@ +import type { StatusPageThemeTokens } from "../tokens"; + +export type RefinedTone = "up" | "warn" | "down"; +export type RefinedHeatCell = "fast" | "med" | "slow" | "down" | "empty"; +export type RefinedBarKind = "up" | "down" | "empty"; +export type RefinedGaugeFill = "ok" | "warm" | "hot"; + +const sansFontStack = + '-apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif'; + +const cardShadow = "0 1px 2px rgba(10, 16, 32, 0.06), 0 6px 18px rgba(10, 16, 32, 0.08)"; +const cardShadowHover = + "0 2px 4px rgba(16, 24, 40, 0.06), 0 10px 24px rgba(16, 24, 40, 0.06)"; + +const toneColor = (tone: RefinedTone, t: StatusPageThemeTokens) => + tone === "down" ? t.down : tone === "warn" ? t.warn : t.up; + +const toneSoft = (tone: RefinedTone, t: StatusPageThemeTokens) => + tone === "down" ? t.downSoft : tone === "warn" ? t.warnSoft : t.upSoft; + +export const refinedStyles = (tokens: StatusPageThemeTokens, isDark: boolean) => { + const heatCellBg: Record = { + fast: tokens.up, + med: `color-mix(in srgb, ${tokens.up} 60%, #ffffff 40%)`, + slow: tokens.warn, + down: tokens.down, + empty: tokens.border, + }; + + const barBg: Record = { + up: tokens.up, + down: tokens.down, + empty: tokens.border, + }; + + const gaugeFillBg: Record = { + ok: tokens.up, + warm: tokens.warn, + hot: tokens.down, + }; + + const sx: Record = { + page: { + flex: "1 0 auto", + maxWidth: 960, + width: "100%", + mx: "auto", + p: "48px 20px 80px", + fontFamily: sansFontStack, + fontSize: 14, + lineHeight: 1.5, + color: tokens.text, + WebkitFontSmoothing: "antialiased", + }, + + top: { + display: "flex", + alignItems: "center", + justifyContent: "space-between", + mb: "28px", + }, + brand: { + display: "flex", + alignItems: "center", + gap: "10px", + fontWeight: 600, + letterSpacing: "-0.01em", + color: tokens.text, + }, + logoMono: { + width: 28, + height: 28, + borderRadius: "8px", + background: tokens.up, + display: "grid", + placeItems: "center", + color: "#fff", + fontWeight: 700, + fontSize: 13, + }, + logoImg: { + maxHeight: 32, + maxWidth: 120, + objectFit: "contain", + }, + company: { fontSize: 14 }, + + hero: { + background: tokens.surface, + border: `1px solid ${tokens.border}`, + borderRadius: tokens.radius, + padding: "22px 24px", + display: "flex", + alignItems: "center", + gap: "16px", + boxShadow: cardShadow, + mb: "20px", + }, + statusDot: (tone: RefinedTone) => ({ + width: 10, + height: 10, + borderRadius: "50%", + background: toneColor(tone, tokens), + boxShadow: `0 0 0 4px ${toneSoft(tone, tokens)}`, + flexShrink: 0, + }), + statusCopy: { flex: 1, minWidth: 0 }, + heroTitle: { + m: 0, + mb: "2px", + fontSize: 17, + fontWeight: 600, + letterSpacing: "-0.01em", + color: tokens.text, + }, + heroSub: { m: 0, color: tokens.textMuted, fontSize: 13 }, + heroIcon: (tone: RefinedTone) => ({ + color: toneColor(tone, tokens), + display: "flex", + alignItems: "center", + }), + + chartSwitchWrap: { + display: "flex", + justifyContent: "flex-end", + mb: "12px", + }, + chartSwitch: { + display: "inline-flex", + border: `1px solid ${tokens.border}`, + borderRadius: "8px", + background: tokens.surface, + p: "3px", + gap: "2px", + }, + chartSwitchButton: (active: boolean) => ({ + border: 0, + background: active ? tokens.upSoft : "transparent", + fontFamily: "inherit", + fontSize: 11, + padding: "5px 14px", + cursor: "pointer", + color: active ? tokens.up : tokens.textMuted, + borderRadius: "5px", + transition: "background 0.15s ease, color 0.15s ease", + fontWeight: active ? 600 : 500, + "&:hover": { color: active ? tokens.up : tokens.text }, + }), + + monitorList: { + listStyle: "none", + m: 0, + p: 0, + display: "flex", + flexDirection: "column", + gap: "12px", + }, + card: { + background: tokens.surface, + border: `1px solid ${tokens.border}`, + borderRadius: tokens.radius, + boxShadow: cardShadow, + overflow: "hidden", + position: "relative", + transition: "transform 0.15s, box-shadow 0.15s", + "&:hover": { transform: "translateY(-1px)", boxShadow: cardShadowHover }, + }, + cardRow: { + display: "grid", + gridTemplateColumns: "1fr auto", + alignItems: "center", + gap: "16px", + p: "16px 20px", + }, + cardLeft: { minWidth: 0 }, + monitorName: { + fontWeight: 600, + fontSize: 14, + letterSpacing: "-0.005em", + color: tokens.text, + overflow: "hidden", + textOverflow: "ellipsis", + whiteSpace: "nowrap", + }, + monitorMeta: { + display: "flex", + gap: "10px", + alignItems: "center", + mt: "4px", + flexWrap: "wrap", + }, + pill: { + fontSize: 10, + textTransform: "uppercase", + letterSpacing: "0.08em", + color: tokens.textMuted, + border: `1px solid ${tokens.border}`, + padding: "2px 8px", + borderRadius: "999px", + fontWeight: 600, + }, + pillHardware: isDark + ? { + fontSize: 10, + textTransform: "uppercase", + letterSpacing: "0.08em", + padding: "2px 8px", + borderRadius: "999px", + fontWeight: 600, + color: "#60a5fa", + border: "1px solid rgba(96, 165, 250, 0.3)", + background: "rgba(96, 165, 250, 0.1)", + } + : { + fontSize: 10, + textTransform: "uppercase", + letterSpacing: "0.08em", + padding: "2px 8px", + borderRadius: "999px", + fontWeight: 600, + color: "#1d4ed8", + border: "1px solid rgba(29, 78, 216, 0.3)", + background: "rgba(29, 78, 216, 0.06)", + }, + monitorUrl: { + fontSize: 12, + color: tokens.textMuted, + fontFamily: "ui-monospace, Menlo, monospace", + overflow: "hidden", + textOverflow: "ellipsis", + whiteSpace: "nowrap", + maxWidth: 280, + }, + + badge: (tone: RefinedTone) => ({ + fontSize: 11, + fontWeight: 600, + padding: "4px 10px", + borderRadius: "999px", + whiteSpace: "nowrap", + background: toneSoft(tone, tokens), + color: toneColor(tone, tokens), + }), + + heatmap: { + padding: "0 20px 16px", + display: "grid", + gridTemplateColumns: "repeat(25, 1fr)", + gap: "3px", + height: 42, + }, + heatmapCell: (kind: RefinedHeatCell) => ({ + borderRadius: "2px", + background: heatCellBg[kind], + opacity: kind === "empty" ? 0.4 : 1, + transition: "transform 0.15s", + "&:hover": { transform: "scaleY(1.15)" }, + }), + + histogram: { + padding: "0 20px", + display: "grid", + gridTemplateColumns: "repeat(25, 1fr)", + gap: "3px", + alignItems: "flex-end", + height: 42, + }, + bar: (kind: RefinedBarKind, heightPct: number) => ({ + background: barBg[kind], + borderRadius: "2px", + minHeight: 3, + opacity: kind === "empty" ? 0.4 : 1, + height: `${heightPct}%`, + }), + chartStats: { + padding: "0 20px 16px", + fontSize: 11, + color: tokens.textMuted, + fontVariantNumeric: "tabular-nums", + }, + + infra: { + padding: "14px 20px 18px", + display: "grid", + gridTemplateColumns: { xs: "1fr", md: "repeat(3, 1fr)" }, + gap: "12px", + }, + infraEmpty: { + padding: "14px 20px 18px", + color: tokens.textMuted, + fontSize: 13, + }, + gauge: { + border: `1px solid ${tokens.border}`, + borderRadius: "10px", + p: "12px 14px", + background: tokens.bg, + }, + gaugeLabel: { + fontSize: 11, + color: tokens.textMuted, + textTransform: "uppercase", + letterSpacing: "0.08em", + fontWeight: 600, + }, + gaugeValue: { + fontSize: 20, + fontWeight: 600, + letterSpacing: "-0.01em", + mt: "2px", + fontVariantNumeric: "tabular-nums", + color: tokens.text, + }, + gaugeBar: { + height: 4, + background: tokens.border, + borderRadius: "2px", + overflow: "hidden", + mt: "8px", + }, + gaugeFill: (level: RefinedGaugeFill, widthPct: number) => ({ + display: "block", + height: "100%", + background: gaugeFillBg[level], + borderRadius: "2px", + transition: "width 0.6s", + width: `${Math.max(0, Math.min(100, widthPct))}%`, + }), + gaugeSub: { + fontSize: 11, + color: tokens.textMuted, + mt: "6px", + fontVariantNumeric: "tabular-nums", + }, + + footer: { + textAlign: "center", + color: tokens.textMuted, + fontSize: 12, + mt: "40px", + "& a": { + color: tokens.up, + textDecoration: "underline", + textUnderlineOffset: "3px", + fontWeight: 600, + "&:hover": { color: tokens.upStrong || tokens.up }, + }, + }, + }; + + return sx; +}; diff --git a/client/src/Pages/StatusPage/Status/themes/shared/ThemedHeatmap.tsx b/client/src/Pages/StatusPage/Status/themes/shared/ThemedHeatmap.tsx index 735f02fa8..2a442405c 100644 --- a/client/src/Pages/StatusPage/Status/themes/shared/ThemedHeatmap.tsx +++ b/client/src/Pages/StatusPage/Status/themes/shared/ThemedHeatmap.tsx @@ -2,18 +2,25 @@ import Tooltip from "@mui/material/Tooltip"; import Box from "@mui/material/Box"; import Stack from "@mui/material/Stack"; import Typography from "@mui/material/Typography"; +import type { SxProps, Theme } from "@mui/material/styles"; import { useTranslation } from "react-i18next"; import type { CheckSnapshot } from "@/Types/Check"; import { formatCheckTimestamp } from "./timeFormat"; const CELLS = 25; +export type HeatCellKind = "fast" | "med" | "slow" | "down" | "empty"; + interface Props { checks: CheckSnapshot[]; - classPrefix: string; + /** sx-based API — preferred. Themes pass their own container + cell recipes. */ + containerSx?: SxProps; + cellSx?: (kind: HeatCellKind) => SxProps; + /** Legacy className-based API — kept for unmigrated themes. Will be removed once all themes move to sx. */ + classPrefix?: string; } -const classify = (check: CheckSnapshot): "fast" | "med" | "slow" | "down" => { +const classify = (check: CheckSnapshot): Exclude => { if (!check.status) return "down"; const rt = check.responseTime ?? 0; if (rt > 500) return "slow"; @@ -21,8 +28,9 @@ const classify = (check: CheckSnapshot): "fast" | "med" | "slow" | "down" => { return "fast"; }; -export const ThemedHeatmap = ({ checks, classPrefix }: Props) => { +export const ThemedHeatmap = ({ checks, containerSx, cellSx, classPrefix }: Props) => { const { t } = useTranslation(); + const useSxApi = Boolean(cellSx); const source = checks.slice(0, CELLS).reverse(); const padded: (CheckSnapshot | null)[] = [ @@ -30,9 +38,18 @@ export const ThemedHeatmap = ({ checks, classPrefix }: Props) => { ...source, ]; + const containerProps = useSxApi + ? { sx: containerSx } + : { className: `${classPrefix}-heatmap` }; + + const cellProps = (kind: HeatCellKind) => + useSxApi + ? { sx: cellSx!(kind) } + : { className: `${classPrefix}-heatmap-cell ${classPrefix}-${kind}` }; + return ( @@ -41,11 +58,11 @@ export const ThemedHeatmap = ({ checks, classPrefix }: Props) => { return ( ); } - const cls = classify(check); + const kind = classify(check); const tooltipContent = ( { placement="top" > diff --git a/client/src/Pages/StatusPage/Status/themes/shared/ThemedHistogram.tsx b/client/src/Pages/StatusPage/Status/themes/shared/ThemedHistogram.tsx index 83a63d01c..65027731b 100644 --- a/client/src/Pages/StatusPage/Status/themes/shared/ThemedHistogram.tsx +++ b/client/src/Pages/StatusPage/Status/themes/shared/ThemedHistogram.tsx @@ -3,6 +3,7 @@ import Tooltip from "@mui/material/Tooltip"; import Box from "@mui/material/Box"; import Stack from "@mui/material/Stack"; import Typography from "@mui/material/Typography"; +import type { SxProps, Theme } from "@mui/material/styles"; import { useTranslation } from "react-i18next"; import type { CheckSnapshot } from "@/Types/Check"; import { formatCheckTimestamp } from "./timeFormat"; @@ -10,16 +11,32 @@ import { formatCheckTimestamp } from "./timeFormat"; const CELLS = 25; const MIN_HEIGHT_PCT = 6; +export type BarKind = "up" | "down" | "empty"; + interface Props { checks: CheckSnapshot[]; - classPrefix: string; + /** sx-based API — preferred. */ + containerSx?: SxProps; + barSx?: (kind: BarKind, heightPct: number) => SxProps; + statsSx?: SxProps; + /** Legacy className-based API. Will be removed once all themes move to sx. */ + classPrefix?: string; statsGap?: number; } -const tone = (check: CheckSnapshot): "up" | "down" => (check.status ? "up" : "down"); +const tone = (check: CheckSnapshot): Exclude => + check.status ? "up" : "down"; -export const ThemedHistogram = ({ checks, classPrefix, statsGap = 1 }: Props) => { +export const ThemedHistogram = ({ + checks, + containerSx, + barSx, + statsSx, + classPrefix, + statsGap = 1, +}: Props) => { const { t } = useTranslation(); + const useSxApi = Boolean(barSx); const { padded, max, avg, peak } = useMemo(() => { const source = checks.slice(0, CELLS).reverse(); @@ -35,12 +52,25 @@ export const ThemedHistogram = ({ checks, classPrefix, statsGap = 1 }: Props) => return { padded: out, max: maxRt, avg: avgRt, peak: valid.length ? maxRt : 0 }; }, [checks]); + const containerProps = useSxApi + ? { sx: containerSx } + : { className: `${classPrefix}-histogram` }; + + const statsProps = useSxApi + ? { sx: statsSx } + : { className: `${classPrefix}-chart-stats` }; + return ( - + {padded.map((check, i) => { if (!check) { - return ( + return useSxApi ? ( + + ) : ( arrow placement="top" > - + {useSxApi ? ( + + ) : ( + + )} ); })} @@ -89,7 +126,7 @@ export const ThemedHistogram = ({ checks, classPrefix, statsGap = 1 }: Props) => {t("pages.statusPages.monitorsList.chart.avg", { value: avg })} {t("pages.statusPages.monitorsList.chart.max", { value: peak })} diff --git a/client/src/Pages/StatusPage/Status/themes/shared/ThemedInfrastructure.tsx b/client/src/Pages/StatusPage/Status/themes/shared/ThemedInfrastructure.tsx index f465ece91..d4334e959 100644 --- a/client/src/Pages/StatusPage/Status/themes/shared/ThemedInfrastructure.tsx +++ b/client/src/Pages/StatusPage/Status/themes/shared/ThemedInfrastructure.tsx @@ -1,11 +1,28 @@ import Box from "@mui/material/Box"; import prettyBytes from "pretty-bytes"; +import type { SxProps, Theme } from "@mui/material/styles"; import { useTranslation } from "react-i18next"; import type { Monitor } from "@/Types/Monitor"; +export type GaugeFillLevel = "ok" | "warm" | "hot"; + +interface InfraSx { + containerSx: SxProps; + emptySx: SxProps; + gaugeSx: SxProps; + gaugeLabelSx: SxProps; + gaugeValueSx: SxProps; + gaugeBarSx: SxProps; + gaugeFillSx: (level: GaugeFillLevel, widthPct: number) => SxProps; + gaugeSubSx: SxProps; +} + interface Props { monitor: Monitor & { checks?: Monitor["recentChecks"] }; - classPrefix: string; + /** sx-based API — preferred. */ + sxApi?: InfraSx; + /** Legacy className-based API. Will be removed once all themes move to sx. */ + classPrefix?: string; } interface Gauge { @@ -17,16 +34,24 @@ interface Gauge { const PCT = 100; -export const ThemedInfrastructure = ({ monitor, classPrefix }: Props) => { +const heatLevel = (value: number): GaugeFillLevel => + value > 85 ? "hot" : value > 70 ? "warm" : "ok"; + +export const ThemedInfrastructure = ({ monitor, sxApi, classPrefix }: Props) => { const { t } = useTranslation(); + const useSxApi = Boolean(sxApi); const latest = monitor.recentChecks?.[0] ?? monitor.checks?.[0]; - if (!latest) { - return ( - - {t("pages.statusPages.monitorsList.noData")} - + + const renderEmpty = () => { + const message = t("pages.statusPages.monitorsList.noData"); + return useSxApi ? ( + {message} + ) : ( + {message} ); - } + }; + + if (!latest) return renderEmpty(); const gauges: Gauge[] = []; @@ -67,10 +92,25 @@ export const ThemedInfrastructure = ({ monitor, classPrefix }: Props) => { }); } - if (gauges.length === 0) { + if (gauges.length === 0) return renderEmpty(); + + if (useSxApi) { + const s = sxApi!; return ( - - {t("pages.statusPages.monitorsList.noData")} + + {gauges.map((g) => ( + + {g.label} + {g.value.toFixed(0)}% + + + + {g.sub} + + ))} ); }