cards
This commit is contained in:
1 parent
04bd7f0e2e
commit
b7a6d50c73
8 files changed
+462
-2
No files matched your search
@@ -0,0 +1,104 @@
|
||||
import Stack from "@mui/material/Stack";
|
||||
import Box from "@mui/material/Box";
|
||||
import Divider from "@mui/material/Divider";
|
||||
import Grid from "@mui/material/Grid2";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import { ValueLabel } from "@/Components/v2/design-elements";
|
||||
import { Globe } from "lucide-react";
|
||||
|
||||
import type { Incident } from "@/Types/Incident";
|
||||
import type { Monitor } from "@/Types/Monitor";
|
||||
import { useTheme } from "@mui/material";
|
||||
import { getIncidentsDuration } from "@/Pages/Incidents/utils";
|
||||
|
||||
export const IncidentItem = ({
|
||||
incident,
|
||||
monitor,
|
||||
}: {
|
||||
incident: Incident;
|
||||
monitor?: Monitor | null;
|
||||
}) => {
|
||||
const theme = useTheme();
|
||||
const duration = getIncidentsDuration(incident);
|
||||
return (
|
||||
<Grid
|
||||
container
|
||||
alignItems="center"
|
||||
spacing={2}
|
||||
sx={{
|
||||
width: "100%",
|
||||
py: theme.spacing(0.5),
|
||||
}}
|
||||
>
|
||||
<Grid
|
||||
size={{ xs: 12, lg: 5 }}
|
||||
sx={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "flex-start",
|
||||
gap: theme.spacing(2),
|
||||
}}
|
||||
>
|
||||
<Globe />
|
||||
<Typography
|
||||
variant="body1"
|
||||
fontWeight={500}
|
||||
noWrap
|
||||
>
|
||||
{monitor ? monitor.name : "N/A"}
|
||||
</Typography>
|
||||
</Grid>
|
||||
|
||||
<Grid
|
||||
size={{ xs: 12, md: 6, lg: 3 }}
|
||||
sx={{
|
||||
display: "flex",
|
||||
}}
|
||||
>
|
||||
<ValueLabel
|
||||
value={incident.status ? "negative" : "positive"}
|
||||
text={incident.status ? "Active" : "Resolved"}
|
||||
/>
|
||||
</Grid>
|
||||
|
||||
<Grid
|
||||
size={{ xs: 12, md: 6, lg: 4 }}
|
||||
sx={{
|
||||
textAlign: { xs: "left", md: "right" },
|
||||
fontWeight: 500,
|
||||
}}
|
||||
>
|
||||
<Typography variant="body1">{duration}</Typography>
|
||||
</Grid>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
|
||||
interface SummaryItemProps {
|
||||
icon: React.ReactNode;
|
||||
label: string;
|
||||
value: string | number;
|
||||
}
|
||||
|
||||
export const SummaryItem = ({ icon, label, value }: SummaryItemProps) => {
|
||||
const theme = useTheme();
|
||||
return (
|
||||
<Box>
|
||||
<Stack
|
||||
direction="row"
|
||||
alignItems="center"
|
||||
gap={theme.spacing(2)}
|
||||
py={theme.spacing(0.5)}
|
||||
>
|
||||
{icon}
|
||||
<Typography
|
||||
variant="body1"
|
||||
fontWeight={500}
|
||||
>
|
||||
{label}: {value}
|
||||
</Typography>
|
||||
</Stack>
|
||||
<Divider sx={{ mt: theme.spacing(2) }} />
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
Whitespace-only changes.
@@ -0,0 +1,141 @@
|
||||
import Stack from "@mui/material/Stack";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import Divider from "@mui/material/Divider";
|
||||
import { BaseBox } from "@/Components/v2/design-elements";
|
||||
import { CircleCheck, TriangleAlert, Bell, Wrench } from "lucide-react";
|
||||
import Box from "@mui/material/Box";
|
||||
import { IncidentItem, SummaryItem } from "@/Pages/Incidents/Components/IncidentItem";
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useTheme } from "@mui/material";
|
||||
import type { Incident, IncidentSummary } from "@/Types/Incident";
|
||||
import type { Monitor } from "@/Types/Monitor";
|
||||
|
||||
interface SummaryCardProps {
|
||||
title: string;
|
||||
sx?: React.CSSProperties;
|
||||
}
|
||||
|
||||
const SummaryCard = ({
|
||||
title,
|
||||
sx,
|
||||
children,
|
||||
}: React.PropsWithChildren<SummaryCardProps>) => {
|
||||
const theme = useTheme();
|
||||
return (
|
||||
<BaseBox
|
||||
sx={{ ...sx }}
|
||||
padding={8}
|
||||
flex={1}
|
||||
>
|
||||
<Stack gap={theme.spacing(4)}>
|
||||
<Typography
|
||||
component="h2"
|
||||
sx={{
|
||||
textTransform: "uppercase",
|
||||
fontWeight: 500,
|
||||
fontSize: 13,
|
||||
}}
|
||||
>
|
||||
{title}
|
||||
</Typography>
|
||||
<Divider />
|
||||
{children}
|
||||
</Stack>
|
||||
</BaseBox>
|
||||
);
|
||||
};
|
||||
|
||||
interface SummaryCardIncidentsProps {
|
||||
incidents?: Incident[];
|
||||
monitors?: Monitor[] | null;
|
||||
}
|
||||
|
||||
export const SummaryCardActiveIncidents = ({ incidents }: SummaryCardIncidentsProps) => {
|
||||
const { t } = useTranslation();
|
||||
const theme = useTheme();
|
||||
|
||||
if (!incidents) return null;
|
||||
|
||||
const hasActive = incidents.some((incident) => incident.status === true);
|
||||
const activeCount = hasActive
|
||||
? incidents.filter((incident) => incident.status === true).length
|
||||
: 0;
|
||||
const color = hasActive ? theme.palette.error.main : theme.palette.success.main;
|
||||
const icon = hasActive ? (
|
||||
<TriangleAlert color={color} />
|
||||
) : (
|
||||
<CircleCheck color={color} />
|
||||
);
|
||||
const msg = hasActive
|
||||
? `${activeCount} ${t("pages.incidents.summaryCard.activeIncidents.active")}`
|
||||
: t("pages.incidents.summaryCard.activeIncidents.noActive");
|
||||
|
||||
return (
|
||||
<SummaryCard title={t("pages.incidents.summaryCard.activeIncidents.title")}>
|
||||
<Stack
|
||||
alignItems="center"
|
||||
justifyContent="center"
|
||||
gap={theme.spacing(4)}
|
||||
>
|
||||
{icon}
|
||||
<Typography>{msg}</Typography>
|
||||
</Stack>
|
||||
</SummaryCard>
|
||||
);
|
||||
};
|
||||
|
||||
export const SummaryCardLatestIncidents = ({
|
||||
incidents,
|
||||
monitors,
|
||||
}: SummaryCardIncidentsProps) => {
|
||||
const { t } = useTranslation();
|
||||
const theme = useTheme();
|
||||
return (
|
||||
<SummaryCard title={t("pages.incidents.summaryCard.latestIncidents.title")}>
|
||||
<Stack gap={theme.spacing(4)}>
|
||||
{incidents?.slice(0, 3).map((incident, index) => (
|
||||
<Box key={incident.id}>
|
||||
<IncidentItem
|
||||
incident={incident}
|
||||
monitor={monitors?.find((m) => m.id === incident.monitorId)}
|
||||
/>
|
||||
{index < incidents.length - 1 && <Divider sx={{ mt: theme.spacing(2) }} />}
|
||||
</Box>
|
||||
))}
|
||||
</Stack>
|
||||
</SummaryCard>
|
||||
);
|
||||
};
|
||||
|
||||
interface SummaryCardStatsProps {
|
||||
summary?: IncidentSummary;
|
||||
}
|
||||
|
||||
export const SummaryCardStats = ({ summary }: SummaryCardStatsProps) => {
|
||||
const { t } = useTranslation();
|
||||
if (!summary) return null;
|
||||
const mostAffected =
|
||||
!summary.total || summary.total === 0
|
||||
? "N/A"
|
||||
: summary.topMonitor?.monitorName || t("N/A");
|
||||
return (
|
||||
<SummaryCard title={t("pages.incidents.summaryCard.incidentStats.title")}>
|
||||
<SummaryItem
|
||||
icon={<Bell size={18} />}
|
||||
label="Total incidents"
|
||||
value={summary?.total || 0}
|
||||
/>
|
||||
<SummaryItem
|
||||
icon={<TriangleAlert size={18} />}
|
||||
label="Most affected monitor"
|
||||
value={mostAffected}
|
||||
/>
|
||||
<SummaryItem
|
||||
icon={<Wrench size={18} />}
|
||||
label="Average resolution time"
|
||||
value={summary.total > 0 ? `${summary.avgResolutionTimeHours || 0} hours` : "N/A"}
|
||||
/>
|
||||
</SummaryCard>
|
||||
);
|
||||
};
|
||||
@@ -1,7 +1,131 @@
|
||||
import { BasePage } from "@/Components/v2/design-elements";
|
||||
import Stack from "@mui/material/Stack";
|
||||
import {
|
||||
SummaryCardActiveIncidents,
|
||||
SummaryCardLatestIncidents,
|
||||
SummaryCardStats,
|
||||
} from "@/Pages/Incidents/Components/SummaryCard";
|
||||
|
||||
import { useGet } from "@/Hooks/UseApi";
|
||||
import { useState, useEffect, useMemo } from "react";
|
||||
import { useParams } from "react-router-dom";
|
||||
import type { IncidentsResponse, IncidentSummary } from "@/Types/Incident";
|
||||
import type { Monitor } from "@/Types/Monitor";
|
||||
import { useTheme } from "@mui/material";
|
||||
|
||||
interface MonitorLookup {
|
||||
[key: string]: { id: string; name: string; type: string };
|
||||
}
|
||||
|
||||
const IncidentsPage = () => {
|
||||
return <BasePage>Incidents Page</BasePage>;
|
||||
const theme = useTheme();
|
||||
const { monitorId } = useParams();
|
||||
|
||||
// Filter state
|
||||
const [selectedMonitor, setSelectedMonitor] = useState(monitorId || "0");
|
||||
const [filter, setFilter] = useState("all");
|
||||
const [dateRange, setDateRange] = useState("all");
|
||||
const [page, setPage] = useState(0);
|
||||
const [rowsPerPage, setRowsPerPage] = useState(10);
|
||||
|
||||
// Build incidents URL with query params
|
||||
const incidentsUrl = useMemo(() => {
|
||||
const params = new URLSearchParams();
|
||||
if (selectedMonitor !== "0") params.append("monitorId", selectedMonitor);
|
||||
if (filter === "active") params.append("status", "true");
|
||||
else if (filter === "resolved") params.append("status", "false");
|
||||
else if (filter === "manual" || filter === "automatic")
|
||||
params.append("resolutionType", filter);
|
||||
params.append("sortOrder", "desc");
|
||||
if (dateRange !== "all") params.append("dateRange", dateRange);
|
||||
params.append("page", String(page));
|
||||
params.append("rowsPerPage", String(rowsPerPage));
|
||||
return `/incidents/team?${params.toString()}`;
|
||||
}, [selectedMonitor, filter, dateRange, page, rowsPerPage]);
|
||||
|
||||
// Fetch incidents
|
||||
const {
|
||||
data: incidentsData,
|
||||
isLoading: isLoadingIncidents,
|
||||
error: incidentsError,
|
||||
refetch: refetchIncidents,
|
||||
} = useGet<IncidentsResponse>(incidentsUrl);
|
||||
|
||||
// Fetch monitors for lookup
|
||||
const {
|
||||
data: monitorsData,
|
||||
isLoading: isLoadingMonitors,
|
||||
error: monitorsError,
|
||||
} = useGet<Monitor[]>("/monitors/team");
|
||||
|
||||
// Fetch incident summary
|
||||
const {
|
||||
data: summaryData,
|
||||
isLoading: isLoadingSummary,
|
||||
error: summaryError,
|
||||
refetch: refetchSummary,
|
||||
} = useGet<IncidentSummary>("/incidents/team/summary");
|
||||
|
||||
// Build monitor lookup
|
||||
const monitorLookup = useMemo<MonitorLookup | undefined>(() => {
|
||||
if (!monitorsData) return undefined;
|
||||
return monitorsData.reduce<MonitorLookup>((acc, monitor) => {
|
||||
acc[monitor.id] = {
|
||||
id: monitor.id,
|
||||
name: monitor.name,
|
||||
type: monitor.type,
|
||||
};
|
||||
return acc;
|
||||
}, {});
|
||||
}, [monitorsData]);
|
||||
|
||||
// Reset page when filters change
|
||||
useEffect(() => {
|
||||
setPage(0);
|
||||
}, [selectedMonitor, filter, dateRange]);
|
||||
|
||||
// Derived state
|
||||
const incidents = incidentsData?.incidents ?? [];
|
||||
const incidentsCount = incidentsData?.count ?? 0;
|
||||
const networkError = !!incidentsError || !!monitorsError || !!summaryError;
|
||||
|
||||
// Expose state and handlers for future UI use
|
||||
void selectedMonitor;
|
||||
void setSelectedMonitor;
|
||||
void filter;
|
||||
void setFilter;
|
||||
void dateRange;
|
||||
void setDateRange;
|
||||
void page;
|
||||
void setPage;
|
||||
void rowsPerPage;
|
||||
void setRowsPerPage;
|
||||
void isLoadingIncidents;
|
||||
void isLoadingMonitors;
|
||||
void isLoadingSummary;
|
||||
void refetchIncidents;
|
||||
void refetchSummary;
|
||||
void monitorLookup;
|
||||
void incidents;
|
||||
void incidentsCount;
|
||||
void summaryData;
|
||||
void networkError;
|
||||
|
||||
return (
|
||||
<BasePage>
|
||||
<Stack
|
||||
direction={{ xs: "column", md: "row" }}
|
||||
gap={theme.spacing(8)}
|
||||
>
|
||||
<SummaryCardActiveIncidents incidents={incidents} />
|
||||
<SummaryCardLatestIncidents
|
||||
incidents={incidents}
|
||||
monitors={monitorsData}
|
||||
/>
|
||||
<SummaryCardStats summary={summaryData} />
|
||||
</Stack>
|
||||
</BasePage>
|
||||
);
|
||||
};
|
||||
|
||||
export default IncidentsPage;
|
||||
@@ -0,0 +1,25 @@
|
||||
import type { Incident } from "@/Types/Incident";
|
||||
import { getHumanReadableDuration } from "@/Utils/timeUtilsLegacy.js";
|
||||
export const getIncidentsDuration = (incident: Incident) => {
|
||||
if (!incident?.startTime) {
|
||||
return "-";
|
||||
}
|
||||
const startTime = new Date(incident?.startTime);
|
||||
const endTime = incident.status
|
||||
? new Date()
|
||||
: incident?.endTime
|
||||
? new Date(incident.endTime)
|
||||
: null;
|
||||
|
||||
if (!endTime) {
|
||||
return "-";
|
||||
}
|
||||
|
||||
const durationMs = endTime.getTime() - startTime.getTime();
|
||||
|
||||
if (durationMs < 0) {
|
||||
return "-";
|
||||
}
|
||||
|
||||
return getHumanReadableDuration(durationMs);
|
||||
};
|
||||
@@ -216,7 +216,13 @@ const Routes = () => {
|
||||
/>
|
||||
<Route
|
||||
path="incidents/:monitorId?"
|
||||
element={<Incidents />}
|
||||
element={
|
||||
<>
|
||||
<ThemeProvider theme={v2theme}>
|
||||
<Incidents />
|
||||
</ThemeProvider>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
|
||||
<Route
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
export interface Incident {
|
||||
id: string;
|
||||
monitorId: string;
|
||||
teamId: string;
|
||||
startTime: string;
|
||||
endTime: string | null;
|
||||
status: boolean;
|
||||
message?: string | null;
|
||||
statusCode?: number | null;
|
||||
resolutionType: "automatic" | "manual" | null;
|
||||
resolvedBy?: string | null;
|
||||
comment?: string | null;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface IncidentsResponse {
|
||||
incidents: Incident[];
|
||||
count: number;
|
||||
}
|
||||
|
||||
export interface IncidentSummaryTopMonitor {
|
||||
monitorId: string;
|
||||
monitorName: string | null;
|
||||
incidentCount: number;
|
||||
}
|
||||
|
||||
export interface IncidentSummaryItem {
|
||||
id: string;
|
||||
monitorId: string;
|
||||
monitorName: string | null;
|
||||
status: boolean;
|
||||
startTime: string;
|
||||
endTime: string | null;
|
||||
resolutionType: "automatic" | "manual" | null;
|
||||
message: string | null;
|
||||
statusCode: number | null;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface IncidentSummary {
|
||||
total: number;
|
||||
totalActive: number;
|
||||
totalManualResolutions: number;
|
||||
totalAutomaticResolutions: number;
|
||||
avgResolutionTimeHours: number;
|
||||
topMonitor: IncidentSummaryTopMonitor | null;
|
||||
latestIncidents: IncidentSummaryItem[];
|
||||
}
|
||||
@@ -350,6 +350,17 @@
|
||||
"title": "Matrix configuration"
|
||||
}
|
||||
}
|
||||
},
|
||||
"incidents": {
|
||||
"summaryCard": {
|
||||
"activeIncidents": {
|
||||
"title": "Active Incidents",
|
||||
"noActive": "No active incidents",
|
||||
"active": "Active incident(s)"
|
||||
},
|
||||
"latestIncidents": { "title": "Latest Incidents" },
|
||||
"incidentStats": { "title": "Incident Statistics" }
|
||||
}
|
||||
}
|
||||
},
|
||||
"incidentsTableNoIncidents": "No incidents recorded",
|
||||
|
||||
Reference in new issue
Block a user