diff --git a/Client/src/Components/StatBox/index.jsx b/Client/src/Components/StatBox/index.jsx
index 953d378ec..b476a1c33 100644
--- a/Client/src/Components/StatBox/index.jsx
+++ b/Client/src/Components/StatBox/index.jsx
@@ -1,7 +1,7 @@
import { Box, Typography } from "@mui/material";
import { useTheme } from "@mui/material/styles";
import PropTypes from "prop-types";
-import useUtils from "../../Pages/Uptime/utils";
+import useUtils from "../../Pages/Uptime/Home/Hooks/useUtils";
/**
* StatBox Component
diff --git a/Client/src/Pages/Infrastructure/Details/index.jsx b/Client/src/Pages/Infrastructure/Details/index.jsx
index acd1bafb1..5da921e30 100644
--- a/Client/src/Pages/Infrastructure/Details/index.jsx
+++ b/Client/src/Pages/Infrastructure/Details/index.jsx
@@ -8,7 +8,7 @@ import AreaChart from "../../../Components/Charts/AreaChart";
import { useSelector } from "react-redux";
import { networkService } from "../../../main";
import PulseDot from "../../../Components/Animated/PulseDot";
-import useUtils from "../../Uptime/utils";
+import useUtils from "../../Uptime/Home/Hooks/useUtils";
import { useNavigate } from "react-router-dom";
import Empty from "./empty";
import { logger } from "../../../Utils/Logger";
diff --git a/Client/src/Pages/Infrastructure/index.jsx b/Client/src/Pages/Infrastructure/index.jsx
index 0bf367b99..43768132b 100644
--- a/Client/src/Pages/Infrastructure/index.jsx
+++ b/Client/src/Pages/Infrastructure/index.jsx
@@ -2,7 +2,7 @@ import { useEffect, useState, useCallback } from "react";
import { useNavigate } from "react-router-dom";
import { /* useDispatch, */ useSelector } from "react-redux";
import { useTheme } from "@emotion/react";
-import useUtils from "../Uptime/utils.jsx";
+import useUtils from "../Uptime/Home/Hooks/useUtils.jsx";
import { jwtDecode } from "jwt-decode";
import SkeletonLayout from "./skeleton";
import Fallback from "../../Components/Fallback";
@@ -17,7 +17,7 @@ import Pagination from "../../Components/Table/TablePagination/index.jsx";
// import { getInfrastructureMonitorsByTeamId } from "../../Features/InfrastructureMonitors/infrastructureMonitorsSlice";
import { networkService } from "../../Utils/NetworkService.js";
import CustomGauge from "../../Components/Charts/CustomGauge/index.jsx";
-import Host from "../Uptime/Home/host.jsx";
+import Host from "../Uptime/Home/Components/Host";
import { useIsAdmin } from "../../Hooks/useIsAdmin.js";
import { InfrastructureMenu } from "./components/Menu";
diff --git a/Client/src/Pages/PageSpeed/Configure/index.jsx b/Client/src/Pages/PageSpeed/Configure/index.jsx
index f7829ef35..eee6dfcc9 100644
--- a/Client/src/Pages/PageSpeed/Configure/index.jsx
+++ b/Client/src/Pages/PageSpeed/Configure/index.jsx
@@ -23,7 +23,7 @@ import PulseDot from "../../../Components/Animated/PulseDot";
import LoadingButton from "@mui/lab/LoadingButton";
import PlayCircleOutlineRoundedIcon from "@mui/icons-material/PlayCircleOutlineRounded";
import SkeletonLayout from "./skeleton";
-import useUtils from "../../Uptime/utils";
+import useUtils from "../../Uptime/Home/Hooks/useUtils";
import "./index.css";
import Dialog from "../../../Components/Dialog";
diff --git a/Client/src/Pages/PageSpeed/Details/index.jsx b/Client/src/Pages/PageSpeed/Details/index.jsx
index c5badbab8..9192faaa9 100644
--- a/Client/src/Pages/PageSpeed/Details/index.jsx
+++ b/Client/src/Pages/PageSpeed/Details/index.jsx
@@ -19,7 +19,7 @@ import PulseDot from "../../../Components/Animated/PulseDot";
import PagespeedDetailsAreaChart from "./Charts/AreaChart";
import Checkbox from "../../../Components/Inputs/Checkbox";
import PieChart from "./Charts/PieChart";
-import useUtils from "../../Uptime/utils";
+import useUtils from "../../Uptime/Home/Hooks/useUtils";
import "./index.css";
import { useIsAdmin } from "../../../Hooks/useIsAdmin";
import StatBox from "../../../Components/StatBox";
diff --git a/Client/src/Pages/PageSpeed/card.jsx b/Client/src/Pages/PageSpeed/card.jsx
index f5b0d7110..f7f6c4249 100644
--- a/Client/src/Pages/PageSpeed/card.jsx
+++ b/Client/src/Pages/PageSpeed/card.jsx
@@ -7,7 +7,7 @@ import { useTheme } from "@emotion/react";
import { Area, AreaChart, CartesianGrid, ResponsiveContainer, Tooltip } from "recharts";
import { useSelector } from "react-redux";
import { formatDateWithTz, formatDurationSplit } from "../../Utils/timeUtils";
-import useUtils from "../Uptime/utils";
+import useUtils from "../Uptime/Home/Hooks/useUtils";
import { useState } from "react";
import IconBox from "../../Components/IconBox";
/**
diff --git a/Client/src/Pages/Uptime/Details/index.jsx b/Client/src/Pages/Uptime/Details/index.jsx
index d5be671d3..be589c1ba 100644
--- a/Client/src/Pages/Uptime/Details/index.jsx
+++ b/Client/src/Pages/Uptime/Details/index.jsx
@@ -19,7 +19,7 @@ import PulseDot from "../../../Components/Animated/PulseDot";
import { ChartBox } from "./styled";
import SkeletonLayout from "./skeleton";
import "./index.css";
-import useUtils from "../utils";
+import useUtils from "../Home/Hooks/useUtils";
import { formatDateWithTz, formatDurationSplit } from "../../../Utils/timeUtils";
import { useIsAdmin } from "../../../Hooks/useIsAdmin";
import IconBox from "../../../Components/IconBox";
diff --git a/Client/src/Pages/Uptime/Home/Hooks/useDebounce.jsx b/Client/src/Pages/Uptime/Home/Hooks/useDebounce.jsx
new file mode 100644
index 000000000..11d639f14
--- /dev/null
+++ b/Client/src/Pages/Uptime/Home/Hooks/useDebounce.jsx
@@ -0,0 +1,18 @@
+import { useState, useEffect } from "react";
+
+const useDebounce = (value, delay) => {
+ const [debouncedValue, setDebouncedValue] = useState(value);
+
+ useEffect(() => {
+ const handler = setTimeout(() => {
+ setDebouncedValue(value);
+ }, delay);
+
+ return () => {
+ clearTimeout(handler);
+ };
+ }, [value, delay]);
+ return debouncedValue;
+};
+
+export default useDebounce;
diff --git a/Client/src/Pages/Uptime/Home/Hooks/useMonitorFetch.jsx b/Client/src/Pages/Uptime/Home/Hooks/useMonitorFetch.jsx
new file mode 100644
index 000000000..d4b7e5ba7
--- /dev/null
+++ b/Client/src/Pages/Uptime/Home/Hooks/useMonitorFetch.jsx
@@ -0,0 +1,98 @@
+import { useEffect, useState } from "react";
+import { networkService } from "../../../../main";
+import { createToast } from "../../../../Utils/toastUtils";
+import { useTheme } from "@emotion/react";
+const getMonitorWithPercentage = (monitor, theme) => {
+ let uptimePercentage = "";
+ let percentageColor = "";
+
+ if (monitor.uptimePercentage !== undefined) {
+ uptimePercentage =
+ monitor.uptimePercentage === 0 ? "0" : (monitor.uptimePercentage * 100).toFixed(2);
+
+ percentageColor =
+ monitor.uptimePercentage < 0.25
+ ? theme.palette.error.main
+ : monitor.uptimePercentage < 0.5
+ ? theme.palette.warning.main
+ : monitor.uptimePercentage < 0.75
+ ? theme.palette.success.main
+ : theme.palette.success.main;
+ }
+
+ return {
+ id: monitor._id,
+ name: monitor.name,
+ url: monitor.url,
+ title: monitor.name,
+ percentage: uptimePercentage,
+ percentageColor,
+ monitor: monitor,
+ };
+};
+
+export const useMonitorFetch = ({
+ authToken,
+ teamId,
+ limit,
+ page,
+ rowsPerPage,
+ filter,
+ field,
+ order,
+ triggerUpdate,
+}) => {
+ const [monitorsAreLoading, setMonitorsAreLoading] = useState(false);
+ const [monitors, setMonitors] = useState([]);
+ const [filteredMonitors, setFilteredMonitors] = useState([]);
+ const [monitorsSummary, setMonitorsSummary] = useState({});
+
+ const theme = useTheme();
+
+ useEffect(() => {
+ const fetchMonitors = async () => {
+ try {
+ setMonitorsAreLoading(true);
+ const res = await networkService.getMonitorsByTeamId({
+ authToken,
+ teamId,
+ limit,
+ types: ["http", "ping", "docker", "port"],
+ page,
+ rowsPerPage,
+ filter,
+ field,
+ order,
+ });
+ const { monitors, filteredMonitors, summary } = res.data.data;
+ const mappedMonitors = filteredMonitors.map((monitor) =>
+ getMonitorWithPercentage(monitor, theme)
+ );
+ setMonitors(monitors);
+ setFilteredMonitors(mappedMonitors);
+ setMonitorsSummary(summary);
+ } catch (error) {
+ createToast({
+ body: error.message,
+ });
+ } finally {
+ setMonitorsAreLoading(false);
+ }
+ };
+ fetchMonitors();
+ }, [
+ authToken,
+ teamId,
+ limit,
+ field,
+ filter,
+ order,
+ page,
+ rowsPerPage,
+ theme,
+ triggerUpdate,
+ ]);
+ return { monitors, filteredMonitors, monitorsSummary, monitorsAreLoading };
+};
+
+export default useMonitorFetch;
diff --git a/Client/src/Pages/Uptime/utils.jsx b/Client/src/Pages/Uptime/Home/Hooks/useUtils.jsx
similarity index 100%
rename from Client/src/Pages/Uptime/utils.jsx
rename to Client/src/Pages/Uptime/Home/Hooks/useUtils.jsx
diff --git a/Client/src/Pages/Uptime/Home/StatusBox.jsx b/Client/src/Pages/Uptime/Home/StatusBox.jsx
deleted file mode 100644
index d04ebdf5f..000000000
--- a/Client/src/Pages/Uptime/Home/StatusBox.jsx
+++ /dev/null
@@ -1,106 +0,0 @@
-import PropTypes from "prop-types";
-import { useTheme } from "@emotion/react";
-import { Box, Stack, Typography } from "@mui/material";
-import Arrow from "../../../assets/icons/top-right-arrow.svg?react";
-import Background from "../../../assets/Images/background-grid.svg?react";
-import ClockSnooze from "../../../assets/icons/clock-snooze.svg?react";
-
-const StatusBox = ({ title, value }) => {
- const theme = useTheme();
-
- let sharedStyles = {
- position: "absolute",
- right: 8,
- opacity: 0.5,
- "& svg path": { stroke: theme.palette.primary.contrastTextTertiary },
- };
-
- let color;
- let icon;
- if (title === "up") {
- color = theme.palette.success.lowContrast;
- icon = (
-
-
-
- );
- } else if (title === "down") {
- color = theme.palette.error.lowContrast;
- icon = (
-
-
-
- );
- } else if (title === "paused") {
- color = theme.palette.warning.lowContrast;
- icon = (
-
-
-
- );
- }
-
- return (
-
-
-
-
-
- {title}
-
- {icon}
-
- {value}
-
-
- #
-
-
-
- );
-};
-
-StatusBox.propTypes = {
- title: PropTypes.oneOf(["up", "down", "paused"]).isRequired,
- value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
-};
-
-export default StatusBox;
diff --git a/Client/src/Pages/Uptime/Home/UptimeDataTable/Skeleton/index.jsx b/Client/src/Pages/Uptime/Home/UptimeDataTable/Skeleton/index.jsx
deleted file mode 100644
index c17f6d74b..000000000
--- a/Client/src/Pages/Uptime/Home/UptimeDataTable/Skeleton/index.jsx
+++ /dev/null
@@ -1,47 +0,0 @@
-import { Skeleton } from "@mui/material";
-import DataTable from "../../../../../Components/Table";
-const ROWS_NUMBER = 7;
-const ROWS_ARRAY = Array.from({ length: ROWS_NUMBER }, (_, i) => i);
-
-const TableSkeleton = () => {
- /* TODO Skeleton does not follow light and dark theme */
-
- const headers = [
- {
- id: "name",
-
- content: "Host",
-
- render: () => ,
- },
- {
- id: "status",
- content: "Status",
- render: () => ,
- },
- {
- id: "responseTime",
- content: "Response Time",
- render: () => ,
- },
- {
- id: "type",
- content: "Type",
- render: () => ,
- },
- {
- id: "actions",
- content: "Actions",
- render: () => ,
- },
- ];
-
- return (
-
- );
-};
-
-export { TableSkeleton };
diff --git a/Client/src/Pages/Uptime/Home/UptimeDataTable/index.jsx b/Client/src/Pages/Uptime/Home/UptimeDataTable/index.jsx
deleted file mode 100644
index 6961c6d5c..000000000
--- a/Client/src/Pages/Uptime/Home/UptimeDataTable/index.jsx
+++ /dev/null
@@ -1,325 +0,0 @@
-// Components
-import { Box, Stack, CircularProgress } from "@mui/material";
-import Search from "../../../../Components/Inputs/Search";
-import { Heading } from "../../../../Components/Heading";
-import DataTable from "../../../../Components/Table";
-import ArrowDownwardRoundedIcon from "@mui/icons-material/ArrowDownwardRounded";
-import ArrowUpwardRoundedIcon from "@mui/icons-material/ArrowUpwardRounded";
-import Host from "../host";
-import { StatusLabel } from "../../../../Components/Label";
-import BarChart from "../../../../Components/Charts/BarChart";
-import ActionsMenu from "../actionsMenu";
-
-// Utils
-import { useTheme } from "@emotion/react";
-import useUtils from "../../utils";
-import { useState, memo, useCallback } from "react";
-import { useNavigate } from "react-router-dom";
-import "../index.css";
-import PropTypes from "prop-types";
-
-const SearchComponent = memo(
- ({ monitors, debouncedSearch, onSearchChange, setIsSearching }) => {
- const [localSearch, setLocalSearch] = useState(debouncedSearch);
- const handleSearch = useCallback(
- (value) => {
- setIsSearching(true);
- setLocalSearch(value);
- onSearchChange(value);
- },
- [onSearchChange, setIsSearching]
- );
-
- return (
-
-
-
- );
- }
-);
-SearchComponent.displayName = "SearchComponent";
-SearchComponent.propTypes = {
- monitors: PropTypes.array,
- debouncedSearch: PropTypes.string,
- onSearchChange: PropTypes.func,
- setIsSearching: PropTypes.func,
-};
-
-/**
- * UptimeDataTable displays a table of uptime monitors with sorting, searching, and action capabilities
- * @param {Object} props - Component props
- * @param {boolean} props.isAdmin - Whether the current user has admin privileges
- * @param {boolean} props.isLoading - Loading state of the table
- * @param {Array<{
- * _id: string,
- * url: string,
- * title: string,
- * percentage: number,
- * percentageColor: string,
- * monitor: {
- * _id: string,
- * type: string,
- * checks: Array
- * }
- * }>} props.monitors - Array of monitor objects to display
- * @param {number} props.monitorCount - Total count of monitors
- * @param {Object} props.sort - Current sort configuration
- * @param {string} props.sort.field - Field to sort by
- * @param {'asc'|'desc'} props.sort.order - Sort direction
- * @param {Function} props.setSort - Callback to update sort configuration
- * @param {string} props.search - Current search query
- * @param {Function} props.setSearch - Callback to update search query
- * @param {boolean} props.isSearching - Whether a search is in progress
- * @param {Function} props.setIsSearching - Callback to update search state
- * @param {Function} props.setIsLoading - Callback to update loading state
- * @param {Function} props.triggerUpdate - Callback to trigger a data refresh
- * @returns {JSX.Element} Rendered component
- */
-const UptimeDataTable = ({
- isAdmin,
- isLoading,
- monitors,
- filteredMonitors,
- monitorCount,
- sort,
- setSort,
- debouncedSearch,
- setSearch,
- isSearching,
- setIsSearching,
- setIsLoading,
- triggerUpdate,
-}) => {
- const { determineState } = useUtils();
-
- const theme = useTheme();
- const navigate = useNavigate();
-
- const handleSort = (field) => {
- let order = "";
- if (sort.field !== field) {
- order = "desc";
- } else {
- order = sort.order === "asc" ? "desc" : "asc";
- }
- setSort({ field, order });
- };
-
- const headers = [
- {
- id: "name",
- content: (
- handleSort("name")}
- >
- Host
-
- {sort.order === "asc" ? (
-
- ) : (
-
- )}
-
-
- ),
- render: (row) => (
-
- ),
- },
- {
- id: "status",
- content: (
- handleSort("status")}
- >
- {" "}
- Status
-
- {sort.order === "asc" ? (
-
- ) : (
-
- )}
-
-
- ),
- render: (row) => {
- const status = determineState(row.monitor);
- return (
-
- );
- },
- },
- {
- id: "responseTime",
- content: "Response Time",
- render: (row) => ,
- },
- {
- id: "type",
- content: "Type",
- render: (row) => (
- {row.monitor.type}
- ),
- },
- {
- id: "actions",
- content: "Actions",
- render: (row) => (
-
- ),
- },
- ];
-
- return (
-
-
- Uptime monitors
- {/* TODO Same as the one in Infrastructure. Create component */}
-
- {monitorCount}
-
-
-
-
-
- {(isSearching || isLoading) && (
- <>
-
-
-
-
- >
- )}
- {
- navigate(`/uptime/${row.id}`);
- },
- emptyView: "No monitors found",
- }}
- />
-
-
- );
-};
-
-const MemoizedUptimeDataTable = memo(UptimeDataTable);
-export default MemoizedUptimeDataTable;
-
-UptimeDataTable.propTypes = {
- isAdmin: PropTypes.bool,
- isLoading: PropTypes.bool,
- monitors: PropTypes.array,
- filteredMonitors: PropTypes.array,
- monitorCount: PropTypes.number,
- sort: PropTypes.shape({
- field: PropTypes.string,
- order: PropTypes.oneOf(["asc", "desc"]),
- }),
- setSort: PropTypes.func,
- debouncedSearch: PropTypes.string,
- setSearch: PropTypes.func,
- isSearching: PropTypes.bool,
- setIsSearching: PropTypes.func,
- setIsLoading: PropTypes.func,
- triggerUpdate: PropTypes.func,
-};
diff --git a/Client/src/Pages/Uptime/Home/actionsMenu.jsx b/Client/src/Pages/Uptime/Home/actionsMenu.jsx
deleted file mode 100644
index 493c5f25e..000000000
--- a/Client/src/Pages/Uptime/Home/actionsMenu.jsx
+++ /dev/null
@@ -1,240 +0,0 @@
-import { useState } from "react";
-import { useSelector, useDispatch } from "react-redux";
-import { useTheme } from "@emotion/react";
-import { useNavigate } from "react-router-dom";
-import { createToast } from "../../../Utils/toastUtils";
-import { logger } from "../../../Utils/Logger";
-import { IconButton, Menu, MenuItem } from "@mui/material";
-import {
- deleteUptimeMonitor,
- pauseUptimeMonitor,
-} from "../../../Features/UptimeMonitors/uptimeMonitorsSlice";
-import Settings from "../../../assets/icons/settings-bold.svg?react";
-import PropTypes from "prop-types";
-import Dialog from "../../../Components/Dialog";
-
-const ActionsMenu = ({
- monitor,
- isAdmin,
- updateRowCallback,
- pauseCallback,
- setIsLoading,
-}) => {
- const [anchorEl, setAnchorEl] = useState(null);
- const [actions, setActions] = useState({});
- const [isOpen, setIsOpen] = useState(false);
- const dispatch = useDispatch();
- const theme = useTheme();
- const authState = useSelector((state) => state.auth);
- const authToken = authState.authToken;
- const { isLoading } = useSelector((state) => state.uptimeMonitors);
-
- const handleRemove = async (event) => {
- event.preventDefault();
- event.stopPropagation();
- let monitor = { _id: actions.id };
- const action = await dispatch(
- deleteUptimeMonitor({ authToken: authState.authToken, monitor })
- );
- if (action.meta.requestStatus === "fulfilled") {
- setIsOpen(false); // close modal
- updateRowCallback();
- createToast({ body: "Monitor deleted successfully." });
- } else {
- createToast({ body: "Failed to delete monitor." });
- }
- };
-
- const handlePause = async () => {
- try {
- setIsLoading(true);
- const action = await dispatch(
- pauseUptimeMonitor({ authToken, monitorId: monitor._id })
- );
- if (pauseUptimeMonitor.fulfilled.match(action)) {
- const state = action?.payload?.data.isActive === false ? "paused" : "resumed";
- createToast({ body: `Monitor ${state} successfully.` });
- pauseCallback();
- } else {
- throw new Error(action?.error?.message ?? "Failed to pause monitor.");
- }
- } catch (error) {
- logger.error("Error pausing monitor:", monitor._id, error);
- createToast({ body: "Failed to pause monitor." });
- }
- };
-
- const openMenu = (event, id, url) => {
- event.preventDefault();
- event.stopPropagation();
- setAnchorEl(event.currentTarget);
- setActions({ id: id, url: url });
- };
-
- const openRemove = (e) => {
- closeMenu(e);
- setIsOpen(true);
- };
-
- const closeMenu = (e) => {
- e.stopPropagation();
- setAnchorEl(null);
- };
-
- const navigate = useNavigate();
- return (
- <>
- {
- event.stopPropagation();
- openMenu(event, monitor._id, monitor.type === "ping" ? null : monitor.url);
- }}
- sx={{
- "&:focus": {
- outline: "none",
- },
- "& svg path": {
- stroke: theme.palette.primary.contrastTextTertiary,
- },
- }}
- >
-
-
-
-
-