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:
1 parent
944ee74a1d
commit
163f5ec1ec
6 files changed
+553
-493
No files matched your search
@@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user