From 6856914d411f908fd340b6b1d7172013599246e7 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Thu, 30 Jul 2026 10:56:24 -0700 Subject: [PATCH] extract hardcoded strings --- .../Components/monitors/charts/ChartUtils.ts | 15 +- .../monitors/charts/HistogramDetails.tsx | 26 ++- .../charts/HistogramDetailsStacked.tsx | 207 ------------------ client/src/locales/en.json | 14 +- 4 files changed, 41 insertions(+), 221 deletions(-) delete mode 100644 client/src/Components/monitors/charts/HistogramDetailsStacked.tsx diff --git a/client/src/Components/monitors/charts/ChartUtils.ts b/client/src/Components/monitors/charts/ChartUtils.ts index fb9d1779c..0516eaac3 100644 --- a/client/src/Components/monitors/charts/ChartUtils.ts +++ b/client/src/Components/monitors/charts/ChartUtils.ts @@ -23,11 +23,12 @@ export const PHASE_COLOR_KEYS = { avgDownload: "download", } as const; -export const PHASE_LABELS: Record<(typeof PHASE_KEYS)[number], string> = { - avgDns: "DNS", - avgTcp: "TCP", - avgTls: "TLS", - avgRequest: "Request", - avgFirstByte: "First byte", - avgDownload: "Download", +// i18n keys, resolved with t() at render +export const PHASE_LABEL_KEYS: Record<(typeof PHASE_KEYS)[number], string> = { + avgDns: "common.charts.phases.dns", + avgTcp: "common.charts.phases.tcp", + avgTls: "common.charts.phases.tls", + avgRequest: "common.charts.phases.request", + avgFirstByte: "common.charts.phases.firstByte", + avgDownload: "common.charts.phases.download", }; diff --git a/client/src/Components/monitors/charts/HistogramDetails.tsx b/client/src/Components/monitors/charts/HistogramDetails.tsx index 0736abd6c..1f78c692e 100644 --- a/client/src/Components/monitors/charts/HistogramDetails.tsx +++ b/client/src/Components/monitors/charts/HistogramDetails.tsx @@ -17,6 +17,7 @@ import Typography from "@mui/material/Typography"; import prettyMilliseconds from "pretty-ms"; import { XTick } from "@/Components/monitors/charts/XTick"; import { useSelector } from "react-redux"; +import { useTranslation } from "react-i18next"; import { formatDateWithTz, tooltipDateFormatLookup } from "@/Utils/TimeUtils"; import { useTheme } from "@mui/material/styles"; import type { Theme } from "@mui/material/styles"; @@ -29,7 +30,7 @@ import { SPACING } from "@/Utils/Theme/constants"; import { PHASE_COLOR_KEYS, PHASE_KEYS, - PHASE_LABELS, + PHASE_LABEL_KEYS, } from "@/Components/monitors/charts/ChartUtils"; type DetailsCheck = GroupedCheck & @@ -49,6 +50,7 @@ const ResponseTimeToolTip = ({ theme, uiTimezone, }: ResponseTimeToolTipProps) => { + const { t } = useTranslation(); if (!label) return null; if (!payload) return null; if (!active) return null; @@ -59,8 +61,12 @@ const ResponseTimeToolTip = ({ {formatDateWithTz(String(label), format, uiTimezone)} - Response time:{" "} - {prettyMilliseconds(responseTime, { formatSubMilliseconds: true, compact: true })} + {t("common.charts.histogram.responseTime", { + value: prettyMilliseconds(responseTime, { + formatSubMilliseconds: true, + compact: true, + }), + })} ); @@ -79,6 +85,7 @@ const TimingPhasesToolTip = ({ theme, uiTimezone, }: TimingPhaseToolTipProps) => { + const { t } = useTranslation(); if (!active || !payload?.length) return null; const bucket = payload[0].payload as GroupedUptimeCheck; const total = PHASE_KEYS.reduce((sum, key) => sum + bucket[key], 0); @@ -86,7 +93,9 @@ const TimingPhasesToolTip = ({ return ( {formatDateWithTz(bucket.bucketDate, format, uiTimezone)} - Total: {prettyMilliseconds(total)} + + {t("common.charts.histogram.total", { value: prettyMilliseconds(total) })} + {PHASE_KEYS.map((key) => ( - {PHASE_LABELS[key]}:{" "} + {t(PHASE_LABEL_KEYS[key])}:{" "} {prettyMilliseconds(bucket[key], { formatSubMilliseconds: true, compact: true, @@ -119,6 +128,7 @@ export const HistogramDetails = ({ range: string; }) => { const [showTimingPhases, setShowTimingPhases] = useState(false); + const { t } = useTranslation(); const theme = useTheme(); const uiTimezone = useSelector((state: RootState) => state.ui.timezone); const yMax = useMemo(() => { @@ -142,7 +152,11 @@ export const HistogramDetails = ({ strokeWidth={1.5} /> } - title={showTimingPhases ? "Timing Phases" : "Response Time"} + title={ + showTimingPhases + ? t("common.charts.labels.timingPhases") + : t("common.charts.labels.responseTime") + } onClick={() => { if (!hasTimingPhases) return; setShowTimingPhases((prev) => !prev); diff --git a/client/src/Components/monitors/charts/HistogramDetailsStacked.tsx b/client/src/Components/monitors/charts/HistogramDetailsStacked.tsx deleted file mode 100644 index 2ef74f56b..000000000 --- a/client/src/Components/monitors/charts/HistogramDetailsStacked.tsx +++ /dev/null @@ -1,207 +0,0 @@ -import type { GroupedUptimeCheck } from "@/Types/Check"; -import type { TooltipProps } from "recharts"; -import type { NameType, ValueType } from "recharts/types/component/DefaultTooltipContent"; -import type { Theme } from "@mui/material/styles"; -import type { RootState } from "@/Types/state"; -import { Clock } from "lucide-react"; -import prettyMilliseconds from "pretty-ms"; - -import Stack from "@mui/material/Stack"; -import { - Area, - AreaChart, - CartesianGrid, - ResponsiveContainer, - YAxis, - XAxis, - Tooltip, -} from "recharts"; -import { BaseBox, BaseChart, Dot } from "@/Components/design-elements"; -import Typography from "@mui/material/Typography"; -import { XTick } from "@/Components/monitors/charts/XTick"; - -import { formatDateWithTz, tooltipDateFormatLookup } from "@/Utils/TimeUtils"; -import { useSelector } from "react-redux"; -import { useMemo } from "react"; -import { useTheme } from "@mui/material"; -import { SPACING } from "@/Utils/Theme/constants"; -import { computeYAxisCap } from "@/Components/monitors/charts/ChartUtils"; - -export const PHASE_KEYS = [ - "avgDns", - "avgTcp", - "avgTls", - "avgRequest", - "avgFirstByte", - "avgDownload", -] as const; - -const PHASE_COLOR_KEYS = { - avgDns: "dns", - avgTcp: "tcp", - avgTls: "tls", - avgRequest: "request", - avgFirstByte: "firstByte", - avgDownload: "download", -} as const; - -const PHASE_LABELS: Record<(typeof PHASE_KEYS)[number], string> = { - avgDns: "DNS", - avgTcp: "TCP", - avgTls: "TLS", - avgRequest: "Request", - avgFirstByte: "First byte", - avgDownload: "Download", -}; - -type TimingPhaseToolTipProps = TooltipProps & { - range: string; - theme: Theme; - uiTimezone: string; -}; - -const TimingPhasesToolTip = ({ - active, - payload, - range, - theme, - uiTimezone, -}: TimingPhaseToolTipProps) => { - if (!active || !payload?.length) return null; - const bucket = payload[0].payload as GroupedUptimeCheck; - const total = PHASE_KEYS.reduce((sum, key) => sum + bucket[key], 0); - const format = tooltipDateFormatLookup(range); - return ( - - {formatDateWithTz(bucket.bucketDate, format, uiTimezone)} - Total: {prettyMilliseconds(total)} - {PHASE_KEYS.map((key) => ( - - - - {PHASE_LABELS[key]}:{" "} - {prettyMilliseconds(bucket[key], { - formatSubMilliseconds: true, - compact: true, - })} - - - ))} - - ); -}; - -export const HistogramDetailsStacked = ({ - checks = [], - range, -}: { - checks: GroupedUptimeCheck[]; - range: string; -}) => { - const theme = useTheme(); - const uiTimezone = useSelector((state: RootState) => state.ui.timezone); - - // Cap the y domain at 2x the p95 of bucket totals, so typical stacks sit - // around mid-height with headroom above - const yMax = useMemo(() => { - const totals = checks.map((check) => - PHASE_KEYS.reduce((sum, key) => sum + check[key], 0) - ); - return computeYAxisCap(totals); - }, [checks]); - - return ( - - } - title="Timing phases" - > - - - - - {PHASE_KEYS.map((key) => ( - - - - - ))} - - - ( - - )} - /> - ( - - )} - /> - {PHASE_KEYS.map((key) => ( - - ))} - - - - ); -}; diff --git a/client/src/locales/en.json b/client/src/locales/en.json index d940f95fc..82d144b1c 100644 --- a/client/src/locales/en.json +++ b/client/src/locales/en.json @@ -68,11 +68,23 @@ "downtime": "Downtime", "high": "High", "low": "Low", + "responseTime": "Response time", + "timingPhases": "Timing phases", "uptime": "Uptime" }, "histogram": { "avg": "Avg: {{value}} ms", - "max": "Max: {{value}} ms" + "max": "Max: {{value}} ms", + "responseTime": "Response time: {{value}}", + "total": "Total: {{value}}" + }, + "phases": { + "dns": "DNS", + "tcp": "TCP", + "tls": "TLS", + "request": "Request", + "firstByte": "First byte", + "download": "Download" } }, "dialogs": {