mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-01-21 00:59:44 -06:00
Merge pull request #2449 from bluewave-labs/fix/status-page-on-monitor-delete
fix/status page on monitor delete
This commit is contained in:
@@ -11,7 +11,7 @@ import { useSelector } from "react-redux";
|
||||
import Alert from "../Alert";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import "./index.css";
|
||||
import { useFetchSettings } from "../../Hooks/useFetchSettings";
|
||||
import { useFetchSettings } from "../../Hooks/settingsHooks";
|
||||
import { useState } from "react";
|
||||
/**
|
||||
* Fallback component to display a fallback UI with a title, a list of checks, and a navigation button.
|
||||
|
||||
@@ -5,7 +5,7 @@ import Button from "@mui/material/Button";
|
||||
import TextInput from "../../../Components/Inputs/TextInput";
|
||||
import { PasswordEndAdornment } from "../../../Components/Inputs/TextInput/Adornments";
|
||||
import { loginCredentials } from "../../../Validation/validation";
|
||||
import TextLink from "../components/TextLink";
|
||||
import TextLink from "../../../Components/TextLink";
|
||||
import Typography from "@mui/material/Typography";
|
||||
|
||||
// Utils
|
||||
|
||||
@@ -18,7 +18,7 @@ import { useSelector, useDispatch } from "react-redux";
|
||||
import { setTimezone, setMode, setLanguage, setShowURL } from "../../Features/UI/uiSlice";
|
||||
import SettingsStats from "./SettingsStats";
|
||||
|
||||
import { useFetchSettings, useSaveSettings } from "../../Hooks/useFetchSettings";
|
||||
import { useFetchSettings, useSaveSettings } from "../../Hooks/settingsHooks";
|
||||
import { useIsAdmin } from "../../Hooks/useIsAdmin";
|
||||
import {
|
||||
useAddDemoMonitors,
|
||||
|
||||
@@ -8,6 +8,7 @@ import StatusBar from "./Components/StatusBar";
|
||||
import MonitorsList from "./Components/MonitorsList";
|
||||
import Dialog from "../../../Components/Dialog";
|
||||
import Breadcrumbs from "../../../Components/Breadcrumbs/index.jsx";
|
||||
import TextLink from "../../../Components/TextLink";
|
||||
|
||||
// Utils
|
||||
import { useStatusPageFetch } from "./Hooks/useStatusPageFetch";
|
||||
@@ -30,6 +31,7 @@ const PublicStatus = () => {
|
||||
const { t } = useTranslation();
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
const isAdmin = useIsAdmin();
|
||||
|
||||
const [statusPage, monitors, isLoading, networkError, fetchStatusPage] =
|
||||
useStatusPageFetch(false, url);
|
||||
@@ -60,6 +62,26 @@ const PublicStatus = () => {
|
||||
return <SkeletonLayout />;
|
||||
}
|
||||
|
||||
if (monitors.length === 0) {
|
||||
return (
|
||||
<GenericFallback>
|
||||
<Typography
|
||||
variant="h1"
|
||||
marginY={theme.spacing(4)}
|
||||
color={theme.palette.primary.contrastTextTertiary}
|
||||
>
|
||||
{"Theres nothing here yet"}
|
||||
</Typography>
|
||||
{isAdmin && (
|
||||
<TextLink
|
||||
linkText={"Add a monitor to get started"}
|
||||
href={`/status/uptime/configure/${url}`}
|
||||
/>
|
||||
)}
|
||||
</GenericFallback>
|
||||
);
|
||||
}
|
||||
|
||||
// Error fetching data
|
||||
if (networkError === true) {
|
||||
return (
|
||||
|
||||
@@ -142,8 +142,7 @@ const CreateMonitor = () => {
|
||||
notifications: monitor.notifications,
|
||||
};
|
||||
|
||||
console.log(JSON.stringify(form, null, 2));
|
||||
// await createMonitor({ monitor: form, redirect: "/uptime" });
|
||||
await createMonitor({ monitor: form, redirect: "/uptime" });
|
||||
};
|
||||
|
||||
const onChange = (event) => {
|
||||
|
||||
@@ -3,6 +3,7 @@ import HardwareCheck from "./HardwareCheck.js";
|
||||
import PageSpeedCheck from "./PageSpeedCheck.js";
|
||||
import Check from "./Check.js";
|
||||
import MonitorStats from "./MonitorStats.js";
|
||||
import StatusPage from "./StatusPage.js";
|
||||
|
||||
const MonitorSchema = mongoose.Schema(
|
||||
{
|
||||
@@ -105,6 +106,9 @@ MonitorSchema.pre("findOneAndDelete", async function (next) {
|
||||
await Check.deleteMany({ monitorId: doc._id });
|
||||
}
|
||||
|
||||
// Deal with status pages
|
||||
await StatusPage.updateMany({ monitors: doc._id }, { $pull: { monitors: doc._id } });
|
||||
|
||||
await MonitorStats.deleteMany({ monitorId: doc._id.toString() });
|
||||
next();
|
||||
} catch (error) {
|
||||
|
||||
@@ -710,9 +710,11 @@ const deleteMonitor = async ({ monitorId }) => {
|
||||
const stringService = ServiceRegistry.get(StringService.SERVICE_NAME);
|
||||
try {
|
||||
const monitor = await Monitor.findByIdAndDelete(monitorId);
|
||||
|
||||
if (!monitor) {
|
||||
throw new Error(stringService.getDbFindMonitorById(monitorId));
|
||||
}
|
||||
|
||||
return monitor;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
|
||||
@@ -106,7 +106,10 @@ const getStatusPage = async (url) => {
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: "$monitors",
|
||||
$unwind: {
|
||||
path: "$monitors",
|
||||
preserveNullAndEmptyArrays: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
@@ -153,9 +156,17 @@ const getStatusPage = async (url) => {
|
||||
url: 1,
|
||||
},
|
||||
monitors: {
|
||||
$sortArray: {
|
||||
input: "$monitors",
|
||||
sortBy: { orderIndex: 1 },
|
||||
$filter: {
|
||||
input: {
|
||||
$sortArray: {
|
||||
input: "$monitors",
|
||||
sortBy: { orderIndex: 1 },
|
||||
},
|
||||
},
|
||||
as: "monitor",
|
||||
cond: {
|
||||
$ne: ["$$monitor.orderIndex", -1],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user