Feat: Summary for Incidents

This commit is contained in:
Br0wnHammer committed 2025-07-01 17:55:50 +05:30
1 parent 35a9c081b5
commit 5428999d46
4 files changed
+85 -8

No files matched your search

@@ -4,9 +4,9 @@ import StatusBox from "./StatusBox";
import { useTheme } from "@emotion/react";
import SkeletonLayout from "./skeleton";
const StatusBoxes = ({ shouldRender }) => {
const StatusBoxes = ({ isLoading, statusCounts }) => {
const theme = useTheme();
if (!shouldRender) return <SkeletonLayout shouldRender={shouldRender} />;
if (isLoading) return <SkeletonLayout shouldRender={isLoading} />;
return (
<Stack
gap={theme.spacing(12)}
@@ -15,29 +15,35 @@ const StatusBoxes = ({ shouldRender }) => {
>
<StatusBox
title={"Total Incidents"}
value={6}
value={statusCounts?.total || 0}
/>
<StatusBox
title={"Resolved"}
status="up"
value={3}
value={statusCounts?.resolved || 0}
/>
<StatusBox
title={"Cannot Resolve"}
status="paused"
value={2}
value={statusCounts?.cannotResolve || 0}
/>
<StatusBox
title={"Down"}
status="down"
value={1}
value={statusCounts?.down || 0}
/>
</Stack>
);
};
StatusBoxes.propTypes = {
shouldRender: PropTypes.bool,
isLoading: PropTypes.bool,
statusCounts: PropTypes.shape({
total: PropTypes.number,
resolved: PropTypes.number,
cannotResolve: PropTypes.number,
down: PropTypes.number,
}),
};
export default StatusBoxes;
+1 -1
View File
@@ -64,7 +64,7 @@ const Incidents = () => {
<Stack gap={theme.spacing(10)}>
<Breadcrumbs list={BREADCRUMBS} />
<StatusBoxes
shouldRender={!isLoading}
isLoading={isLoading}
/>
<OptionsHeader
shouldRender={!isLoading}
+23
View File
@@ -5,6 +5,7 @@ import PageSpeedCheck from "../../models/PageSpeedCheck.js";
import User from "../../models/User.js";
import logger from "../../../utils/logger.js";
import { ObjectId } from "mongodb";
import { buildChecksAndSummaryByTeamIdPipeline } from "./checkModuleQueries.js";
const SERVICE_NAME = "checkModule";
const dateRangeLookup = {
@@ -304,6 +305,27 @@ const ackAllChecks = async (monitorId, teamId, ack, path) => {
}
};
/**
* Get checks and summary by team ID
* @async
* @param {string} teamId
* @returns {Promise<Object>}
* @throws {Error}
*/
const getChecksAndSummaryByTeamId = async ({ teamId }) => {
try {
const matchStage = {
teamId: new ObjectId(teamId),
}
const checks = await Check.aggregate(buildChecksAndSummaryByTeamIdPipeline({ matchStage }));
return checks[0].summary;
} catch (error) {
error.service = SERVICE_NAME;
error.method = "getChecksAndSummaryByTeamId";
throw error;
}
};
/**
* Delete all checks for a monitor
* @async
@@ -387,6 +409,7 @@ export {
getChecksByTeam,
ackCheck,
ackAllChecks,
getChecksAndSummaryByTeamId,
deleteChecks,
deleteChecksByTeamId,
updateChecksTTL,
@@ -0,0 +1,48 @@
const buildChecksAndSummaryByTeamIdPipeline = ({ matchStage }) => {
return [
{ $match: matchStage },
{
$facet: {
summary: [
{
$group: {
_id: null,
totalChecks: { $sum: { $cond: [{ $eq: ["$status", false] }, 1, 0] } },
resolvedChecks: {
$sum: {
$cond: [{ $eq: ["$ack", true] }, 1, 0],
},
},
downChecks: {
$sum: {
$cond: [
{ $and: [{ $eq: ["$ack", false] }, { $eq: ["$status", false] }] },
1,
0,
],
},
},
cannotResolveChecks: {
$sum: {
$cond: [{ $eq: ["$statusCode", 5000] }, 1, 0],
},
},
},
},
{
$project: {
_id: 0,
},
},
],
},
},
{
$project: {
summary: { $arrayElemAt: ["$summary", 0] },
},
},
];
};
export { buildChecksAndSummaryByTeamIdPipeline };