Merge pull request #1541 from bluewave-labs/hotfix/fe/be/incidents-page

hotfix: fe/be/incidents page
This commit is contained in:
Alexander Holliday authored and GitHub committed 2025-01-09 10:53:14 -08:00
commit 5db231351e
3 files changed
+58 -44

No files matched your search

+2 -3
View File
@@ -29,7 +29,7 @@ const Incidents = () => {
const res = await networkService.getMonitorsByTeamId({ const res = await networkService.getMonitorsByTeamId({
authToken: authState.authToken, authToken: authState.authToken,
teamId: authState.user.teamId, teamId: authState.user.teamId,
limit: -1, limit: null,
types: null, types: null,
status: null, status: null,
checkOrder: null, checkOrder: null,
@@ -40,7 +40,6 @@ const Incidents = () => {
field: null, field: null,
order: null, order: null,
}); });
// Reduce to a lookup object for 0(1) lookup
if (res?.data?.data?.monitors?.length > 0) { if (res?.data?.data?.monitors?.length > 0) {
const monitorLookup = res.data.data.monitors.reduce((acc, monitor) => { const monitorLookup = res.data.data.monitors.reduce((acc, monitor) => {
acc[monitor._id] = monitor; acc[monitor._id] = monitor;
@@ -56,7 +55,7 @@ const Incidents = () => {
} }
}; };
fetchMonitors(); fetchMonitors();
}, [authState]); }, [authState, monitorId]);
useEffect(() => {}, [monitors]); useEffect(() => {}, [monitors]);
+1 -1
View File
@@ -508,7 +508,7 @@ class MonitorController {
data: monitors, data: monitors,
}); });
} catch (error) { } catch (error) {
next(handleError(error, SERVICE_NAME, "getMonitorsForDisplay")); next(handleError(error, SERVICE_NAME, "getMonitorsByTeamId"));
} }
}; };
} }
+55 -40
View File
@@ -508,7 +508,6 @@ const getMonitorById = async (monitorId) => {
const getMonitorsByTeamId = async (req) => { const getMonitorsByTeamId = async (req) => {
let { limit, type, page, rowsPerPage, filter, field, order } = req.query; let { limit, type, page, rowsPerPage, filter, field, order } = req.query;
// Parse ints
limit = parseInt(limit); limit = parseInt(limit);
page = parseInt(page); page = parseInt(page);
rowsPerPage = parseInt(rowsPerPage); rowsPerPage = parseInt(rowsPerPage);
@@ -571,54 +570,67 @@ const getMonitorsByTeamId = async (req) => {
{ $sort: sort }, { $sort: sort },
{ $skip: skip }, { $skip: skip },
...(rowsPerPage ? [{ $limit: rowsPerPage }] : []), ...(rowsPerPage ? [{ $limit: rowsPerPage }] : []),
{ ...(limit
$lookup: { ? [
from: "checks",
let: { monitorId: "$_id" },
pipeline: [
{ {
$match: { $lookup: {
$expr: { $eq: ["$monitorId", "$$monitorId"] }, from: "checks",
let: { monitorId: "$_id" },
pipeline: [
{
$match: {
$expr: { $eq: ["$monitorId", "$$monitorId"] },
},
},
{ $sort: { createdAt: -1 } },
...(limit ? [{ $limit: limit }] : []),
],
as: "standardchecks",
}, },
}, },
{ $sort: { createdAt: -1 } }, ]
...(limit ? [{ $limit: limit }] : []), : []),
], ...(limit
as: "standardchecks", ? [
},
},
{
$lookup: {
from: "pagespeedchecks",
let: { monitorId: "$_id" },
pipeline: [
{ {
$match: { $lookup: {
$expr: { $eq: ["$monitorId", "$$monitorId"] }, from: "pagespeedchecks",
let: { monitorId: "$_id" },
pipeline: [
{
$match: {
$expr: { $eq: ["$monitorId", "$$monitorId"] },
},
},
{ $sort: { createdAt: -1 } },
...(limit ? [{ $limit: limit }] : []),
],
as: "pagespeedchecks",
}, },
}, },
{ $sort: { createdAt: -1 } }, ]
...(limit ? [{ $limit: limit }] : []), : []),
], ...(limit
as: "pagespeedchecks", ? [
},
},
{
$lookup: {
from: "hardwarechecks",
let: { monitorId: "$_id" },
pipeline: [
{ {
$match: { $lookup: {
$expr: { $eq: ["$monitorId", "$$monitorId"] }, from: "hardwarechecks",
let: { monitorId: "$_id" },
pipeline: [
{
$match: {
$expr: { $eq: ["$monitorId", "$$monitorId"] },
},
},
{ $sort: { createdAt: -1 } },
...(limit ? [{ $limit: limit }] : []),
],
as: "hardwarechecks",
}, },
}, },
{ $sort: { createdAt: -1 } }, ]
...(limit ? [{ $limit: limit }] : []), : []),
],
as: "hardwarechecks",
},
},
{ {
$addFields: { $addFields: {
checks: { checks: {
@@ -662,6 +674,9 @@ const getMonitorsByTeamId = async (req) => {
let { monitors, summary } = results[0]; let { monitors, summary } = results[0];
monitors = monitors.map((monitor) => { monitors = monitors.map((monitor) => {
if (!monitor.checks) {
return monitor;
}
monitor.checks = NormalizeData(monitor.checks, 10, 100); monitor.checks = NormalizeData(monitor.checks, 10, 100);
return monitor; return monitor;
}); });