Merge pull request #2449 from bluewave-labs/fix/status-page-on-monitor-delete
fix/status page on monitor delete
This commit is contained in:
10 files changed
+47
-9
No files matched your search
@@ -11,7 +11,7 @@ import { useSelector } from "react-redux";
|
|||||||
import Alert from "../Alert";
|
import Alert from "../Alert";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
import { useFetchSettings } from "../../Hooks/useFetchSettings";
|
import { useFetchSettings } from "../../Hooks/settingsHooks";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
/**
|
/**
|
||||||
* Fallback component to display a fallback UI with a title, a list of checks, and a navigation button.
|
* Fallback component to display a fallback UI with a title, a list of checks, and a navigation button.
|
||||||
|
|||||||
File renamed without changes.
File renamed without changes.
@@ -5,7 +5,7 @@ import Button from "@mui/material/Button";
|
|||||||
import TextInput from "../../../Components/Inputs/TextInput";
|
import TextInput from "../../../Components/Inputs/TextInput";
|
||||||
import { PasswordEndAdornment } from "../../../Components/Inputs/TextInput/Adornments";
|
import { PasswordEndAdornment } from "../../../Components/Inputs/TextInput/Adornments";
|
||||||
import { loginCredentials } from "../../../Validation/validation";
|
import { loginCredentials } from "../../../Validation/validation";
|
||||||
import TextLink from "../components/TextLink";
|
import TextLink from "../../../Components/TextLink";
|
||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import { useSelector, useDispatch } from "react-redux";
|
|||||||
import { setTimezone, setMode, setLanguage, setShowURL } from "../../Features/UI/uiSlice";
|
import { setTimezone, setMode, setLanguage, setShowURL } from "../../Features/UI/uiSlice";
|
||||||
import SettingsStats from "./SettingsStats";
|
import SettingsStats from "./SettingsStats";
|
||||||
|
|
||||||
import { useFetchSettings, useSaveSettings } from "../../Hooks/useFetchSettings";
|
import { useFetchSettings, useSaveSettings } from "../../Hooks/settingsHooks";
|
||||||
import { useIsAdmin } from "../../Hooks/useIsAdmin";
|
import { useIsAdmin } from "../../Hooks/useIsAdmin";
|
||||||
import {
|
import {
|
||||||
useAddDemoMonitors,
|
useAddDemoMonitors,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import StatusBar from "./Components/StatusBar";
|
|||||||
import MonitorsList from "./Components/MonitorsList";
|
import MonitorsList from "./Components/MonitorsList";
|
||||||
import Dialog from "../../../Components/Dialog";
|
import Dialog from "../../../Components/Dialog";
|
||||||
import Breadcrumbs from "../../../Components/Breadcrumbs/index.jsx";
|
import Breadcrumbs from "../../../Components/Breadcrumbs/index.jsx";
|
||||||
|
import TextLink from "../../../Components/TextLink";
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
import { useStatusPageFetch } from "./Hooks/useStatusPageFetch";
|
import { useStatusPageFetch } from "./Hooks/useStatusPageFetch";
|
||||||
@@ -30,6 +31,7 @@ const PublicStatus = () => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const isAdmin = useIsAdmin();
|
||||||
|
|
||||||
const [statusPage, monitors, isLoading, networkError, fetchStatusPage] =
|
const [statusPage, monitors, isLoading, networkError, fetchStatusPage] =
|
||||||
useStatusPageFetch(false, url);
|
useStatusPageFetch(false, url);
|
||||||
@@ -60,6 +62,26 @@ const PublicStatus = () => {
|
|||||||
return <SkeletonLayout />;
|
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
|
// Error fetching data
|
||||||
if (networkError === true) {
|
if (networkError === true) {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -142,8 +142,7 @@ const CreateMonitor = () => {
|
|||||||
notifications: monitor.notifications,
|
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) => {
|
const onChange = (event) => {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import HardwareCheck from "./HardwareCheck.js";
|
|||||||
import PageSpeedCheck from "./PageSpeedCheck.js";
|
import PageSpeedCheck from "./PageSpeedCheck.js";
|
||||||
import Check from "./Check.js";
|
import Check from "./Check.js";
|
||||||
import MonitorStats from "./MonitorStats.js";
|
import MonitorStats from "./MonitorStats.js";
|
||||||
|
import StatusPage from "./StatusPage.js";
|
||||||
|
|
||||||
const MonitorSchema = mongoose.Schema(
|
const MonitorSchema = mongoose.Schema(
|
||||||
{
|
{
|
||||||
@@ -105,6 +106,9 @@ MonitorSchema.pre("findOneAndDelete", async function (next) {
|
|||||||
await Check.deleteMany({ monitorId: doc._id });
|
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() });
|
await MonitorStats.deleteMany({ monitorId: doc._id.toString() });
|
||||||
next();
|
next();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -710,9 +710,11 @@ const deleteMonitor = async ({ monitorId }) => {
|
|||||||
const stringService = ServiceRegistry.get(StringService.SERVICE_NAME);
|
const stringService = ServiceRegistry.get(StringService.SERVICE_NAME);
|
||||||
try {
|
try {
|
||||||
const monitor = await Monitor.findByIdAndDelete(monitorId);
|
const monitor = await Monitor.findByIdAndDelete(monitorId);
|
||||||
|
|
||||||
if (!monitor) {
|
if (!monitor) {
|
||||||
throw new Error(stringService.getDbFindMonitorById(monitorId));
|
throw new Error(stringService.getDbFindMonitorById(monitorId));
|
||||||
}
|
}
|
||||||
|
|
||||||
return monitor;
|
return monitor;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
error.service = SERVICE_NAME;
|
error.service = SERVICE_NAME;
|
||||||
|
|||||||
@@ -106,7 +106,10 @@ const getStatusPage = async (url) => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$unwind: "$monitors",
|
$unwind: {
|
||||||
|
path: "$monitors",
|
||||||
|
preserveNullAndEmptyArrays: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$lookup: {
|
$lookup: {
|
||||||
@@ -153,9 +156,17 @@ const getStatusPage = async (url) => {
|
|||||||
url: 1,
|
url: 1,
|
||||||
},
|
},
|
||||||
monitors: {
|
monitors: {
|
||||||
$sortArray: {
|
$filter: {
|
||||||
input: "$monitors",
|
input: {
|
||||||
sortBy: { orderIndex: 1 },
|
$sortArray: {
|
||||||
|
input: "$monitors",
|
||||||
|
sortBy: { orderIndex: 1 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
as: "monitor",
|
||||||
|
cond: {
|
||||||
|
$ne: ["$$monitor.orderIndex", -1],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in new issue
Block a user