Files
Checkmate/client/src/Pages/Incidents/Components/CardSummary.tsx
T

206 lines
4.8 KiB
TypeScript
Raw Normal View History

2026-01-30 23:16:35 +00:00
import Stack from "@mui/material/Stack";
import Typography from "@mui/material/Typography";
import Divider from "@mui/material/Divider";
2026-02-02 17:28:22 +00:00
import Grid from "@mui/material/Grid";
import { BaseBox, ValueLabel } from "@/Components/v2/design-elements";
import { CircleCheck, TriangleAlert, Bell, Wrench, Globe } from "lucide-react";
2026-01-30 23:16:35 +00:00
import Box from "@mui/material/Box";
2026-02-02 17:28:22 +00:00
import { SummaryItem } from "@/Pages/Incidents/Components/IncidentItem";
2026-01-30 23:16:35 +00:00
import { useTranslation } from "react-i18next";
import { useTheme } from "@mui/material";
2026-02-02 17:28:22 +00:00
import type { IncidentSummary, IncidentSummaryItem } from "@/Types/Incident";
import { getIncidentsDuration } from "@/Pages/Incidents/utils";
2026-01-30 23:16:35 +00:00
interface SummaryCardProps {
title: string;
sx?: React.CSSProperties;
}
2026-02-02 17:28:22 +00:00
export const SummaryCard = ({
2026-01-30 23:16:35 +00:00
title,
sx,
children,
}: React.PropsWithChildren<SummaryCardProps>) => {
const theme = useTheme();
return (
<BaseBox
sx={{ ...sx }}
padding={8}
flex={1}
>
2026-01-30 23:28:36 +00:00
<Stack
gap={theme.spacing(4)}
height="100%"
>
2026-01-30 23:16:35 +00:00
<Typography
component="h2"
sx={{
textTransform: "uppercase",
fontWeight: 500,
fontSize: 13,
}}
>
{title}
</Typography>
<Divider />
{children}
</Stack>
</BaseBox>
);
};
2026-02-02 17:28:22 +00:00
interface SummaryCardActiveIncidentsProps {
summary?: IncidentSummary | null;
2026-01-30 23:16:35 +00:00
}
2026-02-02 17:28:22 +00:00
export const SummaryCardActiveIncidents = ({ summary }: SummaryCardActiveIncidentsProps) => {
2026-01-30 23:16:35 +00:00
const { t } = useTranslation();
const theme = useTheme();
2026-02-02 17:28:22 +00:00
if (!summary) return null;
2026-01-30 23:16:35 +00:00
2026-02-02 17:28:22 +00:00
const activeCount = summary.totalActive;
2026-01-30 23:22:56 +00:00
const hasActive = activeCount > 0;
2026-01-30 23:16:35 +00:00
const color = hasActive ? theme.palette.error.main : theme.palette.success.main;
const icon = hasActive ? (
<TriangleAlert color={color} />
) : (
<CircleCheck color={color} />
);
2026-01-30 23:28:36 +00:00
const msg = t("pages.incidents.summaryCard.activeIncidents.active", {
count: activeCount,
});
2026-01-30 23:16:35 +00:00
return (
2026-01-30 23:28:36 +00:00
<SummaryCard
title={t("pages.incidents.summaryCard.activeIncidents.title")}
sx={{ height: "100%" }}
>
2026-01-30 23:16:35 +00:00
<Stack
2026-01-30 23:28:36 +00:00
flex={1}
2026-01-30 23:16:35 +00:00
alignItems="center"
justifyContent="center"
gap={theme.spacing(4)}
>
{icon}
<Typography>{msg}</Typography>
</Stack>
</SummaryCard>
);
};
2026-02-02 17:28:22 +00:00
const SummaryIncidentItem = ({ incident }: { incident: IncidentSummaryItem }) => {
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
>
{incident.monitorName ?? "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 SummaryCardLatestIncidentsProps {
summary?: IncidentSummary | null;
}
export const SummaryCardLatestIncidents = ({ summary }: SummaryCardLatestIncidentsProps) => {
2026-01-30 23:16:35 +00:00
const { t } = useTranslation();
const theme = useTheme();
2026-02-02 17:28:22 +00:00
const latestIncidents = summary?.latestIncidents ?? [];
2026-01-30 23:16:35 +00:00
return (
<SummaryCard title={t("pages.incidents.summaryCard.latestIncidents.title")}>
<Stack gap={theme.spacing(4)}>
2026-02-02 17:28:22 +00:00
{latestIncidents.slice(0, 3).map((incident, index) => (
2026-01-30 23:16:35 +00:00
<Box key={incident.id}>
2026-02-02 17:28:22 +00:00
<SummaryIncidentItem incident={incident} />
{index < latestIncidents.length - 1 && (
<Divider sx={{ mt: theme.spacing(2) }} />
)}
2026-01-30 23:16:35 +00:00
</Box>
))}
</Stack>
</SummaryCard>
);
};
interface SummaryCardStatsProps {
2026-01-30 23:22:56 +00:00
summary?: IncidentSummary | null;
2026-01-30 23:16:35 +00:00
}
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} />}
2026-01-30 23:31:03 +00:00
label={t("pages.incidents.summaryCard.incidentStats.totalIncidents")}
2026-01-30 23:16:35 +00:00
value={summary?.total || 0}
/>
<SummaryItem
icon={<TriangleAlert size={18} />}
2026-01-30 23:31:03 +00:00
label={t("pages.incidents.summaryCard.incidentStats.mostAffectedMonitor")}
2026-01-30 23:16:35 +00:00
value={mostAffected}
/>
<SummaryItem
icon={<Wrench size={18} />}
2026-01-30 23:31:03 +00:00
label={t("pages.incidents.summaryCard.incidentStats.avgResolutionTime")}
2026-01-30 23:16:35 +00:00
value={summary.total > 0 ? `${summary.avgResolutionTimeHours || 0} hours` : "N/A"}
/>
</SummaryCard>
);
};