refactor(status-page): tighten the refined-theme conversion

Apply review feedback:
- Type the styles factory's return as a named RefinedStyles interface so the consumer no longer needs `as Function` / `as any` casts on factory entries
- Lift toneColor / toneSoft to shared/overallStatus alongside the existing OverallTone type — the next three themes will need the same mapping
- Reuse heatLevel() in the legacy classPrefix branch of ThemedInfrastructure so both API paths share one threshold table
- Memoize the styles map in RefinedStatusPage so MUI's sx processor sees referential equality across renders that don't actually change tokens
- Make the dual-API gate in ThemedHeatmap / ThemedHistogram require ALL relevant sx props together so a partial migration can't silently fall back to the legacy class path
This commit is contained in:
gorkem-bwl committed 2026-04-27 18:30:04 -04:00
1 parent 163f5ec1ec
commit b95d8886b9
6 files changed
+92 -68

No files matched your search

@@ -30,7 +30,7 @@ const classify = (check: CheckSnapshot): Exclude<HeatCellKind, "empty"> => {
export const ThemedHeatmap = ({ checks, containerSx, cellSx, classPrefix }: Props) => {
const { t } = useTranslation();
const useSxApi = Boolean(cellSx);
const useSxApi = Boolean(containerSx && cellSx);
const source = checks.slice(0, CELLS).reverse();
const padded: (CheckSnapshot | null)[] = [
@@ -36,7 +36,7 @@ export const ThemedHistogram = ({
statsGap = 1,
}: Props) => {
const { t } = useTranslation();
const useSxApi = Boolean(barSx);
const useSxApi = Boolean(containerSx && barSx && statsSx);
const { padded, max, avg, peak } = useMemo(() => {
const source = checks.slice(0, CELLS).reverse();
@@ -118,8 +118,8 @@ export const ThemedInfrastructure = ({ monitor, sxApi, classPrefix }: Props) =>
return (
<Box className={`${classPrefix}-infra`}>
{gauges.map((g) => {
const heatClass =
g.value > 85 ? `${classPrefix}-hot` : g.value > 70 ? `${classPrefix}-warm` : "";
const level = heatLevel(g.value);
const heatClass = level === "ok" ? "" : `${classPrefix}-${level}`;
return (
<Box
key={g.key}
@@ -9,9 +9,16 @@ import {
Wrench,
} from "lucide-react";
import type { Monitor, MonitorStatus } from "@/Types/Monitor";
import type { StatusPageThemeTokens } from "../tokens";
export type OverallTone = "up" | "warn" | "down";
export const toneColor = (tone: OverallTone, t: StatusPageThemeTokens): string =>
tone === "down" ? t.down : tone === "warn" ? t.warn : t.up;
export const toneSoft = (tone: OverallTone, t: StatusPageThemeTokens): string =>
tone === "down" ? t.downSoft : tone === "warn" ? t.warnSoft : t.upSoft;
export interface OverallStatus {
tone: OverallTone;
message: string;