diff --git a/client/src/Pages/StatusPage/Status/index.tsx b/client/src/Pages/StatusPage/Status/index.tsx index ae5b3d8ed..b38b25323 100644 --- a/client/src/Pages/StatusPage/Status/index.tsx +++ b/client/src/Pages/StatusPage/Status/index.tsx @@ -87,6 +87,16 @@ const StatusPageView = () => { const location = useLocation(); const [searchParams, setSearchParams] = useSearchParams(); + const onRangeChange = (next: StatusPageRange) => { + const updated = new URLSearchParams(searchParams); + if (next === "latest") { + updated.delete("range"); + } else { + updated.set("range", next); + } + setSearchParams(updated, { replace: true }); + }; + const onCustomDomainHost = isCustomDomainHost(); const isPublic = onCustomDomainHost || location.pathname.startsWith(PUBLIC_STATUS_PAGE_PREFIX); @@ -160,6 +170,9 @@ const StatusPageView = () => { statusPage={statusPage} monitors={monitors} config={themeConfig} + range={range} + onRangeChange={onRangeChange} + bucketTimezone={data.bucketTimezone ?? "Etc/UTC"} /> ); diff --git a/client/src/Pages/StatusPage/Status/themes/bold/styles.ts b/client/src/Pages/StatusPage/Status/themes/bold/styles.ts index c4df4e207..86208d41b 100644 --- a/client/src/Pages/StatusPage/Status/themes/bold/styles.ts +++ b/client/src/Pages/StatusPage/Status/themes/bold/styles.ts @@ -4,8 +4,10 @@ import { type OverallTone, toneColor, toneSoft } from "../shared/overallStatus"; import { BOLD_SANS_STACK, MONO_STACK } from "../shared/fontStacks"; import { MAX_RECENT_CHECKS } from "@/Types/Monitor"; -export type BoldHeatCell = "fast" | "med" | "slow" | "down" | "empty"; -export type BoldBarKind = "up" | "down" | "empty"; +import type { BarKind, HeatCellKind } from "../shared/ChartCells"; + +export type BoldHeatCell = HeatCellKind; +export type BoldBarKind = BarKind; export type BoldGaugeFill = "ok" | "warm" | "hot"; export interface BoldStyles { @@ -55,6 +57,7 @@ export const boldStyles = ( fast: tokens.up, med: `color-mix(in srgb, ${tokens.up} 70%, #ffffff 30%)`, slow: tokens.warn, + degraded: tokens.degraded, down: tokens.down, empty: tokens.border, }; @@ -62,12 +65,14 @@ export const boldStyles = ( fast: `0 0 6px color-mix(in srgb, ${tokens.up} 18%, transparent)`, med: `0 0 6px color-mix(in srgb, ${tokens.up} 18%, transparent)`, slow: `0 0 6px color-mix(in srgb, ${tokens.warn} 20%, transparent)`, + degraded: `0 0 6px color-mix(in srgb, ${tokens.degraded} 20%, transparent)`, down: `0 0 6px color-mix(in srgb, ${tokens.down} 20%, transparent)`, empty: "none", }; const barBg: Record = { up: tokens.up, + degraded: tokens.degraded, down: tokens.down, empty: tokens.border, }; diff --git a/client/src/Pages/StatusPage/Status/themes/editorial/styles.ts b/client/src/Pages/StatusPage/Status/themes/editorial/styles.ts index 868ebf186..9de2c96fb 100644 --- a/client/src/Pages/StatusPage/Status/themes/editorial/styles.ts +++ b/client/src/Pages/StatusPage/Status/themes/editorial/styles.ts @@ -8,8 +8,10 @@ import { } from "../shared/fontStacks"; import { MAX_RECENT_CHECKS } from "@/Types/Monitor"; -export type EditorialHeatCell = "fast" | "med" | "slow" | "down" | "empty"; -export type EditorialBarKind = "up" | "down" | "empty"; +import type { BarKind, HeatCellKind } from "../shared/ChartCells"; + +export type EditorialHeatCell = HeatCellKind; +export type EditorialBarKind = BarKind; export type EditorialGaugeFill = "ok" | "warm" | "hot"; export interface EditorialStyles { @@ -59,12 +61,14 @@ export const editorialStyles = ( fast: tokens.up, med: `color-mix(in srgb, ${tokens.up} 60%, ${tokens.bg})`, slow: tokens.warn, + degraded: tokens.degraded, down: tokens.down, empty: tokens.border, }; const barBg: Record = { up: tokens.up, + degraded: tokens.degraded, down: tokens.down, empty: tokens.border, }; diff --git a/client/src/Pages/StatusPage/Status/themes/modern/styles.ts b/client/src/Pages/StatusPage/Status/themes/modern/styles.ts index 2f730ee63..7bb108f51 100644 --- a/client/src/Pages/StatusPage/Status/themes/modern/styles.ts +++ b/client/src/Pages/StatusPage/Status/themes/modern/styles.ts @@ -5,8 +5,10 @@ import { type OverallTone, toneColor, toneSoft } from "../shared/overallStatus"; import { MONO_STACK, SANS_STACK } from "../shared/fontStacks"; import { MAX_RECENT_CHECKS } from "@/Types/Monitor"; -export type ModernHeatCell = "fast" | "med" | "slow" | "down" | "empty"; -export type ModernBarKind = "up" | "down" | "empty"; +import type { BarKind, HeatCellKind } from "../shared/ChartCells"; + +export type ModernHeatCell = HeatCellKind; +export type ModernBarKind = BarKind; export type ModernGaugeFill = "ok" | "warm" | "hot"; export interface ModernStyles { @@ -86,12 +88,14 @@ export const modernStyles = ( fast: `linear-gradient(180deg, ${tokens.up}, ${tokens.upStrong})`, med: `linear-gradient(180deg, color-mix(in srgb, ${tokens.up} 70%, #ffffff 30%), ${tokens.up})`, slow: `linear-gradient(180deg, ${tokens.warn}, ${tokens.degraded})`, + degraded: `linear-gradient(180deg, ${tokens.degraded}, color-mix(in srgb, ${tokens.degraded} 70%, #000000 30%))`, down: `linear-gradient(180deg, ${tokens.down}, color-mix(in srgb, ${tokens.down} 70%, #000000 30%))`, empty: tokens.border, }; const barBg: Record = { up: tokens.up, + degraded: tokens.degraded, down: tokens.down, empty: tokens.border, }; diff --git a/client/src/Pages/StatusPage/Status/themes/refined/styles.ts b/client/src/Pages/StatusPage/Status/themes/refined/styles.ts index 457b86ede..38f972c95 100644 --- a/client/src/Pages/StatusPage/Status/themes/refined/styles.ts +++ b/client/src/Pages/StatusPage/Status/themes/refined/styles.ts @@ -3,8 +3,10 @@ import type { StatusPageThemeTokens } from "../tokens"; import { type OverallTone, toneColor, toneSoft } from "../shared/overallStatus"; import { MONO_STACK, SANS_STACK } from "../shared/fontStacks"; -export type RefinedHeatCell = "fast" | "med" | "slow" | "down" | "empty"; -export type RefinedBarKind = "up" | "down" | "empty"; +import type { BarKind, HeatCellKind } from "../shared/ChartCells"; + +export type RefinedHeatCell = HeatCellKind; +export type RefinedBarKind = BarKind; export type RefinedGaugeFill = "ok" | "warm" | "hot"; import { MAX_RECENT_CHECKS } from "@/Types/Monitor"; @@ -71,12 +73,14 @@ export const refinedStyles = ( fast: tokens.up, med: `color-mix(in srgb, ${tokens.up} 60%, #ffffff 40%)`, slow: tokens.warn, + degraded: tokens.degraded, down: tokens.down, empty: tokens.border, }; const barBg: Record = { up: tokens.up, + degraded: tokens.degraded, down: tokens.down, empty: tokens.border, }; diff --git a/client/src/Pages/StatusPage/Status/themes/shared/BaseStatusPage.tsx b/client/src/Pages/StatusPage/Status/themes/shared/BaseStatusPage.tsx index 96beeb173..a522b302f 100644 --- a/client/src/Pages/StatusPage/Status/themes/shared/BaseStatusPage.tsx +++ b/client/src/Pages/StatusPage/Status/themes/shared/BaseStatusPage.tsx @@ -4,17 +4,15 @@ import Stack from "@mui/material/Stack"; import { useTranslation } from "react-i18next"; import type { SxProps, Theme } from "@mui/material/styles"; import type { Monitor } from "@/Types/Monitor"; -import type { StatusPage } from "@/Types/StatusPage"; -import { getMonitorTypeLabel } from "@/Types/StatusPage"; +import type { StatusPage, StatusPageRange } from "@/Types/StatusPage"; +import { + getMonitorTypeLabel, + STATUS_PAGE_RANGE_DAYS, + STATUS_PAGE_RANGES, +} from "@/Types/StatusPage"; import type { StatusPageThemeTokens } from "@/Pages/StatusPage/Status/themes/tokens"; -import { - ThemedHeatmap, - type HeatCellKind, -} from "@/Pages/StatusPage/Status/themes/shared/ThemedHeatmap"; -import { - ThemedHistogram, - type BarKind, -} from "@/Pages/StatusPage/Status/themes/shared/ThemedHistogram"; +import { ThemedHeatmap } from "@/Pages/StatusPage/Status/themes/shared/ThemedHeatmap"; +import { ThemedHistogram } from "@/Pages/StatusPage/Status/themes/shared/ThemedHistogram"; import { ThemedInfrastructure, type GaugeFillLevel, @@ -28,6 +26,12 @@ import { } from "@/Pages/StatusPage/Status/themes/shared/overallStatus"; import { useStatusPageTheme } from "@/Pages/StatusPage/Status/themes/StatusPageThemeProvider"; import { formatPercentage } from "@/Utils/FormatUtils"; +import { + checksToCells, + dailyBucketsToCells, + type BarKind, + type HeatCellKind, +} from "@/Pages/StatusPage/Status/themes/shared/ChartCells"; type StatusPageMonitor = Monitor; @@ -82,9 +86,19 @@ interface Props { statusPage: StatusPage; monitors: StatusPageMonitor[]; config: ThemeConfig; + range: StatusPageRange; + onRangeChange: (range: StatusPageRange) => void; + bucketTimezone: string; } -export const BaseStatusPage = ({ statusPage, monitors, config }: Props) => { +export const BaseStatusPage = ({ + statusPage, + monitors, + config, + range, + onRangeChange, + bucketTimezone, +}: Props) => { const { t } = useTranslation(); const { tokens, mode } = useStatusPageTheme(); const styles = useMemo( @@ -126,33 +140,56 @@ export const BaseStatusPage = ({ statusPage, monitors, config }: Props) => { /> {statusPage.showCharts && ( - - + + setChartMode("heatmap")} - sx={styles.chartSwitchButton(chartMode === "heatmap")} + sx={styles.chartSwitch} + role="radiogroup" > - {t("pages.statusPages.monitorsList.chartTypeHeatmap")} - - setChartMode("histogram")} - sx={styles.chartSwitchButton(chartMode === "histogram")} - > - {t("pages.statusPages.monitorsList.chartTypeHistogram")} + setChartMode("heatmap")} + sx={styles.chartSwitchButton(chartMode === "heatmap")} + > + {t("pages.statusPages.monitorsList.chartTypeHeatmap")} + + setChartMode("histogram")} + sx={styles.chartSwitchButton(chartMode === "histogram")} + > + {t("pages.statusPages.monitorsList.chartTypeHistogram")} + - + + + {STATUS_PAGE_RANGES.map((value) => ( + onRangeChange(value)} + sx={styles.chartSwitchButton(range === value)} + > + {t(`pages.statusPages.range.${value}`)} + + ))} + + + )} { const badgeTone = monitorBadgeTone(monitor.status); const uptimePercentage = formatPercentage(monitor.uptimePercentage ?? 0); + const cells = + range === "latest" + ? checksToCells(monitor.recentChecks ?? [], t) + : dailyBucketsToCells( + monitor.dailyChecks ?? [], + STATUS_PAGE_RANGE_DAYS[range], + bucketTimezone, + t + ); + return ( { {showChart && (chartMode === "heatmap" ? ( ) : ( ; cellSx: (kind: HeatCellKind) => SxProps; } -const classify = (check: CheckSnapshot): Exclude => { - if (!check.status) return "down"; - const rt = check.responseTime ?? 0; - if (rt > 500) return "slow"; - if (rt > 250) return "med"; - return "fast"; -}; - -export const ThemedHeatmap = ({ checks, containerSx, cellSx }: Props) => { +export const ThemedHeatmap = ({ cells, containerSx, cellSx }: Props) => { const { t } = useTranslation(); - const source = checks.slice(-CELLS); - const padded: (CheckSnapshot | null)[] = [ - ...source, - ...Array.from({ length: Math.max(0, CELLS - source.length) }, () => null), - ]; - return ( - {padded.map((check, i) => { - if (!check) { + {cells.map((cell) => { + if (cell.heatKind === "empty") { return ( ); } - const kind = classify(check); - const tooltipContent = ; return ( ); diff --git a/client/src/Pages/StatusPage/Status/themes/shared/ThemedHistogram.tsx b/client/src/Pages/StatusPage/Status/themes/shared/ThemedHistogram.tsx index a5c0b71f1..5fc1dcf33 100644 --- a/client/src/Pages/StatusPage/Status/themes/shared/ThemedHistogram.tsx +++ b/client/src/Pages/StatusPage/Status/themes/shared/ThemedHistogram.tsx @@ -5,17 +5,14 @@ import Stack from "@mui/material/Stack"; import type { SxProps, Theme } from "@mui/material/styles"; import { useTranslation } from "react-i18next"; import type { CheckSnapshot } from "@/Types/Check"; -import { MAX_RECENT_CHECKS } from "@/Types/Monitor"; -import { computeBarHeights } from "@/Utils/DataUtils"; import { formatMs } from "@/Utils/TimeUtils"; -import { ThemedChartTooltip } from "@/Pages/StatusPage/Status/themes/shared/ThemedChartTooltip"; -const CELLS = MAX_RECENT_CHECKS; -const MIN_HEIGHT_PCT = 6; - -export type BarKind = "up" | "down" | "empty"; +import type { + BarKind, + ChartCell, +} from "@/Pages/StatusPage/Status/themes/shared/ChartCells"; interface Props { - checks: CheckSnapshot[]; + cells: ChartCell[]; containerSx: SxProps; barSx: (kind: BarKind, heightPct: number) => SxProps; statsSx: SxProps; @@ -26,7 +23,7 @@ const tone = (check: CheckSnapshot): Exclude => check.status ? "up" : "down"; export const ThemedHistogram = ({ - checks, + cells, containerSx, barSx, statsSx, @@ -34,45 +31,42 @@ export const ThemedHistogram = ({ }: Props) => { const { t } = useTranslation(); - const { padded, heights, avg, peak } = useMemo(() => { - const source = checks.slice(-CELLS); - const out: (CheckSnapshot | null)[] = [ - ...source, - ...Array.from({ length: Math.max(0, CELLS - source.length) }, () => null), - ]; - const heights = computeBarHeights(source); - const valid = out.filter((c): c is CheckSnapshot => c !== null && c.responseTime > 0); - const maxRt = valid.length ? Math.max(...valid.map((c) => c.responseTime)) : 0; + const { avg, peak } = useMemo(() => { + const valid = cells.filter((cell) => cell.responseTime > 0); + const maxRt = valid.length ? Math.max(...valid.map((cell) => cell.responseTime)) : 0; const avgRt = valid.length - ? valid.reduce((s, c) => s + c.responseTime, 0) / valid.length + ? valid.reduce((sum, cell) => sum + cell.responseTime, 0) / valid.length : 0; - return { padded: out, heights, avg: formatMs(avgRt), peak: formatMs(maxRt) }; - }, [checks]); + return { avg: formatMs(avgRt), peak: formatMs(maxRt) }; + }, [cells]); return ( - - {padded.map((check, i) => { - if (!check) { + + {cells.map((cell) => { + if (cell.barKind === "empty") { return ( ); } - const height = heights[i] ?? MIN_HEIGHT_PCT; - const tooltipContent = ; return ( ); diff --git a/client/src/Types/Monitor.ts b/client/src/Types/Monitor.ts index ef328ebdb..6eaa280d7 100644 --- a/client/src/Types/Monitor.ts +++ b/client/src/Types/Monitor.ts @@ -1,4 +1,9 @@ -import type { GroupedCheck, CheckSnapshot, GroupedUptimeCheck } from "@/Types/Check"; +import type { + GroupedCheck, + CheckSnapshot, + GroupedUptimeCheck, + DailyCheckBucket, +} from "@/Types/Check"; import type { PageSpeedGroupedCheck } from "@/Types/Check"; import type { GeoContinent } from "@/Types/GeoCheck"; export type { GeoContinent } from "@/Types/GeoCheck"; @@ -149,6 +154,7 @@ export interface Monitor { dnsServer?: string; dnsRecordType?: DnsRecordType; recentChecks: CheckSnapshot[]; + dailyChecks?: DailyCheckBucket[]; createdAt: string; updatedAt: string; } diff --git a/client/src/Types/StatusPage.ts b/client/src/Types/StatusPage.ts index 89dd44782..a9adb9271 100644 --- a/client/src/Types/StatusPage.ts +++ b/client/src/Types/StatusPage.ts @@ -24,13 +24,16 @@ export const STATUS_PAGE_THEME_MODES = ["auto", "light", "dark"] as const; export type StatusPageThemeMode = (typeof STATUS_PAGE_THEME_MODES)[number]; export const DEFAULT_STATUS_PAGE_THEME_MODE: StatusPageThemeMode = "auto"; -export const STATUS_PAGE_RANGES = ["latest", "30d", "60d", "90d"] as const; +export const STATUS_PAGE_DAY_RANGES = ["30d", "60d", "90d"] as const; +export type StatusPageDayRange = (typeof STATUS_PAGE_DAY_RANGES)[number]; +export const STATUS_PAGE_RANGES = ["latest", ...STATUS_PAGE_DAY_RANGES] as const; export type StatusPageRange = (typeof STATUS_PAGE_RANGES)[number]; -export const STATUS_PAGE_RANGE_DAYS: Record< - Exclude, - number -> = { "30d": 30, "60d": 60, "90d": 90 }; +export const STATUS_PAGE_RANGE_DAYS: Record = { + "30d": 30, + "60d": 60, + "90d": 90, +}; export const isStatusPageRange = (value: string | null): value is StatusPageRange => STATUS_PAGE_RANGES.some((range) => range === value); @@ -78,4 +81,7 @@ export interface StatusPage { export interface StatusPageResponse { statusPage: StatusPage; monitors: Monitor[]; + range?: StatusPageDayRange; // present only when range !== "latest" + bucketTimezone?: string; + checkTTLDays?: number; } diff --git a/client/src/locales/en.json b/client/src/locales/en.json index c20fdc82f..669e1b479 100644 --- a/client/src/locales/en.json +++ b/client/src/locales/en.json @@ -1442,6 +1442,13 @@ }, "statusPages": { "deleteSuccess": "Status page deleted successfully", + "rangeSelectorAria": "History range", + "range": { + "latest": "Latest", + "30d": "30 days", + "60d": "60 days", + "90d": "90 days" + }, "fallback": { "title": "No status pages yet", "description": "Publish a public page that shows real-time uptime and incident history to your customers and stakeholders.",