status pages

This commit is contained in:
Alex Holliday committed 2026-01-03 20:32:16 +00:00
1 parent 602597abe2
commit e5ef14215f
14 files changed
+77 -60

No files matched your search

@@ -17,9 +17,7 @@ import { BaseBox } from "@/components/design-elements";
import { useAppSelector } from "@/hooks/AppHooks"; import { useAppSelector } from "@/hooks/AppHooks";
import { formatDateWithTz, tooltipDateFormatLookup } from "@/utils/TimeUtils"; import { formatDateWithTz, tooltipDateFormatLookup } from "@/utils/TimeUtils";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import type { GroupedCheck } from "@/types/check";
type Datum = Record<string, unknown> & { _id: string | number };
export const BarDockerCount = ({ export const BarDockerCount = ({
data, data,
dataKey, dataKey,
@@ -27,7 +25,7 @@ export const BarDockerCount = ({
title, title,
emptyText, emptyText,
}: { }: {
data: Datum[]; data: GroupedCheck[];
dataKey: string; dataKey: string;
range: string; range: string;
title: string; title: string;
@@ -48,7 +48,7 @@ export const HeaderControls = ({
loading={isPosting || isPatching} loading={isPosting || isPatching}
startIcon={<Mail size={20} strokeWidth={1.5} />} startIcon={<Mail size={20} strokeWidth={1.5} />}
onClick={async () => { onClick={async () => {
await post(`/monitors/${monitor._id}/notifications/test`, {}); await post(`/monitors/${monitor.id}/notifications/test`, {});
}} }}
> >
{t("common.buttons.testNotification")} {t("common.buttons.testNotification")}
@@ -57,7 +57,7 @@ export const HeaderControls = ({
<Button <Button
startIcon={<Bug size={20} strokeWidth={1.5} />} startIcon={<Bug size={20} strokeWidth={1.5} />}
onClick={() => { onClick={() => {
navigate(`/incidents?monitorId=${monitor._id}`); navigate(`/incidents?monitorId=${monitor.id}`);
}} }}
> >
{t("common.buttons.incidents")} {t("common.buttons.incidents")}
@@ -65,7 +65,7 @@ export const HeaderControls = ({
<Button <Button
loading={isPatching || isPosting} loading={isPatching || isPosting}
onClick={async () => { onClick={async () => {
await patch(`/monitors/${monitor._id}/active`); await patch(`/monitors/${monitor.id}/active`);
refetch(); refetch();
}} }}
startIcon={ startIcon={
@@ -83,7 +83,7 @@ export const HeaderControls = ({
<Button <Button
startIcon={<Settings size={20} strokeWidth={1.5} />} startIcon={<Settings size={20} strokeWidth={1.5} />}
onClick={() => { onClick={() => {
navigate(`${path}/${monitor._id}/configure`); navigate(`${path}/${monitor.id}/configure`);
}} }}
> >
{t("common.buttons.configure")} {t("common.buttons.configure")}
@@ -5,14 +5,10 @@ import Link from "@mui/material/Link";
import { config } from "@/config/index"; import { config } from "@/config/index";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import type { IStatusPageWithMonitors } from "@/types/status-page"; import type { IStatusPage } from "@/types/status-page";
const HOST = config.HOST; const HOST = config.HOST;
export const NameHeader = ({ export const NameHeader = ({ statusPage }: { statusPage: IStatusPage }) => {
statusPage,
}: {
statusPage: IStatusPageWithMonitors;
}) => {
const { t } = useTranslation(); const { t } = useTranslation();
return ( return (
<Stack direction={"row"} alignItems={"flex-end"} spacing={4}> <Stack direction={"row"} alignItems={"flex-end"} spacing={4}>
@@ -2,15 +2,11 @@ import Typography from "@mui/material/Typography";
import Stack from "@mui/material/Stack"; import Stack from "@mui/material/Stack";
import { getStatusPageHeaderConfig } from "@/utils/MonitorUtils"; import { getStatusPageHeaderConfig } from "@/utils/MonitorUtils";
import type { IStatusPageWithMonitors } from "@/types/status-page"; import type { IStatusPage } from "@/types/status-page";
import { useTheme } from "@mui/material/styles"; import { useTheme } from "@mui/material/styles";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
export const StatusHeader = ({ export const StatusHeader = ({ statusPage }: { statusPage: IStatusPage }) => {
statusPage,
}: {
statusPage: IStatusPageWithMonitors;
}) => {
const theme = useTheme(); const theme = useTheme();
const { t } = useTranslation(); const { t } = useTranslation();
const headerConfig = getStatusPageHeaderConfig(statusPage?.monitors || [], t); const headerConfig = getStatusPageHeaderConfig(statusPage?.monitors || [], t);
@@ -8,7 +8,9 @@ import { useTheme } from "@mui/material/styles";
import { useAppSelector } from "@/hooks/AppHooks"; import { useAppSelector } from "@/hooks/AppHooks";
import type { IMonitor } from "@/types/monitor"; import type { IMonitor } from "@/types/monitor";
export const StatusPageRow = ({ monitor }: { monitor: IMonitor }) => { type Props = { monitor: IMonitor; checks: any[] };
export const StatusPageRow = ({ monitor, checks }: Props) => {
const theme = useTheme(); const theme = useTheme();
const type = useAppSelector((state) => state?.ui?.chartType || "heatmap"); const type = useAppSelector((state) => state?.ui?.chartType || "heatmap");
@@ -32,7 +34,7 @@ export const StatusPageRow = ({ monitor }: { monitor: IMonitor }) => {
{type === "heatmap" && ( {type === "heatmap" && (
<HeatmapResponseTime <HeatmapResponseTime
gap={{ xs: theme.spacing(0.5), md: theme.spacing(2) }} gap={{ xs: theme.spacing(0.5), md: theme.spacing(2) }}
checks={monitor?.latestChecks ?? []} checks={checks ?? []}
availabilityCellSx={{ availabilityCellSx={{
borderRadius: { borderRadius: {
xs: theme.spacing(0.5), xs: theme.spacing(0.5),
@@ -49,7 +51,7 @@ export const StatusPageRow = ({ monitor }: { monitor: IMonitor }) => {
)} )}
{type === "histogram" && ( {type === "histogram" && (
<HistogramResponseTime <HistogramResponseTime
checks={monitor?.latestChecks ?? []} checks={checks ?? []}
height={{ xs: 50, md: 100 }} height={{ xs: 50, md: 100 }}
gap={{ xs: 0.5, md: theme.spacing(4) }} gap={{ xs: 0.5, md: theme.spacing(4) }}
/> />
+1 -1
View File
@@ -73,7 +73,7 @@ const ChecksPage = () => {
> >
<MenuItem value="all">All monitors</MenuItem> <MenuItem value="all">All monitors</MenuItem>
{monitors.map((monitor) => ( {monitors.map((monitor) => (
<MenuItem key={monitor._id} value={monitor._id}> <MenuItem key={monitor.id} value={monitor.id}>
{monitor.name} {monitor.name}
</MenuItem> </MenuItem>
))} ))}
+5 -2
View File
@@ -38,8 +38,11 @@ const DockerDetailsPage = () => {
const monitor = response?.data?.monitor; const monitor = response?.data?.monitor;
const stats = response?.data?.stats; const stats = response?.data?.stats;
const checks = (response?.data?.checks || []) as any; const checks = response?.data?.checks || [];
const snapshot = monitor?.latestChecks?.[0]?.dockerContainers ?? []; // TODO snapshot no longer added to checks
const latestBucket =
Array.isArray(checks) && checks.length > 0 ? checks[0] : null;
const snapshot = latestBucket?.runningContainersSnapshot ?? [];
const palette = getStatusPalette(monitor?.status || "initializing"); const palette = getStatusPalette(monitor?.status || "initializing");
const streakDuration = stats?.currentStreakStartedAt const streakDuration = stats?.currentStreakStartedAt
+1 -1
View File
@@ -93,7 +93,7 @@ const IncidentsPage = () => {
> >
<MenuItem value="all">All monitors</MenuItem> <MenuItem value="all">All monitors</MenuItem>
{monitors.map((monitor) => ( {monitors.map((monitor) => (
<MenuItem key={monitor._id} value={monitor._id}> <MenuItem key={monitor.id} value={monitor.id}>
{monitor.name} {monitor.name}
</MenuItem> </MenuItem>
))} ))}
@@ -5,24 +5,27 @@ import { useNavigate } from "react-router";
import { usePatch, useGet } from "@/hooks/UseApi"; import { usePatch, useGet } from "@/hooks/UseApi";
import type { ApiResponse } from "@/types/api"; import type { ApiResponse } from "@/types/api";
import type { IMonitor } from "@/types/monitor"; import type { IMonitor } from "@/types/monitor";
import type { IStatusPageWithMonitors } from "@/types/status-page"; import type {
IStatusPage,
IStatusPageWithChecksMap,
} from "@/types/status-page";
import type { FormValues } from "@/pages/status-page/StatusPageForm"; import type { FormValues } from "@/pages/status-page/StatusPageForm";
const StatusPageConfigPage = () => { const StatusPageConfigPage = () => {
const navigate = useNavigate(); const navigate = useNavigate();
const { id } = useParams(); const { id } = useParams();
const { patch, loading } = usePatch<FormValues, IStatusPageWithMonitors>(); const { patch, loading } = usePatch<FormValues, IStatusPage>();
const { response, isValidating } = const { response, isValidating } =
useGet<ApiResponse<IMonitor[]>>("/monitors"); useGet<ApiResponse<IMonitor[]>>("/monitors");
const { response: statusPageResponse } = useGet<ApiResponse<any>>( const { response: statusPageResponse } = useGet<
`/status-pages/${id}` ApiResponse<IStatusPageWithChecksMap>
); >(`/status-pages/${id}`);
const monitors = response?.data || []; const monitors = response?.data || [];
const initialData = statusPageResponse?.data || {}; const initialData: any = statusPageResponse?.data?.statusPage || {};
initialData.monitors = initialData.monitors =
initialData?.monitors?.map((monitor: IMonitor) => monitor?._id) || []; initialData?.monitors?.map((monitor: any) => monitor?._id) || [];
const onSubmit = async (data: FormValues) => { const onSubmit = async (data: FormValues) => {
const res = await patch(`/status-pages/${id}`, data); const res = await patch(`/status-pages/${id}`, data);
@@ -4,11 +4,10 @@ import { StatusPageRow } from "@/components/status-pages/StatusPageRow";
import { BasePage } from "@/components/design-elements"; import { BasePage } from "@/components/design-elements";
import { useTheme } from "@mui/material/styles"; import { useTheme } from "@mui/material/styles";
import type { IMonitor } from "@/types/monitor";
import { useGet } from "@/hooks/UseApi"; import { useGet } from "@/hooks/UseApi";
import type { ApiResponse } from "@/types/api"; import type { ApiResponse } from "@/types/api";
import { useParams } from "react-router"; import { useParams } from "react-router";
import type { IStatusPageWithMonitors } from "@/types/status-page"; import type { IStatusPageWithChecksMap } from "@/types/status-page";
import { NameHeader } from "@/components/status-pages/NameHeader"; import { NameHeader } from "@/components/status-pages/NameHeader";
import { config } from "@/config/index"; import { config } from "@/config/index";
@@ -16,13 +15,14 @@ const GLOBAL_REFRESH = config.GLOBAL_REFRESH;
const StatusPages = () => { const StatusPages = () => {
const theme = useTheme(); const theme = useTheme();
const { id } = useParams(); const { id } = useParams();
const { response, loading } = useGet<ApiResponse<IStatusPageWithMonitors>>( const { response, loading } = useGet<ApiResponse<IStatusPageWithChecksMap>>(
`/status-pages/${id}`, `/status-pages/${id}`,
{}, {},
{ refreshInterval: GLOBAL_REFRESH, keepPreviousData: true } { refreshInterval: GLOBAL_REFRESH, keepPreviousData: true }
); );
const statusPage = response?.data; const statusPage = response?.data?.statusPage;
const monitors: IMonitor[] = statusPage?.monitors || []; const monitors = statusPage?.monitors || [];
const checksMap: Record<string, any[]> = response?.data?.checksMap || {};
if (!statusPage) { if (!statusPage) {
return null; return null;
@@ -33,8 +33,15 @@ const StatusPages = () => {
<Stack minWidth={"66vw"} spacing={theme.spacing(8)}> <Stack minWidth={"66vw"} spacing={theme.spacing(8)}>
<NameHeader statusPage={statusPage} /> <NameHeader statusPage={statusPage} />
<StatusHeader statusPage={statusPage} /> <StatusHeader statusPage={statusPage} />
{monitors?.map((monitor: IMonitor) => { {monitors?.map((monitor: any) => {
return <StatusPageRow key={monitor?._id} monitor={monitor} />; const checks = checksMap?.[monitor?._id as any] || [];
return (
<StatusPageRow
key={monitor?._id}
monitor={monitor}
checks={checks}
/>
);
})} })}
</Stack> </Stack>
</BasePage> </BasePage>
@@ -160,17 +160,17 @@ export const StatusPageForm = ({
options={monitorOptions} options={monitorOptions}
getOptionLabel={(option) => option.name} getOptionLabel={(option) => option.name}
value={monitorOptions.filter((o: any) => value={monitorOptions.filter((o: any) =>
(field.value || []).includes(o._id) (field.value || []).includes(o.id)
)} )}
onChange={(_, newValue) => { onChange={(_, newValue) => {
field.onChange(newValue.map((o: any) => o._id)); field.onChange(newValue.map((o: any) => o.id));
}} }}
/> />
)} )}
/> />
<Stack gap={theme.spacing(2)} mt={theme.spacing(2)}> <Stack gap={theme.spacing(2)} mt={theme.spacing(2)}>
{monitors.map((monitorId) => { {monitors.map((monitorId) => {
const option = monitorOptions.find((o) => o._id === monitorId); const option = monitorOptions.find((o) => o.id === monitorId);
if (!option) return null; if (!option) return null;
return ( return (
<Stack <Stack
@@ -4,11 +4,10 @@ import { StatusPageRow } from "@/components/status-pages/StatusPageRow";
import { BasePage } from "@/components/design-elements"; import { BasePage } from "@/components/design-elements";
import { useTheme } from "@mui/material/styles"; import { useTheme } from "@mui/material/styles";
import type { IMonitor } from "@/types/monitor";
import { useGet } from "@/hooks/UseApi"; import { useGet } from "@/hooks/UseApi";
import type { ApiResponse } from "@/types/api"; import type { ApiResponse } from "@/types/api";
import { useParams } from "react-router"; import { useParams } from "react-router";
import type { IStatusPageWithMonitors } from "@/types/status-page"; import type { IStatusPageWithChecksMap } from "@/types/status-page";
import { NameHeader } from "@/components/status-pages/NameHeader"; import { NameHeader } from "@/components/status-pages/NameHeader";
import { config } from "@/config/index"; import { config } from "@/config/index";
@@ -16,13 +15,14 @@ const GLOBAL_REFRESH = config.GLOBAL_REFRESH;
const StatusPages = () => { const StatusPages = () => {
const theme = useTheme(); const theme = useTheme();
const { url } = useParams(); const { url } = useParams();
const { response } = useGet<ApiResponse<IStatusPageWithMonitors>>( const { response } = useGet<ApiResponse<IStatusPageWithChecksMap>>(
`/status-pages/public/${url}`, `/status-pages/public/${url}`,
{}, {},
{ refreshInterval: GLOBAL_REFRESH, keepPreviousData: true } { refreshInterval: GLOBAL_REFRESH, keepPreviousData: true }
); );
const statusPage = response?.data; const statusPage = response?.data?.statusPage;
const monitors: IMonitor[] = statusPage?.monitors || []; const monitors = statusPage?.monitors || [];
const checksMap: Record<string, any[]> = response?.data?.checksMap || {};
if (!statusPage) { if (!statusPage) {
return null; return null;
@@ -33,8 +33,16 @@ const StatusPages = () => {
<Stack minWidth={"66vw"} spacing={theme.spacing(8)}> <Stack minWidth={"66vw"} spacing={theme.spacing(8)}>
<NameHeader statusPage={statusPage} /> <NameHeader statusPage={statusPage} />
<StatusHeader statusPage={statusPage} /> <StatusHeader statusPage={statusPage} />
{monitors?.map((monitor: IMonitor) => { {monitors?.map((monitor: any) => {
return <StatusPageRow key={monitor?._id} monitor={monitor} />; const checks = checksMap?.[monitor?._id as any] || [];
return (
<StatusPageRow
key={monitor?.id}
monitor={monitor}
checks={checks}
/>
);
})} })}
</Stack> </Stack>
</BasePage> </BasePage>
+1
View File
@@ -155,6 +155,7 @@ export interface GroupedCheck {
downChecks?: number; downChecks?: number;
avgResponseTimeUp?: number | null; avgResponseTimeUp?: number | null;
avgResponseTimeDown?: number | null; avgResponseTimeDown?: number | null;
runningContainersSnapshot?: IDockerContainerSummary[];
} }
export interface LatestCheck { export interface LatestCheck {
+12 -9
View File
@@ -1,15 +1,6 @@
import type { IMonitor } from "@/types/monitor"; import type { IMonitor } from "@/types/monitor";
export interface IStatusPage { export interface IStatusPage {
_id: string;
name: string;
description: string;
url: string;
isPublished: boolean;
monitors: string[];
}
export interface IStatusPageWithMonitors {
_id: string; _id: string;
name: string; name: string;
description: string; description: string;
@@ -17,3 +8,15 @@ export interface IStatusPageWithMonitors {
isPublished: boolean; isPublished: boolean;
monitors: IMonitor[]; monitors: IMonitor[];
} }
export interface IStatusPageWithChecksMap {
statusPage: {
_id: string;
name: string;
description: string;
url: string;
isPublished: boolean;
monitors: IMonitor[];
};
checksMap: Record<string, any[]>;
}