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