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.
This commit is contained in:
gorkem-bwl committed 2026-04-27 18:21:31 -04:00
1 parent 944ee74a1d
commit 163f5ec1ec
6 files changed
+553 -493

No files matched your search

@@ -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<Theme>;
cellSx?: (kind: HeatCellKind) => SxProps<Theme>;
/** 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<HeatCellKind, "empty"> => {
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 (
<Box
className={`${classPrefix}-heatmap`}
{...containerProps}
role="img"
aria-label={t("pages.statusPages.monitorsList.chart.heatmapAria")}
>
@@ -41,11 +58,11 @@ export const ThemedHeatmap = ({ checks, classPrefix }: Props) => {
return (
<Box
key={`empty-${i}`}
className={`${classPrefix}-heatmap-cell ${classPrefix}-empty`}
{...cellProps("empty")}
/>
);
}
const cls = classify(check);
const kind = classify(check);
const tooltipContent = (
<Stack gap={0.25}>
<Typography
@@ -72,7 +89,7 @@ export const ThemedHeatmap = ({ checks, classPrefix }: Props) => {
placement="top"
>
<Box
className={`${classPrefix}-heatmap-cell ${classPrefix}-${cls}`}
{...cellProps(kind)}
aria-label={`${check.responseTime} ms, ${check.status ? "up" : "down"}`}
/>
</Tooltip>
@@ -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<Theme>;
barSx?: (kind: BarKind, heightPct: number) => SxProps<Theme>;
statsSx?: SxProps<Theme>;
/** 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<BarKind, "empty"> =>
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 (
<Stack gap={statsGap}>
<Box className={`${classPrefix}-histogram`}>
<Box {...containerProps}>
{padded.map((check, i) => {
if (!check) {
return (
return useSxApi ? (
<Box
key={`empty-${i}`}
sx={barSx!("empty", MIN_HEIGHT_PCT)}
/>
) : (
<Box
key={`empty-${i}`}
className={`${classPrefix}-bar ${classPrefix}-empty`}
@@ -77,11 +107,18 @@ export const ThemedHistogram = ({ checks, classPrefix, statsGap = 1 }: Props) =>
arrow
placement="top"
>
<Box
className={`${classPrefix}-bar ${classPrefix}-${tone(check)}`}
style={{ height: `${height}%` }}
aria-label={`${check.responseTime} ms`}
/>
{useSxApi ? (
<Box
sx={barSx!(tone(check), height)}
aria-label={`${check.responseTime} ms`}
/>
) : (
<Box
className={`${classPrefix}-bar ${classPrefix}-${tone(check)}`}
style={{ height: `${height}%` }}
aria-label={`${check.responseTime} ms`}
/>
)}
</Tooltip>
);
})}
@@ -89,7 +126,7 @@ export const ThemedHistogram = ({ checks, classPrefix, statsGap = 1 }: Props) =>
<Stack
direction="row"
justifyContent="space-between"
className={`${classPrefix}-chart-stats`}
{...statsProps}
>
<span>{t("pages.statusPages.monitorsList.chart.avg", { value: avg })}</span>
<span>{t("pages.statusPages.monitorsList.chart.max", { value: peak })}</span>
@@ -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<Theme>;
emptySx: SxProps<Theme>;
gaugeSx: SxProps<Theme>;
gaugeLabelSx: SxProps<Theme>;
gaugeValueSx: SxProps<Theme>;
gaugeBarSx: SxProps<Theme>;
gaugeFillSx: (level: GaugeFillLevel, widthPct: number) => SxProps<Theme>;
gaugeSubSx: SxProps<Theme>;
}
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 (
<Box className={`${classPrefix}-infra-empty`}>
{t("pages.statusPages.monitorsList.noData")}
</Box>
const renderEmpty = () => {
const message = t("pages.statusPages.monitorsList.noData");
return useSxApi ? (
<Box sx={sxApi!.emptySx}>{message}</Box>
) : (
<Box className={`${classPrefix}-infra-empty`}>{message}</Box>
);
}
};
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 (
<Box className={`${classPrefix}-infra-empty`}>
{t("pages.statusPages.monitorsList.noData")}
<Box sx={s.containerSx}>
{gauges.map((g) => (
<Box
key={g.key}
sx={s.gaugeSx}
>
<Box sx={s.gaugeLabelSx}>{g.label}</Box>
<Box sx={s.gaugeValueSx}>{g.value.toFixed(0)}%</Box>
<Box sx={s.gaugeBarSx}>
<Box sx={s.gaugeFillSx(heatLevel(g.value), Math.min(100, g.value))} />
</Box>
<Box sx={s.gaugeSubSx}>{g.sub}</Box>
</Box>
))}
</Box>
);
}