fix: changes fixing type errors and adding colorFn comment
This commit is contained in:
1 parent
6cea199e4f
commit
41fa2717a9
2 files changed
+10
-8
No files matched your search
@@ -3,7 +3,7 @@ import Stack from "@mui/material/Stack";
|
|||||||
import Box from "@mui/material/Box";
|
import Box from "@mui/material/Box";
|
||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
|
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme, type Theme } from "@mui/material/styles";
|
||||||
import { useMemo, useState, useEffect } from "react";
|
import { useMemo, useState, useEffect } from "react";
|
||||||
import { getInfraGaugeColor } from "@/Utils/MonitorUtils";
|
import { getInfraGaugeColor } from "@/Utils/MonitorUtils";
|
||||||
|
|
||||||
@@ -17,6 +17,9 @@ export const Gauge = ({
|
|||||||
strokeWidth = 15,
|
strokeWidth = 15,
|
||||||
precision = 1,
|
precision = 1,
|
||||||
unit = "%",
|
unit = "%",
|
||||||
|
// colorFn lets callers override the default color logic.
|
||||||
|
// The Gauge was originally designed for metrics where higher values are worse (e.g., CPU usage).
|
||||||
|
// PageSpeed scores are the opposite—higher is better—so a custom colorFn can be used to invert the behavior.
|
||||||
colorFn,
|
colorFn,
|
||||||
}: {
|
}: {
|
||||||
isLoading?: boolean;
|
isLoading?: boolean;
|
||||||
@@ -25,7 +28,7 @@ export const Gauge = ({
|
|||||||
strokeWidth?: number;
|
strokeWidth?: number;
|
||||||
precision?: number;
|
precision?: number;
|
||||||
unit?: string;
|
unit?: string;
|
||||||
colorFn?: (val: number, theme: any) => string;
|
colorFn?: (val: number, theme: Theme) => string;
|
||||||
}) => {
|
}) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const progressWithinRange = Math.max(MINIMUM_VALUE, Math.min(progress, MAXIMUM_VALUE));
|
const progressWithinRange = Math.max(MINIMUM_VALUE, Math.min(progress, MAXIMUM_VALUE));
|
||||||
|
|||||||
@@ -27,14 +27,12 @@ interface MonitorsListProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getMonitorBadgeStyles = (monitorType: string, theme: Theme) => {
|
const getMonitorBadgeStyles = (monitorType: string, theme: Theme) => {
|
||||||
const monitorColors = {
|
const monitorColors: Record<string, string> = {
|
||||||
hardware: theme.palette.info.light,
|
hardware: theme.palette.info.light,
|
||||||
pagespeed: theme.palette.warning.light,
|
pagespeed: theme.palette.warning.light,
|
||||||
};
|
};
|
||||||
|
|
||||||
const bg =
|
const bg = monitorColors[monitorType] || theme.palette.success.light;
|
||||||
monitorColors[monitorType as keyof typeof monitorColors] ||
|
|
||||||
theme.palette.success.light;
|
|
||||||
return {
|
return {
|
||||||
backgroundColor: bg,
|
backgroundColor: bg,
|
||||||
color: theme.palette.background.paper,
|
color: theme.palette.background.paper,
|
||||||
@@ -113,8 +111,9 @@ const MonitorContent = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (monitor.type === "pagespeed") {
|
if (monitor.type === "pagespeed") {
|
||||||
if (statusPage.showPageSpeed === false) return null;
|
return statusPage.showPageSpeed === false ? null : (
|
||||||
return <PageSpeedMetrics monitor={monitor} />;
|
<PageSpeedMetrics monitor={monitor} />
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (statusPage.showCharts === false) return null;
|
if (statusPage.showCharts === false) return null;
|
||||||
|
|||||||
Reference in new issue
Block a user