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>
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user