incidents -> checks
This commit is contained in:
1 parent
f696b4ef9b
commit
427e5a18ea
21 files changed
+615
-613
No files matched your search
@@ -0,0 +1,264 @@
|
|||||||
|
//Components
|
||||||
|
import Stack from "@mui/material/Stack";
|
||||||
|
import DataTable from "@/Components/v1/Table/index.jsx";
|
||||||
|
import Table from "@mui/material/Table";
|
||||||
|
import TableBody from "@mui/material/TableBody";
|
||||||
|
import TableRow from "@mui/material/TableRow";
|
||||||
|
import TableCell from "@mui/material/TableCell";
|
||||||
|
import TableSkeleton from "@/Components/v1/Table/skeleton.jsx";
|
||||||
|
import Pagination from "@/Components/v1/Table/TablePagination/index.jsx";
|
||||||
|
import { StatusLabel } from "@/Components/v1/Label/index.jsx";
|
||||||
|
import { HttpStatusLabel } from "@/Components/v1/HttpStatusLabel/index.jsx";
|
||||||
|
import GenericFallback from "@/Components/v1/GenericFallback/index.jsx";
|
||||||
|
import NetworkError from "@/Components/v1/GenericFallback/NetworkError.jsx";
|
||||||
|
|
||||||
|
//Utils
|
||||||
|
import { formatDateWithTz } from "@/Utils/timeUtils.js";
|
||||||
|
import { useSelector } from "react-redux";
|
||||||
|
import { useState } from "react";
|
||||||
|
import PropTypes from "prop-types";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import {
|
||||||
|
useFetchChecksTeam,
|
||||||
|
useFetchChecksByMonitor,
|
||||||
|
useResolveIncident,
|
||||||
|
} from "@/Hooks/checkHooks.js";
|
||||||
|
import { Button, Typography, useTheme } from "@mui/material";
|
||||||
|
import { lighten } from "@mui/material/styles";
|
||||||
|
|
||||||
|
const GetTooltip = (row) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const phases = row?.timings?.phases;
|
||||||
|
|
||||||
|
const phaseKeyFormattingMap = {
|
||||||
|
firstByte: "first byte",
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<Stack
|
||||||
|
backgroundColor={lighten(theme.palette.primary.main, 0.1)}
|
||||||
|
border={`1px solid ${theme.palette.primary.lowContrast}`}
|
||||||
|
borderRadius={theme.shape.borderRadius}
|
||||||
|
py={theme.spacing(2)}
|
||||||
|
px={theme.spacing(4)}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
variant="body2"
|
||||||
|
color={theme.palette.primary.contrastText}
|
||||||
|
>{`Status code: ${row?.statusCode}`}</Typography>
|
||||||
|
<Typography
|
||||||
|
variant="body2"
|
||||||
|
color={theme.palette.primary.contrastText}
|
||||||
|
>{`Response time: ${row?.responseTime} ms`}</Typography>
|
||||||
|
{phases && (
|
||||||
|
<>
|
||||||
|
<Typography
|
||||||
|
variant="body2"
|
||||||
|
color={theme.palette.primary.contrastText}
|
||||||
|
>{`Request timing: `}</Typography>
|
||||||
|
<Table
|
||||||
|
size="small"
|
||||||
|
sx={{ ml: theme.spacing(2), mt: theme.spacing(2) }}
|
||||||
|
>
|
||||||
|
<TableBody>
|
||||||
|
{Object.keys(phases)?.map((phaseKey) => (
|
||||||
|
<TableRow key={phaseKey}>
|
||||||
|
<TableCell sx={{ border: "none", p: 0 }}>
|
||||||
|
<Typography
|
||||||
|
variant="body2"
|
||||||
|
color="success"
|
||||||
|
>
|
||||||
|
{`${phaseKeyFormattingMap[phaseKey] || phaseKey}:`}
|
||||||
|
</Typography>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell sx={{ border: "none", p: 0 }}>
|
||||||
|
<Typography
|
||||||
|
color={theme.palette.primary.contrastText}
|
||||||
|
variant="body2"
|
||||||
|
>{`${phases[phaseKey]} ms`}</Typography>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const IncidentTable = ({
|
||||||
|
isLoading,
|
||||||
|
monitors,
|
||||||
|
selectedMonitor,
|
||||||
|
filter,
|
||||||
|
dateRange,
|
||||||
|
updateTrigger,
|
||||||
|
setUpdateTrigger,
|
||||||
|
}) => {
|
||||||
|
//Redux state
|
||||||
|
const uiTimezone = useSelector((state) => state.ui.timezone);
|
||||||
|
|
||||||
|
//Local state
|
||||||
|
const [page, setPage] = useState(0);
|
||||||
|
const [rowsPerPage, setRowsPerPage] = useState(10);
|
||||||
|
const selectedMonitorDetails = monitors?.[selectedMonitor];
|
||||||
|
const selectedMonitorType = selectedMonitorDetails?.type;
|
||||||
|
|
||||||
|
//Hooks
|
||||||
|
const [resolveIncident, resolveLoading] = useResolveIncident();
|
||||||
|
|
||||||
|
const [checksMonitor, checksCountMonitor, isLoadingMonitor, networkErrorMonitor] =
|
||||||
|
useFetchChecksByMonitor({
|
||||||
|
monitorId: selectedMonitor === "0" ? undefined : selectedMonitor,
|
||||||
|
type: selectedMonitorType,
|
||||||
|
status: false,
|
||||||
|
sortOrder: "desc",
|
||||||
|
limit: null,
|
||||||
|
dateRange,
|
||||||
|
filter: filter === "resolved" ? "all" : filter,
|
||||||
|
ack: filter === "resolved" ? true : false,
|
||||||
|
page: page,
|
||||||
|
rowsPerPage: rowsPerPage,
|
||||||
|
enabled: selectedMonitor !== "0",
|
||||||
|
updateTrigger,
|
||||||
|
});
|
||||||
|
|
||||||
|
const [checksTeam, checksCountTeam, isLoadingTeam, networkErrorTeam] =
|
||||||
|
useFetchChecksTeam({
|
||||||
|
status: false,
|
||||||
|
sortOrder: "desc",
|
||||||
|
limit: null,
|
||||||
|
dateRange,
|
||||||
|
filter: filter === "resolved" ? "all" : filter,
|
||||||
|
ack: filter === "resolved" ? true : false,
|
||||||
|
page: page,
|
||||||
|
rowsPerPage: rowsPerPage,
|
||||||
|
enabled: selectedMonitor === "0",
|
||||||
|
updateTrigger,
|
||||||
|
});
|
||||||
|
|
||||||
|
const checks = selectedMonitor === "0" ? checksTeam : checksMonitor;
|
||||||
|
const checksCount = selectedMonitor === "0" ? checksCountTeam : checksCountMonitor;
|
||||||
|
isLoading = isLoadingTeam || isLoadingMonitor;
|
||||||
|
const networkError = selectedMonitor === "0" ? networkErrorTeam : networkErrorMonitor;
|
||||||
|
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
//Handlers
|
||||||
|
const handleChangePage = (_, newPage) => {
|
||||||
|
setPage(newPage);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleChangeRowsPerPage = (event) => {
|
||||||
|
setRowsPerPage(event.target.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleResolveIncident = (checkId) => {
|
||||||
|
resolveIncident(checkId, setUpdateTrigger);
|
||||||
|
};
|
||||||
|
|
||||||
|
const headers = [
|
||||||
|
{
|
||||||
|
id: "monitorName",
|
||||||
|
content: t("incidentsTableMonitorName"),
|
||||||
|
render: (row) => monitors[row.monitorId]?.name ?? "N/A",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "status",
|
||||||
|
content: t("incidentsTableStatus"),
|
||||||
|
render: (row) => {
|
||||||
|
const status = row.status === true ? "up" : "down";
|
||||||
|
return (
|
||||||
|
<StatusLabel
|
||||||
|
status={status}
|
||||||
|
text={status}
|
||||||
|
customStyles={{ textTransform: "capitalize" }}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "dateTime",
|
||||||
|
content: t("incidentsTableDateTime"),
|
||||||
|
render: (row) => {
|
||||||
|
const formattedDate = formatDateWithTz(
|
||||||
|
row.createdAt,
|
||||||
|
"YYYY-MM-DD HH:mm:ss A",
|
||||||
|
uiTimezone
|
||||||
|
);
|
||||||
|
return formattedDate;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "statusCode",
|
||||||
|
content: t("incidentsTableStatusCode"),
|
||||||
|
render: (row) => <HttpStatusLabel status={row.statusCode} />,
|
||||||
|
},
|
||||||
|
{ id: "message", content: t("incidentsTableMessage"), render: (row) => row.message },
|
||||||
|
{
|
||||||
|
id: "action",
|
||||||
|
content: t("actions"),
|
||||||
|
render: (row) => {
|
||||||
|
return row.ack === false ? (
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="accent"
|
||||||
|
onClick={() => {
|
||||||
|
handleResolveIncident(row._id);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("incidentsTableActionResolve")}
|
||||||
|
</Button>
|
||||||
|
) : (
|
||||||
|
<Typography>
|
||||||
|
{t("incidentsTableResolvedAt")}{" "}
|
||||||
|
{formatDateWithTz(row.ackAt, "YYYY-MM-DD HH:mm:ss A", uiTimezone)}
|
||||||
|
</Typography>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
if (isLoading || resolveLoading) return <TableSkeleton />;
|
||||||
|
|
||||||
|
if (networkError) {
|
||||||
|
return (
|
||||||
|
<GenericFallback>
|
||||||
|
<NetworkError />
|
||||||
|
</GenericFallback>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isLoading && typeof checksCount === "undefined") {
|
||||||
|
return <GenericFallback>{t("incidentsTableNoIncidents")}</GenericFallback>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<DataTable
|
||||||
|
headers={headers}
|
||||||
|
data={checks}
|
||||||
|
config={{ tooltipContent: GetTooltip }}
|
||||||
|
/>
|
||||||
|
<Pagination
|
||||||
|
paginationLabel={t("incidentsTablePaginationLabel")}
|
||||||
|
itemCount={checksCount}
|
||||||
|
page={page}
|
||||||
|
rowsPerPage={rowsPerPage}
|
||||||
|
handleChangePage={handleChangePage}
|
||||||
|
handleChangeRowsPerPage={handleChangeRowsPerPage}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
IncidentTable.propTypes = {
|
||||||
|
isLoading: PropTypes.bool,
|
||||||
|
monitors: PropTypes.object,
|
||||||
|
selectedMonitor: PropTypes.string,
|
||||||
|
filter: PropTypes.string,
|
||||||
|
dateRange: PropTypes.string,
|
||||||
|
updateTrigger: PropTypes.bool,
|
||||||
|
setUpdateTrigger: PropTypes.func,
|
||||||
|
};
|
||||||
|
export default IncidentTable;
|
||||||
+8
-7
@@ -5,6 +5,7 @@ import PropTypes from "prop-types";
|
|||||||
|
|
||||||
//Utils
|
//Utils
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
|
import SkeletonLayout from "./skeleton.jsx";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
const OptionsHeader = ({
|
const OptionsHeader = ({
|
||||||
@@ -14,27 +15,27 @@ const OptionsHeader = ({
|
|||||||
monitors,
|
monitors,
|
||||||
filter = "all",
|
filter = "all",
|
||||||
setFilter,
|
setFilter,
|
||||||
dateRange = "all",
|
dateRange = "hour",
|
||||||
setDateRange,
|
setDateRange,
|
||||||
}) => {
|
}) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const monitorNames = typeof monitors !== "undefined" ? Object.values(monitors) : [];
|
const monitorNames = typeof monitors !== "undefined" ? Object.values(monitors) : [];
|
||||||
|
|
||||||
const filterOptions = [
|
const filterOptions = [
|
||||||
{ _id: "all", name: t("incidentsPage.incidentsOptionsHeaderFilterAll") },
|
{ _id: "all", name: t("incidentsOptionsHeaderFilterAll") },
|
||||||
{ _id: "active", name: t("incidentsPage.incidentsOptionsHeaderFilterActive") },
|
{ _id: "down", name: t("incidentsOptionsHeaderFilterDown") },
|
||||||
{ _id: "resolved", name: t("incidentsPage.incidentsOptionsHeaderFilterResolved") },
|
{ _id: "resolve", name: t("incidentsOptionsHeaderFilterCannotResolve") },
|
||||||
{ _id: "manual", name: t("incidentsPage.incidentsOptionsHeaderFilterManual") },
|
{ _id: "resolved", name: t("incidentsOptionsHeaderFilterResolved") },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// The stacks below which are three in number have the same style so
|
||||||
const stackStyles = {
|
const stackStyles = {
|
||||||
direction: "row",
|
direction: "row",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
gap: theme.spacing(6),
|
gap: theme.spacing(6),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!shouldRender) return;
|
if (!shouldRender) return <SkeletonLayout />;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack
|
<Stack
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,120 @@
|
|||||||
|
// Components
|
||||||
|
import { Stack } from "@mui/material";
|
||||||
|
import Breadcrumbs from "@/Components/v1/Breadcrumbs/index.jsx";
|
||||||
|
import GenericFallback from "@/Components/v1/GenericFallback/index.jsx";
|
||||||
|
import IncidentTable from "./Components/IncidentTable/index.jsx";
|
||||||
|
import OptionsHeader from "./Components/OptionsHeader/index.jsx";
|
||||||
|
import StatusBoxes from "./Components/StatusBoxes/index.jsx";
|
||||||
|
import { Box, Button } from "@mui/material";
|
||||||
|
|
||||||
|
//Utils
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import { useFetchMonitorsByTeamId } from "@/Hooks/monitorHooks.js";
|
||||||
|
import {
|
||||||
|
useFetchChecksSummaryByTeamId,
|
||||||
|
useAcknowledgeChecks,
|
||||||
|
} from "@/Hooks/checkHooks.js";
|
||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import NetworkError from "@/Components/v1/GenericFallback/NetworkError.jsx";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useParams } from "react-router-dom";
|
||||||
|
|
||||||
|
//Constants
|
||||||
|
const Checks = () => {
|
||||||
|
// Redux state
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const BREADCRUMBS = [{ name: t("checksPageTitle"), path: "/checks" }];
|
||||||
|
|
||||||
|
// Local state
|
||||||
|
const [selectedMonitor, setSelectedMonitor] = useState("0");
|
||||||
|
const [filter, setFilter] = useState(undefined);
|
||||||
|
const [dateRange, setDateRange] = useState(undefined);
|
||||||
|
const [monitorLookup, setMonitorLookup] = useState(undefined);
|
||||||
|
const [updateTrigger, setUpdateTrigger] = useState(false);
|
||||||
|
|
||||||
|
//Hooks
|
||||||
|
const { acknowledge, isLoadingAcknowledge } = useAcknowledgeChecks();
|
||||||
|
|
||||||
|
//Utils
|
||||||
|
const theme = useTheme();
|
||||||
|
const [monitors, , isLoading, networkError] = useFetchMonitorsByTeamId({});
|
||||||
|
const [summary, isLoadingSummary, networkErrorSummary] = useFetchChecksSummaryByTeamId({
|
||||||
|
updateTrigger,
|
||||||
|
});
|
||||||
|
const { monitorId } = useParams();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (monitorId) {
|
||||||
|
setSelectedMonitor(monitorId);
|
||||||
|
}
|
||||||
|
}, [monitorId]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const monitorLookup = monitors?.reduce((acc, monitor) => {
|
||||||
|
acc[monitor._id] = {
|
||||||
|
_id: monitor._id,
|
||||||
|
name: monitor.name,
|
||||||
|
type: monitor.type,
|
||||||
|
};
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
setMonitorLookup(monitorLookup);
|
||||||
|
}, [monitors]);
|
||||||
|
|
||||||
|
const handleAcknowledge = () => {
|
||||||
|
const monitorId = selectedMonitor === "0" ? null : selectedMonitor;
|
||||||
|
acknowledge(setUpdateTrigger, monitorId);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (networkError || networkErrorSummary) {
|
||||||
|
return (
|
||||||
|
<GenericFallback>
|
||||||
|
<NetworkError />
|
||||||
|
</GenericFallback>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Stack gap={theme.spacing(10)}>
|
||||||
|
<Breadcrumbs list={BREADCRUMBS} />
|
||||||
|
<Box alignSelf="flex-end">
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="accent"
|
||||||
|
onClick={handleAcknowledge}
|
||||||
|
disabled={isLoadingAcknowledge}
|
||||||
|
>
|
||||||
|
{selectedMonitor === "0"
|
||||||
|
? t("checksPageActionResolveAllMonitor")
|
||||||
|
: t("checksPageActionResolveMonitor")}
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
<StatusBoxes
|
||||||
|
isLoading={isLoadingSummary}
|
||||||
|
summary={summary}
|
||||||
|
/>
|
||||||
|
<OptionsHeader
|
||||||
|
shouldRender={!isLoading}
|
||||||
|
monitors={monitorLookup}
|
||||||
|
selectedMonitor={selectedMonitor}
|
||||||
|
setSelectedMonitor={setSelectedMonitor}
|
||||||
|
filter={filter}
|
||||||
|
setFilter={setFilter}
|
||||||
|
dateRange={dateRange}
|
||||||
|
setDateRange={setDateRange}
|
||||||
|
/>
|
||||||
|
<IncidentTable
|
||||||
|
isLoading={isLoading}
|
||||||
|
monitors={monitorLookup ? monitorLookup : {}}
|
||||||
|
selectedMonitor={selectedMonitor}
|
||||||
|
filter={filter}
|
||||||
|
dateRange={dateRange}
|
||||||
|
updateTrigger={updateTrigger}
|
||||||
|
setUpdateTrigger={setUpdateTrigger}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Checks;
|
||||||
File renamed without changes.
@@ -1,10 +1,5 @@
|
|||||||
//Components
|
//Components
|
||||||
import Stack from "@mui/material/Stack";
|
|
||||||
import DataTable from "@/Components/v1/Table/index.jsx";
|
import DataTable from "@/Components/v1/Table/index.jsx";
|
||||||
import Table from "@mui/material/Table";
|
|
||||||
import TableBody from "@mui/material/TableBody";
|
|
||||||
import TableRow from "@mui/material/TableRow";
|
|
||||||
import TableCell from "@mui/material/TableCell";
|
|
||||||
import TableSkeleton from "@/Components/v1/Table/skeleton.jsx";
|
import TableSkeleton from "@/Components/v1/Table/skeleton.jsx";
|
||||||
import Pagination from "@/Components/v1/Table/TablePagination/index.jsx";
|
import Pagination from "@/Components/v1/Table/TablePagination/index.jsx";
|
||||||
import { StatusLabel } from "@/Components/v1/Label/index.jsx";
|
import { StatusLabel } from "@/Components/v1/Label/index.jsx";
|
||||||
@@ -13,213 +8,154 @@ import GenericFallback from "@/Components/v1/GenericFallback/index.jsx";
|
|||||||
import NetworkError from "@/Components/v1/GenericFallback/NetworkError.jsx";
|
import NetworkError from "@/Components/v1/GenericFallback/NetworkError.jsx";
|
||||||
|
|
||||||
//Utils
|
//Utils
|
||||||
import { formatDateWithTz } from "@/Utils/timeUtils.js";
|
import { formatDateWithTz } from "../../../../Utils/timeUtils.js";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import { useState } from "react";
|
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import {
|
|
||||||
useFetchChecksTeam,
|
|
||||||
useFetchChecksByMonitor,
|
|
||||||
useResolveIncident,
|
|
||||||
} from "@/Hooks/checkHooks.js";
|
|
||||||
import { Button, Typography, useTheme } from "@mui/material";
|
import { Button, Typography, useTheme } from "@mui/material";
|
||||||
import { lighten } from "@mui/material/styles";
|
|
||||||
|
|
||||||
const GetTooltip = (row) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
const phases = row?.timings?.phases;
|
|
||||||
|
|
||||||
const phaseKeyFormattingMap = {
|
|
||||||
firstByte: "first byte",
|
|
||||||
};
|
|
||||||
return (
|
|
||||||
<Stack
|
|
||||||
backgroundColor={lighten(theme.palette.primary.main, 0.1)}
|
|
||||||
border={`1px solid ${theme.palette.primary.lowContrast}`}
|
|
||||||
borderRadius={theme.shape.borderRadius}
|
|
||||||
py={theme.spacing(2)}
|
|
||||||
px={theme.spacing(4)}
|
|
||||||
>
|
|
||||||
<Typography
|
|
||||||
variant="body2"
|
|
||||||
color={theme.palette.primary.contrastText}
|
|
||||||
>{`Status code: ${row?.statusCode}`}</Typography>
|
|
||||||
<Typography
|
|
||||||
variant="body2"
|
|
||||||
color={theme.palette.primary.contrastText}
|
|
||||||
>{`Response time: ${row?.responseTime} ms`}</Typography>
|
|
||||||
{phases && (
|
|
||||||
<>
|
|
||||||
<Typography
|
|
||||||
variant="body2"
|
|
||||||
color={theme.palette.primary.contrastText}
|
|
||||||
>{`Request timing: `}</Typography>
|
|
||||||
<Table
|
|
||||||
size="small"
|
|
||||||
sx={{ ml: theme.spacing(2), mt: theme.spacing(2) }}
|
|
||||||
>
|
|
||||||
<TableBody>
|
|
||||||
{Object.keys(phases)?.map((phaseKey) => (
|
|
||||||
<TableRow key={phaseKey}>
|
|
||||||
<TableCell sx={{ border: "none", p: 0 }}>
|
|
||||||
<Typography
|
|
||||||
variant="body2"
|
|
||||||
color="success"
|
|
||||||
>
|
|
||||||
{`${phaseKeyFormattingMap[phaseKey] || phaseKey}:`}
|
|
||||||
</Typography>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell sx={{ border: "none", p: 0 }}>
|
|
||||||
<Typography
|
|
||||||
color={theme.palette.primary.contrastText}
|
|
||||||
variant="body2"
|
|
||||||
>{`${phases[phaseKey]} ms`}</Typography>
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
|
||||||
))}
|
|
||||||
</TableBody>
|
|
||||||
</Table>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const IncidentTable = ({
|
const IncidentTable = ({
|
||||||
isLoading,
|
monitors = [],
|
||||||
monitors,
|
incidents = [],
|
||||||
selectedMonitor,
|
incidentsCount = 0,
|
||||||
filter,
|
isLoading = false,
|
||||||
dateRange,
|
networkError = false,
|
||||||
updateTrigger,
|
page = 0,
|
||||||
setUpdateTrigger,
|
rowsPerPage = 10,
|
||||||
|
handleChangePage,
|
||||||
|
handleChangeRowsPerPage,
|
||||||
|
resolveIncident,
|
||||||
|
handleUpdateTrigger,
|
||||||
}) => {
|
}) => {
|
||||||
//Redux state
|
|
||||||
const uiTimezone = useSelector((state) => state.ui.timezone);
|
const uiTimezone = useSelector((state) => state.ui.timezone);
|
||||||
|
|
||||||
//Local state
|
|
||||||
const [page, setPage] = useState(0);
|
|
||||||
const [rowsPerPage, setRowsPerPage] = useState(10);
|
|
||||||
const selectedMonitorDetails = monitors?.[selectedMonitor];
|
|
||||||
const selectedMonitorType = selectedMonitorDetails?.type;
|
|
||||||
|
|
||||||
//Hooks
|
|
||||||
const [resolveIncident, resolveLoading] = useResolveIncident();
|
|
||||||
|
|
||||||
const [checksMonitor, checksCountMonitor, isLoadingMonitor, networkErrorMonitor] =
|
|
||||||
useFetchChecksByMonitor({
|
|
||||||
monitorId: selectedMonitor === "0" ? undefined : selectedMonitor,
|
|
||||||
type: selectedMonitorType,
|
|
||||||
status: false,
|
|
||||||
sortOrder: "desc",
|
|
||||||
limit: null,
|
|
||||||
dateRange,
|
|
||||||
filter: filter === "resolved" ? "all" : filter,
|
|
||||||
ack: filter === "resolved" ? true : false,
|
|
||||||
page: page,
|
|
||||||
rowsPerPage: rowsPerPage,
|
|
||||||
enabled: selectedMonitor !== "0",
|
|
||||||
updateTrigger,
|
|
||||||
});
|
|
||||||
|
|
||||||
const [checksTeam, checksCountTeam, isLoadingTeam, networkErrorTeam] =
|
|
||||||
useFetchChecksTeam({
|
|
||||||
status: false,
|
|
||||||
sortOrder: "desc",
|
|
||||||
limit: null,
|
|
||||||
dateRange,
|
|
||||||
filter: filter === "resolved" ? "all" : filter,
|
|
||||||
ack: filter === "resolved" ? true : false,
|
|
||||||
page: page,
|
|
||||||
rowsPerPage: rowsPerPage,
|
|
||||||
enabled: selectedMonitor === "0",
|
|
||||||
updateTrigger,
|
|
||||||
});
|
|
||||||
|
|
||||||
const checks = selectedMonitor === "0" ? checksTeam : checksMonitor;
|
|
||||||
const checksCount = selectedMonitor === "0" ? checksCountTeam : checksCountMonitor;
|
|
||||||
isLoading = isLoadingTeam || isLoadingMonitor;
|
|
||||||
const networkError = selectedMonitor === "0" ? networkErrorTeam : networkErrorMonitor;
|
|
||||||
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
//Handlers
|
const handleResolveIncident = async (incidentId) => {
|
||||||
const handleChangePage = (_, newPage) => {
|
try {
|
||||||
setPage(newPage);
|
await resolveIncident(incidentId);
|
||||||
};
|
handleUpdateTrigger();
|
||||||
|
} catch (error) {
|
||||||
const handleChangeRowsPerPage = (event) => {
|
console.error(t("incidentsPage.errorResolvingIncident"), error);
|
||||||
setRowsPerPage(event.target.value);
|
}
|
||||||
};
|
|
||||||
|
|
||||||
const handleResolveIncident = (checkId) => {
|
|
||||||
resolveIncident(checkId, setUpdateTrigger);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const headers = [
|
const headers = [
|
||||||
{
|
{
|
||||||
id: "monitorName",
|
id: "monitorName",
|
||||||
content: t("incidentsTableMonitorName"),
|
content: t("incidentsTableMonitorName"),
|
||||||
render: (row) => monitors[row.monitorId]?.name ?? "N/A",
|
render: (row) => {
|
||||||
|
console.log(monitors, row);
|
||||||
|
const monitor = monitors.find((monitor) => monitor.id === row.monitorId);
|
||||||
|
return monitor ? monitor.name : "N/A";
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "status",
|
id: "status",
|
||||||
content: t("incidentsTableStatus"),
|
content: t("incidentsTableStatus"),
|
||||||
render: (row) => {
|
render: (row) => {
|
||||||
const status = row.status === true ? "up" : "down";
|
const status = row.status === true ? "down" : "up";
|
||||||
|
const statusText =
|
||||||
|
row.status === true ? t("incidentsPage.active") : t("incidentsPage.resolved");
|
||||||
return (
|
return (
|
||||||
<StatusLabel
|
<StatusLabel
|
||||||
status={status}
|
status={status}
|
||||||
text={status}
|
text={statusText}
|
||||||
customStyles={{ textTransform: "capitalize" }}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "dateTime",
|
id: "startTime",
|
||||||
content: t("incidentsTableDateTime"),
|
content: t("incidentsPage.startTime"),
|
||||||
render: (row) => {
|
render: (row) => {
|
||||||
const formattedDate = formatDateWithTz(
|
const formattedDate = formatDateWithTz(
|
||||||
row.createdAt,
|
row.startTime || row.createdAt,
|
||||||
"YYYY-MM-DD HH:mm:ss A",
|
"YYYY-MM-DD HH:mm:ss A",
|
||||||
uiTimezone
|
uiTimezone
|
||||||
);
|
);
|
||||||
return formattedDate;
|
return formattedDate;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: "endTime",
|
||||||
|
content: t("incidentsPage.endTime"),
|
||||||
|
render: (row) => {
|
||||||
|
if (row.endTime) {
|
||||||
|
return formatDateWithTz(row.endTime, "YYYY-MM-DD HH:mm:ss A", uiTimezone);
|
||||||
|
}
|
||||||
|
return "-";
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "resolutionType",
|
||||||
|
content: t("incidentsPage.resolutionType"),
|
||||||
|
render: (row) => {
|
||||||
|
if (row.resolutionType) {
|
||||||
|
return (
|
||||||
|
<Typography
|
||||||
|
variant="body2"
|
||||||
|
sx={{
|
||||||
|
textTransform: "capitalize",
|
||||||
|
color:
|
||||||
|
row.resolutionType === "manual"
|
||||||
|
? theme.palette.accent.main
|
||||||
|
: theme.palette.success.main,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{row.resolutionType}
|
||||||
|
</Typography>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return "-";
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
id: "statusCode",
|
id: "statusCode",
|
||||||
content: t("incidentsTableStatusCode"),
|
content: t("incidentsTableStatusCode"),
|
||||||
render: (row) => <HttpStatusLabel status={row.statusCode} />,
|
render: (row) => <HttpStatusLabel status={row.statusCode} />,
|
||||||
},
|
},
|
||||||
{ id: "message", content: t("incidentsTableMessage"), render: (row) => row.message },
|
{
|
||||||
|
id: "message",
|
||||||
|
content: t("incidentsTableMessage"),
|
||||||
|
render: (row) => row.message || "-",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
id: "action",
|
id: "action",
|
||||||
content: t("actions"),
|
content: t("actions"),
|
||||||
render: (row) => {
|
render: (row) => {
|
||||||
return row.ack === false ? (
|
if (row.status === true) {
|
||||||
<Button
|
return (
|
||||||
variant="contained"
|
<Button
|
||||||
color="accent"
|
variant="contained"
|
||||||
onClick={() => {
|
color="accent"
|
||||||
handleResolveIncident(row._id);
|
sx={{
|
||||||
}}
|
minHeight: "max-content",
|
||||||
>
|
lineHeight: 1.2,
|
||||||
{t("incidentsTableActionResolve")}
|
}}
|
||||||
</Button>
|
onClick={() => {
|
||||||
) : (
|
handleResolveIncident(row.id);
|
||||||
<Typography>
|
}}
|
||||||
{t("incidentsTableResolvedAt")}{" "}
|
>
|
||||||
{formatDateWithTz(row.ackAt, "YYYY-MM-DD HH:mm:ss A", uiTimezone)}
|
{t("incidentsPage.incidentsTableActionResolveManually")}
|
||||||
</Typography>
|
</Button>
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
<Typography
|
||||||
|
variant="body2"
|
||||||
|
color={theme.palette.primary.contrastTextSecondary}
|
||||||
|
>
|
||||||
|
{t("incidentsPage.incidentsTableResolved")}
|
||||||
|
</Typography>
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
if (isLoading || resolveLoading) return <TableSkeleton />;
|
if (isLoading) return <TableSkeleton />;
|
||||||
|
|
||||||
if (networkError) {
|
if (networkError) {
|
||||||
return (
|
return (
|
||||||
@@ -229,20 +165,25 @@ const IncidentTable = ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isLoading && typeof checksCount === "undefined") {
|
if (!isLoading && !networkError && incidents?.length === 0) {
|
||||||
return <GenericFallback>{t("incidentsTableNoIncidents")}</GenericFallback>;
|
return (
|
||||||
|
<GenericFallback>
|
||||||
|
{t("incidentsTableNoIncidents", "No incidents found")}
|
||||||
|
</GenericFallback>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const incidentsData = Array.isArray(incidents) ? incidents : [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<DataTable
|
<DataTable
|
||||||
headers={headers}
|
headers={headers}
|
||||||
data={checks}
|
data={incidentsData}
|
||||||
config={{ tooltipContent: GetTooltip }}
|
|
||||||
/>
|
/>
|
||||||
<Pagination
|
<Pagination
|
||||||
paginationLabel={t("incidentsTablePaginationLabel")}
|
paginationLabel={t("incidentsTablePaginationLabel", "Incidents")}
|
||||||
itemCount={checksCount}
|
itemCount={incidentsCount || 0}
|
||||||
page={page}
|
page={page}
|
||||||
rowsPerPage={rowsPerPage}
|
rowsPerPage={rowsPerPage}
|
||||||
handleChangePage={handleChangePage}
|
handleChangePage={handleChangePage}
|
||||||
@@ -253,12 +194,16 @@ const IncidentTable = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
IncidentTable.propTypes = {
|
IncidentTable.propTypes = {
|
||||||
isLoading: PropTypes.bool,
|
incidents: PropTypes.array.isRequired, // Array of incident objects
|
||||||
monitors: PropTypes.object,
|
incidentsCount: PropTypes.number.isRequired, // Total count for pagination
|
||||||
selectedMonitor: PropTypes.string,
|
isLoading: PropTypes.bool.isRequired, // Loading state
|
||||||
filter: PropTypes.string,
|
networkError: PropTypes.bool, // Network error object
|
||||||
dateRange: PropTypes.string,
|
page: PropTypes.number.isRequired, // Current page number
|
||||||
updateTrigger: PropTypes.bool,
|
rowsPerPage: PropTypes.number.isRequired, // Number of rows per page
|
||||||
setUpdateTrigger: PropTypes.func,
|
handleChangePage: PropTypes.func.isRequired, // Handler for page change
|
||||||
|
handleChangeRowsPerPage: PropTypes.func.isRequired, // Handler for rows per page change
|
||||||
|
resolveIncident: PropTypes.func.isRequired,
|
||||||
|
handleUpdateTrigger: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default IncidentTable;
|
export default IncidentTable;
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -5,7 +5,6 @@ import PropTypes from "prop-types";
|
|||||||
|
|
||||||
//Utils
|
//Utils
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import SkeletonLayout from "./skeleton.jsx";
|
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
const OptionsHeader = ({
|
const OptionsHeader = ({
|
||||||
@@ -15,27 +14,27 @@ const OptionsHeader = ({
|
|||||||
monitors,
|
monitors,
|
||||||
filter = "all",
|
filter = "all",
|
||||||
setFilter,
|
setFilter,
|
||||||
dateRange = "hour",
|
dateRange = "all",
|
||||||
setDateRange,
|
setDateRange,
|
||||||
}) => {
|
}) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const monitorNames = typeof monitors !== "undefined" ? Object.values(monitors) : [];
|
const monitorNames = typeof monitors !== "undefined" ? Object.values(monitors) : [];
|
||||||
|
|
||||||
const filterOptions = [
|
const filterOptions = [
|
||||||
{ _id: "all", name: t("incidentsOptionsHeaderFilterAll") },
|
{ _id: "all", name: t("incidentsPage.incidentsOptionsHeaderFilterAll") },
|
||||||
{ _id: "down", name: t("incidentsOptionsHeaderFilterDown") },
|
{ _id: "active", name: t("incidentsPage.incidentsOptionsHeaderFilterActive") },
|
||||||
{ _id: "resolve", name: t("incidentsOptionsHeaderFilterCannotResolve") },
|
{ _id: "resolved", name: t("incidentsPage.incidentsOptionsHeaderFilterResolved") },
|
||||||
{ _id: "resolved", name: t("incidentsOptionsHeaderFilterResolved") },
|
{ _id: "manual", name: t("incidentsPage.incidentsOptionsHeaderFilterManual") },
|
||||||
];
|
];
|
||||||
|
|
||||||
// The stacks below which are three in number have the same style so
|
|
||||||
const stackStyles = {
|
const stackStyles = {
|
||||||
direction: "row",
|
direction: "row",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
gap: theme.spacing(6),
|
gap: theme.spacing(6),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!shouldRender) return <SkeletonLayout />;
|
if (!shouldRender) return;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack
|
<Stack
|
||||||
|
|||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -4,70 +4,100 @@ import Breadcrumbs from "@/Components/v1/Breadcrumbs/index.jsx";
|
|||||||
import GenericFallback from "@/Components/v1/GenericFallback/index.jsx";
|
import GenericFallback from "@/Components/v1/GenericFallback/index.jsx";
|
||||||
import IncidentTable from "./Components/IncidentTable/index.jsx";
|
import IncidentTable from "./Components/IncidentTable/index.jsx";
|
||||||
import OptionsHeader from "./Components/OptionsHeader/index.jsx";
|
import OptionsHeader from "./Components/OptionsHeader/index.jsx";
|
||||||
import StatusBoxes from "./Components/StatusBoxes/index.jsx";
|
import IncidentsSummaryPanel from "./Components/IncidentsSummaryPanel/index.jsx";
|
||||||
import { Box, Button } from "@mui/material";
|
|
||||||
|
|
||||||
//Utils
|
//Utils
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { useFetchMonitorsByTeamId } from "@/Hooks/monitorHooks.js";
|
|
||||||
import {
|
|
||||||
useFetchChecksSummaryByTeamId,
|
|
||||||
useAcknowledgeChecks,
|
|
||||||
} from "@/Hooks/checkHooks.js";
|
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import NetworkError from "@/Components/v1/GenericFallback/NetworkError.jsx";
|
import NetworkError from "@/Components/v1/GenericFallback/NetworkError.jsx";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useParams } from "react-router-dom";
|
|
||||||
|
|
||||||
//Constants
|
// Hooks
|
||||||
const Checks = () => {
|
import useFetchIncidents from "./hooks/useFetchIncidents.js";
|
||||||
// Redux state
|
import { useFetchMonitorsByTeamId } from "../../Hooks/monitorHooks.js";
|
||||||
|
|
||||||
|
const Incidents2 = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const BREADCRUMBS = [{ name: t("checksPageTitle"), path: "/checks" }];
|
const BREADCRUMBS = [
|
||||||
|
{ name: t("incidentsPageTitle", "Incidents"), path: "/incidents" },
|
||||||
|
];
|
||||||
|
|
||||||
// Local state
|
|
||||||
const [selectedMonitor, setSelectedMonitor] = useState("0");
|
const [selectedMonitor, setSelectedMonitor] = useState("0");
|
||||||
const [filter, setFilter] = useState(undefined);
|
const [filter, setFilter] = useState("all");
|
||||||
const [dateRange, setDateRange] = useState(undefined);
|
const [dateRange, setDateRange] = useState("all");
|
||||||
|
const [page, setPage] = useState(0);
|
||||||
|
const [rowsPerPage, setRowsPerPage] = useState(10);
|
||||||
const [monitorLookup, setMonitorLookup] = useState(undefined);
|
const [monitorLookup, setMonitorLookup] = useState(undefined);
|
||||||
const [updateTrigger, setUpdateTrigger] = useState(false);
|
const [updateTrigger, setUpdateTrigger] = useState(false);
|
||||||
|
const handleUpdateTrigger = () => {
|
||||||
|
setUpdateTrigger((prev) => !prev);
|
||||||
|
};
|
||||||
|
|
||||||
//Hooks
|
const [monitors, isLoadingMonitors, monitorsNetworkError] = useFetchMonitorsByTeamId(
|
||||||
const { acknowledge, isLoadingAcknowledge } = useAcknowledgeChecks();
|
{}
|
||||||
|
);
|
||||||
|
|
||||||
|
const {
|
||||||
|
incidents,
|
||||||
|
incidentsCount,
|
||||||
|
isLoading: isLoadingIncidents,
|
||||||
|
networkError: incidentsNetworkError,
|
||||||
|
fetchIncidents,
|
||||||
|
fetchActiveIncidents,
|
||||||
|
fetchResolvedIncidents,
|
||||||
|
resolveIncident,
|
||||||
|
} = useFetchIncidents();
|
||||||
|
|
||||||
|
const networkError = monitorsNetworkError || incidentsNetworkError;
|
||||||
|
|
||||||
//Utils
|
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const [monitors, , isLoading, networkError] = useFetchMonitorsByTeamId({});
|
|
||||||
const [summary, isLoadingSummary, networkErrorSummary] = useFetchChecksSummaryByTeamId({
|
|
||||||
updateTrigger,
|
|
||||||
});
|
|
||||||
const { monitorId } = useParams();
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (monitorId) {
|
setPage(0);
|
||||||
setSelectedMonitor(monitorId);
|
}, [selectedMonitor, filter, dateRange]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const config = {
|
||||||
|
monitorId: selectedMonitor !== "0" ? selectedMonitor : undefined,
|
||||||
|
sortOrder: "desc",
|
||||||
|
dateRange,
|
||||||
|
page,
|
||||||
|
rowsPerPage,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (filter === "active") {
|
||||||
|
fetchActiveIncidents(config);
|
||||||
|
} else if (filter === "resolved") {
|
||||||
|
fetchResolvedIncidents(config);
|
||||||
|
} else {
|
||||||
|
fetchIncidents(config);
|
||||||
}
|
}
|
||||||
}, [monitorId]);
|
}, [
|
||||||
|
selectedMonitor,
|
||||||
|
filter,
|
||||||
|
dateRange,
|
||||||
|
page,
|
||||||
|
rowsPerPage,
|
||||||
|
updateTrigger,
|
||||||
|
fetchActiveIncidents,
|
||||||
|
fetchResolvedIncidents,
|
||||||
|
fetchIncidents,
|
||||||
|
]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const monitorLookup = monitors?.reduce((acc, monitor) => {
|
const lookup = monitors?.reduce((acc, monitor) => {
|
||||||
acc[monitor._id] = {
|
acc[monitor.id] = {
|
||||||
_id: monitor._id,
|
id: monitor.id,
|
||||||
name: monitor.name,
|
name: monitor.name,
|
||||||
type: monitor.type,
|
type: monitor.type,
|
||||||
};
|
};
|
||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
setMonitorLookup(monitorLookup);
|
setMonitorLookup(lookup);
|
||||||
}, [monitors]);
|
}, [monitors]);
|
||||||
|
|
||||||
const handleAcknowledge = () => {
|
if (networkError) {
|
||||||
const monitorId = selectedMonitor === "0" ? null : selectedMonitor;
|
|
||||||
acknowledge(setUpdateTrigger, monitorId);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (networkError || networkErrorSummary) {
|
|
||||||
return (
|
return (
|
||||||
<GenericFallback>
|
<GenericFallback>
|
||||||
<NetworkError />
|
<NetworkError />
|
||||||
@@ -75,27 +105,23 @@ const Checks = () => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleChangePage = (_, newPage) => {
|
||||||
|
setPage(newPage);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleChangeRowsPerPage = (event) => {
|
||||||
|
setRowsPerPage(parseInt(event.target.value, 10));
|
||||||
|
setPage(0);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack gap={theme.spacing(10)}>
|
<Stack gap={theme.spacing(10)}>
|
||||||
<Breadcrumbs list={BREADCRUMBS} />
|
<Breadcrumbs list={BREADCRUMBS} />
|
||||||
<Box alignSelf="flex-end">
|
|
||||||
<Button
|
<IncidentsSummaryPanel updateTrigger={updateTrigger} />
|
||||||
variant="contained"
|
|
||||||
color="accent"
|
|
||||||
onClick={handleAcknowledge}
|
|
||||||
disabled={isLoadingAcknowledge}
|
|
||||||
>
|
|
||||||
{selectedMonitor === "0"
|
|
||||||
? t("checksPageActionResolveAllMonitor")
|
|
||||||
: t("checksPageActionResolveMonitor")}
|
|
||||||
</Button>
|
|
||||||
</Box>
|
|
||||||
<StatusBoxes
|
|
||||||
isLoading={isLoadingSummary}
|
|
||||||
summary={summary}
|
|
||||||
/>
|
|
||||||
<OptionsHeader
|
<OptionsHeader
|
||||||
shouldRender={!isLoading}
|
shouldRender={!isLoadingMonitors}
|
||||||
monitors={monitorLookup}
|
monitors={monitorLookup}
|
||||||
selectedMonitor={selectedMonitor}
|
selectedMonitor={selectedMonitor}
|
||||||
setSelectedMonitor={setSelectedMonitor}
|
setSelectedMonitor={setSelectedMonitor}
|
||||||
@@ -104,17 +130,22 @@ const Checks = () => {
|
|||||||
dateRange={dateRange}
|
dateRange={dateRange}
|
||||||
setDateRange={setDateRange}
|
setDateRange={setDateRange}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<IncidentTable
|
<IncidentTable
|
||||||
isLoading={isLoading}
|
monitors={monitors || []}
|
||||||
monitors={monitorLookup ? monitorLookup : {}}
|
incidents={incidents || []}
|
||||||
selectedMonitor={selectedMonitor}
|
incidentsCount={incidentsCount || 0}
|
||||||
filter={filter}
|
isLoading={isLoadingIncidents}
|
||||||
dateRange={dateRange}
|
networkError={incidentsNetworkError}
|
||||||
updateTrigger={updateTrigger}
|
page={page}
|
||||||
setUpdateTrigger={setUpdateTrigger}
|
rowsPerPage={rowsPerPage}
|
||||||
|
handleChangePage={handleChangePage}
|
||||||
|
handleChangeRowsPerPage={handleChangeRowsPerPage}
|
||||||
|
resolveIncident={resolveIncident}
|
||||||
|
handleUpdateTrigger={handleUpdateTrigger}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Checks;
|
export default Incidents2;
|
||||||
@@ -1,209 +0,0 @@
|
|||||||
//Components
|
|
||||||
import DataTable from "@/Components/v1/Table/index.jsx";
|
|
||||||
import TableSkeleton from "@/Components/v1/Table/skeleton.jsx";
|
|
||||||
import Pagination from "@/Components/v1/Table/TablePagination/index.jsx";
|
|
||||||
import { StatusLabel } from "@/Components/v1/Label/index.jsx";
|
|
||||||
import { HttpStatusLabel } from "@/Components/v1/HttpStatusLabel/index.jsx";
|
|
||||||
import GenericFallback from "@/Components/v1/GenericFallback/index.jsx";
|
|
||||||
import NetworkError from "@/Components/v1/GenericFallback/NetworkError.jsx";
|
|
||||||
|
|
||||||
//Utils
|
|
||||||
import { formatDateWithTz } from "../../../../Utils/timeUtils.js";
|
|
||||||
import { useSelector } from "react-redux";
|
|
||||||
import PropTypes from "prop-types";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { Button, Typography, useTheme } from "@mui/material";
|
|
||||||
|
|
||||||
const IncidentTable = ({
|
|
||||||
monitors = [],
|
|
||||||
incidents = [],
|
|
||||||
incidentsCount = 0,
|
|
||||||
isLoading = false,
|
|
||||||
networkError = false,
|
|
||||||
page = 0,
|
|
||||||
rowsPerPage = 10,
|
|
||||||
handleChangePage,
|
|
||||||
handleChangeRowsPerPage,
|
|
||||||
resolveIncident,
|
|
||||||
handleUpdateTrigger,
|
|
||||||
}) => {
|
|
||||||
const uiTimezone = useSelector((state) => state.ui.timezone);
|
|
||||||
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const theme = useTheme();
|
|
||||||
|
|
||||||
const handleResolveIncident = async (incidentId) => {
|
|
||||||
try {
|
|
||||||
await resolveIncident(incidentId);
|
|
||||||
handleUpdateTrigger();
|
|
||||||
} catch (error) {
|
|
||||||
console.error(t("incidentsPage.errorResolvingIncident"), error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const headers = [
|
|
||||||
{
|
|
||||||
id: "monitorName",
|
|
||||||
content: t("incidentsTableMonitorName"),
|
|
||||||
render: (row) => {
|
|
||||||
console.log(monitors, row);
|
|
||||||
const monitor = monitors.find((monitor) => monitor.id === row.monitorId);
|
|
||||||
return monitor ? monitor.name : "N/A";
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "status",
|
|
||||||
content: t("incidentsTableStatus"),
|
|
||||||
render: (row) => {
|
|
||||||
const status = row.status === true ? "down" : "up";
|
|
||||||
const statusText =
|
|
||||||
row.status === true ? t("incidentsPage.active") : t("incidentsPage.resolved");
|
|
||||||
return (
|
|
||||||
<StatusLabel
|
|
||||||
status={status}
|
|
||||||
text={statusText}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "startTime",
|
|
||||||
content: t("incidentsPage.startTime"),
|
|
||||||
render: (row) => {
|
|
||||||
const formattedDate = formatDateWithTz(
|
|
||||||
row.startTime || row.createdAt,
|
|
||||||
"YYYY-MM-DD HH:mm:ss A",
|
|
||||||
uiTimezone
|
|
||||||
);
|
|
||||||
return formattedDate;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "endTime",
|
|
||||||
content: t("incidentsPage.endTime"),
|
|
||||||
render: (row) => {
|
|
||||||
if (row.endTime) {
|
|
||||||
return formatDateWithTz(row.endTime, "YYYY-MM-DD HH:mm:ss A", uiTimezone);
|
|
||||||
}
|
|
||||||
return "-";
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "resolutionType",
|
|
||||||
content: t("incidentsPage.resolutionType"),
|
|
||||||
render: (row) => {
|
|
||||||
if (row.resolutionType) {
|
|
||||||
return (
|
|
||||||
<Typography
|
|
||||||
variant="body2"
|
|
||||||
sx={{
|
|
||||||
textTransform: "capitalize",
|
|
||||||
color:
|
|
||||||
row.resolutionType === "manual"
|
|
||||||
? theme.palette.accent.main
|
|
||||||
: theme.palette.success.main,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{row.resolutionType}
|
|
||||||
</Typography>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return "-";
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "statusCode",
|
|
||||||
content: t("incidentsTableStatusCode"),
|
|
||||||
render: (row) => <HttpStatusLabel status={row.statusCode} />,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "message",
|
|
||||||
content: t("incidentsTableMessage"),
|
|
||||||
render: (row) => row.message || "-",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "action",
|
|
||||||
content: t("actions"),
|
|
||||||
render: (row) => {
|
|
||||||
if (row.status === true) {
|
|
||||||
return (
|
|
||||||
<Button
|
|
||||||
variant="contained"
|
|
||||||
color="accent"
|
|
||||||
sx={{
|
|
||||||
minHeight: "max-content",
|
|
||||||
lineHeight: 1.2,
|
|
||||||
}}
|
|
||||||
onClick={() => {
|
|
||||||
handleResolveIncident(row.id);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t("incidentsPage.incidentsTableActionResolveManually")}
|
|
||||||
</Button>
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return (
|
|
||||||
<Typography
|
|
||||||
variant="body2"
|
|
||||||
color={theme.palette.primary.contrastTextSecondary}
|
|
||||||
>
|
|
||||||
{t("incidentsPage.incidentsTableResolved")}
|
|
||||||
</Typography>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
if (isLoading) return <TableSkeleton />;
|
|
||||||
|
|
||||||
if (networkError) {
|
|
||||||
return (
|
|
||||||
<GenericFallback>
|
|
||||||
<NetworkError />
|
|
||||||
</GenericFallback>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isLoading && !networkError && incidents?.length === 0) {
|
|
||||||
return (
|
|
||||||
<GenericFallback>
|
|
||||||
{t("incidentsTableNoIncidents", "No incidents found")}
|
|
||||||
</GenericFallback>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const incidentsData = Array.isArray(incidents) ? incidents : [];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<DataTable
|
|
||||||
headers={headers}
|
|
||||||
data={incidentsData}
|
|
||||||
/>
|
|
||||||
<Pagination
|
|
||||||
paginationLabel={t("incidentsTablePaginationLabel", "Incidents")}
|
|
||||||
itemCount={incidentsCount || 0}
|
|
||||||
page={page}
|
|
||||||
rowsPerPage={rowsPerPage}
|
|
||||||
handleChangePage={handleChangePage}
|
|
||||||
handleChangeRowsPerPage={handleChangeRowsPerPage}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
IncidentTable.propTypes = {
|
|
||||||
incidents: PropTypes.array.isRequired, // Array of incident objects
|
|
||||||
incidentsCount: PropTypes.number.isRequired, // Total count for pagination
|
|
||||||
isLoading: PropTypes.bool.isRequired, // Loading state
|
|
||||||
networkError: PropTypes.bool, // Network error object
|
|
||||||
page: PropTypes.number.isRequired, // Current page number
|
|
||||||
rowsPerPage: PropTypes.number.isRequired, // Number of rows per page
|
|
||||||
handleChangePage: PropTypes.func.isRequired, // Handler for page change
|
|
||||||
handleChangeRowsPerPage: PropTypes.func.isRequired, // Handler for rows per page change
|
|
||||||
resolveIncident: PropTypes.func.isRequired,
|
|
||||||
handleUpdateTrigger: PropTypes.func.isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default IncidentTable;
|
|
||||||
@@ -1,151 +0,0 @@
|
|||||||
// Components
|
|
||||||
import { Stack } from "@mui/material";
|
|
||||||
import Breadcrumbs from "@/Components/v1/Breadcrumbs/index.jsx";
|
|
||||||
import GenericFallback from "@/Components/v1/GenericFallback/index.jsx";
|
|
||||||
import IncidentTable from "./Components/IncidentTable/index.jsx";
|
|
||||||
import OptionsHeader from "./Components/OptionsHeader/index.jsx";
|
|
||||||
import IncidentsSummaryPanel from "./Components/IncidentsSummaryPanel/index.jsx";
|
|
||||||
|
|
||||||
//Utils
|
|
||||||
import { useTheme } from "@emotion/react";
|
|
||||||
import { useState, useEffect } from "react";
|
|
||||||
import NetworkError from "@/Components/v1/GenericFallback/NetworkError.jsx";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
|
|
||||||
// Hooks
|
|
||||||
import useFetchIncidents from "./hooks/useFetchIncidents.js";
|
|
||||||
import { useFetchMonitorsByTeamId } from "../../Hooks/monitorHooks.js";
|
|
||||||
|
|
||||||
const Incidents2 = () => {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
|
|
||||||
const BREADCRUMBS = [
|
|
||||||
{ name: t("incidentsPageTitle", "Incidents"), path: "/incidents" },
|
|
||||||
];
|
|
||||||
|
|
||||||
const [selectedMonitor, setSelectedMonitor] = useState("0");
|
|
||||||
const [filter, setFilter] = useState("all");
|
|
||||||
const [dateRange, setDateRange] = useState("all");
|
|
||||||
const [page, setPage] = useState(0);
|
|
||||||
const [rowsPerPage, setRowsPerPage] = useState(10);
|
|
||||||
const [monitorLookup, setMonitorLookup] = useState(undefined);
|
|
||||||
const [updateTrigger, setUpdateTrigger] = useState(false);
|
|
||||||
const handleUpdateTrigger = () => {
|
|
||||||
setUpdateTrigger((prev) => !prev);
|
|
||||||
};
|
|
||||||
|
|
||||||
const [monitors, isLoadingMonitors, monitorsNetworkError] = useFetchMonitorsByTeamId(
|
|
||||||
{}
|
|
||||||
);
|
|
||||||
|
|
||||||
const {
|
|
||||||
incidents,
|
|
||||||
incidentsCount,
|
|
||||||
isLoading: isLoadingIncidents,
|
|
||||||
networkError: incidentsNetworkError,
|
|
||||||
fetchIncidents,
|
|
||||||
fetchActiveIncidents,
|
|
||||||
fetchResolvedIncidents,
|
|
||||||
resolveIncident,
|
|
||||||
} = useFetchIncidents();
|
|
||||||
|
|
||||||
const networkError = monitorsNetworkError || incidentsNetworkError;
|
|
||||||
|
|
||||||
const theme = useTheme();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setPage(0);
|
|
||||||
}, [selectedMonitor, filter, dateRange]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const config = {
|
|
||||||
monitorId: selectedMonitor !== "0" ? selectedMonitor : undefined,
|
|
||||||
sortOrder: "desc",
|
|
||||||
dateRange,
|
|
||||||
page,
|
|
||||||
rowsPerPage,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (filter === "active") {
|
|
||||||
fetchActiveIncidents(config);
|
|
||||||
} else if (filter === "resolved") {
|
|
||||||
fetchResolvedIncidents(config);
|
|
||||||
} else {
|
|
||||||
fetchIncidents(config);
|
|
||||||
}
|
|
||||||
}, [
|
|
||||||
selectedMonitor,
|
|
||||||
filter,
|
|
||||||
dateRange,
|
|
||||||
page,
|
|
||||||
rowsPerPage,
|
|
||||||
updateTrigger,
|
|
||||||
fetchActiveIncidents,
|
|
||||||
fetchResolvedIncidents,
|
|
||||||
fetchIncidents,
|
|
||||||
]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const lookup = monitors?.reduce((acc, monitor) => {
|
|
||||||
acc[monitor.id] = {
|
|
||||||
id: monitor.id,
|
|
||||||
name: monitor.name,
|
|
||||||
type: monitor.type,
|
|
||||||
};
|
|
||||||
return acc;
|
|
||||||
}, {});
|
|
||||||
setMonitorLookup(lookup);
|
|
||||||
}, [monitors]);
|
|
||||||
|
|
||||||
if (networkError) {
|
|
||||||
return (
|
|
||||||
<GenericFallback>
|
|
||||||
<NetworkError />
|
|
||||||
</GenericFallback>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleChangePage = (_, newPage) => {
|
|
||||||
setPage(newPage);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleChangeRowsPerPage = (event) => {
|
|
||||||
setRowsPerPage(parseInt(event.target.value, 10));
|
|
||||||
setPage(0);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Stack gap={theme.spacing(10)}>
|
|
||||||
<Breadcrumbs list={BREADCRUMBS} />
|
|
||||||
|
|
||||||
<IncidentsSummaryPanel updateTrigger={updateTrigger} />
|
|
||||||
|
|
||||||
<OptionsHeader
|
|
||||||
shouldRender={!isLoadingMonitors}
|
|
||||||
monitors={monitorLookup}
|
|
||||||
selectedMonitor={selectedMonitor}
|
|
||||||
setSelectedMonitor={setSelectedMonitor}
|
|
||||||
filter={filter}
|
|
||||||
setFilter={setFilter}
|
|
||||||
dateRange={dateRange}
|
|
||||||
setDateRange={setDateRange}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<IncidentTable
|
|
||||||
monitors={monitors || []}
|
|
||||||
incidents={incidents || []}
|
|
||||||
incidentsCount={incidentsCount || 0}
|
|
||||||
isLoading={isLoadingIncidents}
|
|
||||||
networkError={incidentsNetworkError}
|
|
||||||
page={page}
|
|
||||||
rowsPerPage={rowsPerPage}
|
|
||||||
handleChangePage={handleChangePage}
|
|
||||||
handleChangeRowsPerPage={handleChangeRowsPerPage}
|
|
||||||
resolveIncident={resolveIncident}
|
|
||||||
handleUpdateTrigger={handleUpdateTrigger}
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Incidents2;
|
|
||||||
@@ -28,9 +28,11 @@ import InfrastructureDetails from "../Pages/Infrastructure/Details/index.jsx";
|
|||||||
// Server Status
|
// Server Status
|
||||||
import ServerUnreachable from "../Pages/ServerUnreachable.jsx";
|
import ServerUnreachable from "../Pages/ServerUnreachable.jsx";
|
||||||
|
|
||||||
|
// Checks
|
||||||
|
import Checks from "../Pages/Checks/index.jsx";
|
||||||
|
|
||||||
// Incidents
|
// Incidents
|
||||||
import Checks from "../Pages/Incidents";
|
import Incidents from "../Pages/Incidents/index.jsx";
|
||||||
import Incidents2 from "../Pages/Incidents2/index.jsx";
|
|
||||||
|
|
||||||
// Status pages
|
// Status pages
|
||||||
import CreateStatus from "../Pages/StatusPage/Create/index.jsx";
|
import CreateStatus from "../Pages/StatusPage/Create/index.jsx";
|
||||||
@@ -136,7 +138,7 @@ const Routes = () => {
|
|||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="incidents/:monitorId?"
|
path="incidents/:monitorId?"
|
||||||
element={<Incidents2 />}
|
element={<Incidents />}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Route
|
<Route
|
||||||
|
|||||||
Reference in new issue
Block a user