early return if status page public and not published

This commit is contained in:
Alex Holliday committed 2025-02-08 08:05:42 -08:00
1 parent 1fabf918c3
commit 2f1f2d1a3f
3 files changed
+12 -6

No files matched your search

@@ -45,7 +45,7 @@ const getRandomDevice = () => {
model: randomModel, model: randomModel,
}; };
}; };
const useSubscribeToDetails = ({ monitorId, dateRange }) => { const useSubscribeToDetails = ({ monitorId, isPublic, isPublished, dateRange }) => {
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
const [connectionStatus, setConnectionStatus] = useState(undefined); const [connectionStatus, setConnectionStatus] = useState(undefined);
const [retryCount, setRetryCount] = useState(0); const [retryCount, setRetryCount] = useState(0);
@@ -58,10 +58,15 @@ const useSubscribeToDetails = ({ monitorId, dateRange }) => {
const prevDateRangeRef = useRef(dateRange); const prevDateRangeRef = useRef(dateRange);
useEffect(() => { useEffect(() => {
if (typeof monitorId === "undefined") {
return;
}
// If this page is public and not published, don't subscribe to details
if (isPublic && isPublished === false) {
return;
}
try { try {
if (typeof monitorId === "undefined") {
return;
}
const cleanup = networkService.subscribeToDistributedUptimeDetails({ const cleanup = networkService.subscribeToDistributedUptimeDetails({
authToken, authToken,
monitorId, monitorId,
@@ -8,6 +8,7 @@ const useStatusPageFetchByUrl = ({ url }) => {
const [networkError, setNetworkError] = useState(false); const [networkError, setNetworkError] = useState(false);
const [statusPage, setStatusPage] = useState(undefined); const [statusPage, setStatusPage] = useState(undefined);
const [monitorId, setMonitorId] = useState(undefined); const [monitorId, setMonitorId] = useState(undefined);
const [isPublished, setIsPublished] = useState(false);
const { authToken } = useSelector((state) => state.auth); const { authToken } = useSelector((state) => state.auth);
useEffect(() => { useEffect(() => {
const fetchStatusPageByUrl = async () => { const fetchStatusPageByUrl = async () => {
@@ -17,6 +18,7 @@ const useStatusPageFetchByUrl = ({ url }) => {
const statusPage = response.data.data; const statusPage = response.data.data;
setStatusPage(statusPage); setStatusPage(statusPage);
setMonitorId(statusPage?.monitors[0]); setMonitorId(statusPage?.monitors[0]);
setIsPublished(statusPage?.isPublished);
} catch (error) { } catch (error) {
setNetworkError(true); setNetworkError(true);
createToast({ createToast({
@@ -29,7 +31,7 @@ const useStatusPageFetchByUrl = ({ url }) => {
fetchStatusPageByUrl(); fetchStatusPageByUrl();
}, [authToken, url]); }, [authToken, url]);
return [isLoading, networkError, statusPage, monitorId]; return [isLoading, networkError, statusPage, monitorId, isPublished];
}; };
export { useStatusPageFetchByUrl }; export { useStatusPageFetchByUrl };
@@ -1,7 +1,6 @@
import { handleError } from "./controllerUtils.js"; import { handleError } from "./controllerUtils.js";
import Monitor from "../db/models/Monitor.js"; import Monitor from "../db/models/Monitor.js";
import DistributedUptimeCheck from "../db/models/DistributedUptimeCheck.js"; import DistributedUptimeCheck from "../db/models/DistributedUptimeCheck.js";
const SERVICE_NAME = "DistributedUptimeQueueController"; const SERVICE_NAME = "DistributedUptimeQueueController";
class DistributedUptimeController { class DistributedUptimeController {