initial commit
This commit is contained in:
1 parent
7cb985116e
commit
75acf7b38f
955 files changed
+37333
-87054
No files matched your search
@@ -0,0 +1,165 @@
|
||||
import { Table, Pagination, ValueLabel } from "@/components/design-elements";
|
||||
import Box from "@mui/material/Box";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import { Button } from "@/components/inputs";
|
||||
import type { Header } from "@/components/design-elements/Table";
|
||||
|
||||
import { usePatch } from "@/hooks/UseApi";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { formatDateWithTz } from "@/utils/TimeUtils";
|
||||
import { useAppSelector } from "@/hooks/AppHooks";
|
||||
import type { IIncident } from "@/types/incident";
|
||||
|
||||
export const IncidentTable = ({
|
||||
incidents,
|
||||
count,
|
||||
page,
|
||||
setPage,
|
||||
rowsPerPage,
|
||||
setRowsPerPage,
|
||||
refetch,
|
||||
}: {
|
||||
incidents: IIncident[];
|
||||
count: number;
|
||||
page: number;
|
||||
setPage: (page: number) => void;
|
||||
rowsPerPage: number;
|
||||
setRowsPerPage: (rowsPerPage: number) => void;
|
||||
refetch: () => void;
|
||||
}) => {
|
||||
const { patch, loading: isPatching } = usePatch();
|
||||
const { t } = useTranslation();
|
||||
const uiTimezone = useAppSelector((state: any) => state.ui.timezone);
|
||||
|
||||
const getHeaders = (t: Function, uiTimezone: string) => {
|
||||
const headers: Header<IIncident>[] = [
|
||||
{
|
||||
id: "name",
|
||||
content: t("incidentsTableMonitorName"),
|
||||
render: (row) => {
|
||||
return row.monitorId.name || "N/A";
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "start",
|
||||
content: "Incident start",
|
||||
render: (row) => {
|
||||
return formatDateWithTz(
|
||||
row.startedAt,
|
||||
"ddd, MMMM D, YYYY, HH:mm A",
|
||||
uiTimezone
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "end",
|
||||
content: "Incident end",
|
||||
render: (row) => {
|
||||
return row.endedAt
|
||||
? formatDateWithTz(
|
||||
row.endedAt,
|
||||
"ddd, MMMM D, YYYY, HH:mm A",
|
||||
uiTimezone
|
||||
)
|
||||
: "Ongoing";
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "status",
|
||||
content: "Current monitor status",
|
||||
render: (row) => {
|
||||
return (
|
||||
<Typography textTransform={"capitalize"} color="textPrimary">
|
||||
{row.monitorId.status}
|
||||
</Typography>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "resolved",
|
||||
content: "Resolved",
|
||||
render: (row) => {
|
||||
return (
|
||||
<ValueLabel
|
||||
value={row.resolved ? "positive" : "negative"}
|
||||
text={row.resolved ? "Yes" : "No"}
|
||||
/>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "resolutionType",
|
||||
content: "Resolution type",
|
||||
render: (row) => {
|
||||
return row.resolutionType || "N/A";
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "resolvedBy",
|
||||
content: "Resolved by",
|
||||
render: (row) => {
|
||||
return row.resolvedBy?.email || "N/A";
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "actions",
|
||||
content: "Actions",
|
||||
render: (row) => {
|
||||
return row.resolved ? null : (
|
||||
<Button
|
||||
onClick={async (e) => {
|
||||
e.stopPropagation();
|
||||
await patch(`/incidents/${row._id}/resolve`, {
|
||||
resolutionNote: "Resolved via UI",
|
||||
});
|
||||
refetch();
|
||||
}}
|
||||
variant="contained"
|
||||
color="accent"
|
||||
>
|
||||
Resolve
|
||||
</Button>
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
||||
return headers;
|
||||
};
|
||||
|
||||
const headers = getHeaders(t, uiTimezone);
|
||||
|
||||
const handlePageChange = (
|
||||
_e: React.MouseEvent<HTMLButtonElement> | null,
|
||||
newPage: number
|
||||
) => {
|
||||
setPage(newPage);
|
||||
};
|
||||
|
||||
const handleRowsPerPageChange = (
|
||||
e: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>
|
||||
) => {
|
||||
const value = Number(e.target.value);
|
||||
setPage(0);
|
||||
setRowsPerPage(value);
|
||||
};
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Table
|
||||
headers={headers}
|
||||
data={incidents}
|
||||
onRowClick={(row) => {
|
||||
alert(JSON.stringify(row, null, 2));
|
||||
}}
|
||||
/>
|
||||
<Pagination
|
||||
component="div"
|
||||
count={count}
|
||||
page={page}
|
||||
rowsPerPage={rowsPerPage}
|
||||
onPageChange={handlePageChange}
|
||||
onRowsPerPageChange={handleRowsPerPageChange}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,121 @@
|
||||
import Stack from "@mui/material/Stack";
|
||||
import MenuItem from "@mui/material/MenuItem";
|
||||
import { Select } from "@/components/inputs";
|
||||
import { BasePage, InfoBox } from "@/components/design-elements";
|
||||
import { IncidentTable } from "@/pages/incidents/IncidentTable";
|
||||
import { HeaderRange } from "@/components/common/HeaderRange";
|
||||
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import { useParams } from "react-router";
|
||||
import { useState, useEffect } from "react";
|
||||
import { useGet } from "@/hooks/UseApi";
|
||||
import type { ApiResponse } from "@/hooks/UseApi";
|
||||
import type { SelectChangeEvent } from "@mui/material/Select";
|
||||
import type { IIncident } from "@/types/incident";
|
||||
import type { IMonitor } from "@/types/monitor";
|
||||
|
||||
const IncidentsPage = () => {
|
||||
const theme = useTheme();
|
||||
const [selectedMonitorId, setSelectedMonitorId] = useState<string>("all");
|
||||
const { id } = useParams<{ id: string }>();
|
||||
|
||||
const [page, setPage] = useState(0);
|
||||
const [rowsPerPage, setRowsPerPage] = useState(10);
|
||||
const [range, setRange] = useState("2h");
|
||||
const [resolved, setResolved] = useState<boolean | null>(false);
|
||||
|
||||
const { response, isValidating, refetch } = useGet<
|
||||
ApiResponse<{ count: number; incidents: IIncident[] }>
|
||||
>(
|
||||
`/incidents?page=${page}&rowsPerPage=${rowsPerPage}&range=${range}${
|
||||
selectedMonitorId && selectedMonitorId !== "all"
|
||||
? `&monitorId=${selectedMonitorId}`
|
||||
: ""
|
||||
}${resolved !== null ? `&resolved=${resolved}` : ""}`,
|
||||
{},
|
||||
{ keepPreviousData: true },
|
||||
{ useTeamIdAsKey: true }
|
||||
);
|
||||
|
||||
const incidents = response?.data?.incidents
|
||||
? [...response.data.incidents].reverse()
|
||||
: [];
|
||||
const count = response?.data?.count || 0;
|
||||
|
||||
const { response: monitorResponse } = useGet<ApiResponse<IMonitor[]>>(
|
||||
`/monitors`,
|
||||
{},
|
||||
{ keepPreviousData: true }
|
||||
);
|
||||
|
||||
const monitors: IMonitor[] = monitorResponse?.data || [];
|
||||
|
||||
useEffect(() => {
|
||||
if (id) {
|
||||
setSelectedMonitorId(id);
|
||||
}
|
||||
}, [id]);
|
||||
|
||||
return (
|
||||
<BasePage>
|
||||
<InfoBox
|
||||
title="Incident History"
|
||||
description="View all past and ongoing incidents across your monitors. Analyze downtime patterns, incident duration, and resolution times to improve reliability."
|
||||
/>
|
||||
<Stack
|
||||
direction={{ xs: "column", md: "row" }}
|
||||
spacing={theme.spacing(8)}
|
||||
justifyContent={"space-between"}
|
||||
>
|
||||
<Stack
|
||||
direction={{ xs: "column", md: "row" }}
|
||||
spacing={theme.spacing(8)}
|
||||
>
|
||||
<Select<string>
|
||||
onChange={(e: SelectChangeEvent<string>) => {
|
||||
setSelectedMonitorId(e.target.value);
|
||||
}}
|
||||
value={selectedMonitorId}
|
||||
>
|
||||
<MenuItem value="all">All monitors</MenuItem>
|
||||
{monitors.map((monitor) => (
|
||||
<MenuItem key={monitor._id} value={monitor._id}>
|
||||
{monitor.name}
|
||||
</MenuItem>
|
||||
))}
|
||||
</Select>
|
||||
<Select<string>
|
||||
onChange={(e: SelectChangeEvent<string>) => {
|
||||
if (e.target.value === "resolved") {
|
||||
setResolved(true);
|
||||
} else if (e.target.value === "unresolved") {
|
||||
setResolved(false);
|
||||
} else {
|
||||
setResolved(null);
|
||||
}
|
||||
}}
|
||||
value={
|
||||
resolved === null ? "all" : resolved ? "resolved" : "unresolved"
|
||||
}
|
||||
>
|
||||
<MenuItem value={"all"}>All</MenuItem>
|
||||
<MenuItem value={"resolved"}>Resolved</MenuItem>
|
||||
<MenuItem value={"unresolved"}>Unresolved</MenuItem>
|
||||
</Select>
|
||||
</Stack>
|
||||
<HeaderRange range={range} setRange={setRange} loading={isValidating} />
|
||||
</Stack>
|
||||
<IncidentTable
|
||||
incidents={incidents}
|
||||
rowsPerPage={rowsPerPage}
|
||||
setRowsPerPage={setRowsPerPage}
|
||||
page={page}
|
||||
setPage={setPage}
|
||||
count={count}
|
||||
refetch={refetch}
|
||||
/>
|
||||
</BasePage>
|
||||
);
|
||||
};
|
||||
|
||||
export default IncidentsPage;
|
||||
Reference in new issue
Block a user