2024-08-27 15:18:18 -07:00
|
|
|
import "./index.css";
|
2024-09-18 17:22:58 -04:00
|
|
|
import { useEffect, useState } from "react";
|
2024-08-27 15:18:18 -07:00
|
|
|
import { useSelector, useDispatch } from "react-redux";
|
|
|
|
|
import { getUptimeMonitorsByTeamId } from "../../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
|
|
|
|
import { useNavigate } from "react-router-dom";
|
|
|
|
|
import { useTheme } from "@emotion/react";
|
2024-10-18 15:45:50 -04:00
|
|
|
import { Box, Button, Stack, Typography } from "@mui/material";
|
2024-08-27 15:18:18 -07:00
|
|
|
import PropTypes from "prop-types";
|
|
|
|
|
import SkeletonLayout from "./skeleton";
|
|
|
|
|
import Fallback from "./fallback";
|
2024-08-27 19:46:09 -07:00
|
|
|
import StatusBox from "./StatusBox";
|
2024-08-28 10:28:02 -04:00
|
|
|
import Breadcrumbs from "../../../Components/Breadcrumbs";
|
2024-08-30 13:20:36 -04:00
|
|
|
import Greeting from "../../../Utils/greeting";
|
2024-09-04 16:15:14 -07:00
|
|
|
import MonitorTable from "./MonitorTable";
|
2024-09-18 17:14:03 -04:00
|
|
|
import Search from "../../../Components/Inputs/Search";
|
2024-09-19 11:07:38 +08:00
|
|
|
import useDebounce from "../../../Utils/debounce";
|
2024-08-27 15:18:18 -07:00
|
|
|
|
|
|
|
|
const Monitors = ({ isAdmin }) => {
|
2024-10-16 21:48:13 -04:00
|
|
|
const theme = useTheme();
|
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
const monitorState = useSelector((state) => state.uptimeMonitors);
|
|
|
|
|
const authState = useSelector((state) => state.auth);
|
2024-10-18 14:49:48 -04:00
|
|
|
const dispatch = useDispatch({});
|
|
|
|
|
|
|
|
|
|
//TODO create components, and lower these states.
|
2024-10-16 21:48:13 -04:00
|
|
|
const [search, setSearch] = useState("");
|
|
|
|
|
const [isSearching, setIsSearching] = useState(false);
|
|
|
|
|
const debouncedFilter = useDebounce(search, 500);
|
2024-08-27 15:18:18 -07:00
|
|
|
|
2024-10-16 21:48:13 -04:00
|
|
|
const handleSearch = (value) => {
|
|
|
|
|
setIsSearching(true);
|
|
|
|
|
setSearch(value);
|
|
|
|
|
};
|
2024-09-19 00:31:46 -04:00
|
|
|
|
2024-10-16 21:48:13 -04:00
|
|
|
useEffect(() => {
|
|
|
|
|
dispatch(getUptimeMonitorsByTeamId(authState.authToken));
|
|
|
|
|
}, [authState.authToken, dispatch]);
|
2024-09-19 00:31:46 -04:00
|
|
|
|
2024-10-18 15:45:50 -04:00
|
|
|
const loading = monitorState?.isLoading;
|
2024-09-18 17:14:03 -04:00
|
|
|
|
2024-10-18 15:45:50 -04:00
|
|
|
const totalMonitors = monitorState?.monitorsSummary?.monitorCounts?.total;
|
|
|
|
|
const isTotalMonitorsUndefined = totalMonitors === undefined;
|
|
|
|
|
const hasMonitors = !isTotalMonitorsUndefined && totalMonitors !== 0;
|
|
|
|
|
const noMonitors = isTotalMonitorsUndefined || totalMonitors === 0;
|
2024-10-18 14:49:48 -04:00
|
|
|
const canAddMonitor = isAdmin && hasMonitors;
|
|
|
|
|
const needsAdmin = !isAdmin && noMonitors;
|
|
|
|
|
|
2024-10-16 21:48:13 -04:00
|
|
|
return (
|
|
|
|
|
<Stack
|
|
|
|
|
className="monitors"
|
|
|
|
|
gap={theme.spacing(8)}
|
|
|
|
|
>
|
|
|
|
|
<Box>
|
|
|
|
|
<Breadcrumbs list={[{ name: `monitors`, path: "/monitors" }]} />
|
|
|
|
|
<Stack
|
|
|
|
|
direction="row"
|
|
|
|
|
justifyContent="space-between"
|
|
|
|
|
alignItems="center"
|
|
|
|
|
mt={theme.spacing(5)}
|
2024-10-16 21:57:41 -04:00
|
|
|
gap={theme.spacing(6)}
|
2024-10-16 21:48:13 -04:00
|
|
|
>
|
|
|
|
|
<Greeting type="uptime" />
|
2024-10-18 14:49:48 -04:00
|
|
|
{canAddMonitor && (
|
2024-10-16 21:48:13 -04:00
|
|
|
<Button
|
|
|
|
|
variant="contained"
|
|
|
|
|
color="primary"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
navigate("/monitors/create");
|
|
|
|
|
}}
|
|
|
|
|
sx={{ fontWeight: 500 }}
|
|
|
|
|
>
|
|
|
|
|
Create monitor
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
</Stack>
|
|
|
|
|
</Box>
|
2024-10-18 14:49:48 -04:00
|
|
|
{noMonitors && <Fallback isAdmin={isAdmin} />}
|
|
|
|
|
{needsAdmin && <p>Wait for an admin to add some monitors!</p>}
|
2024-10-16 21:48:13 -04:00
|
|
|
{loading ? (
|
|
|
|
|
<SkeletonLayout />
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
2024-10-18 14:49:48 -04:00
|
|
|
{hasMonitors && (
|
2024-10-16 21:48:13 -04:00
|
|
|
<>
|
|
|
|
|
<Stack
|
|
|
|
|
gap={theme.spacing(8)}
|
|
|
|
|
direction="row"
|
|
|
|
|
justifyContent="space-between"
|
|
|
|
|
>
|
|
|
|
|
<StatusBox
|
|
|
|
|
title="up"
|
|
|
|
|
value={monitorState?.monitorsSummary?.monitorCounts?.up ?? 0}
|
|
|
|
|
/>
|
|
|
|
|
<StatusBox
|
|
|
|
|
title="down"
|
|
|
|
|
value={monitorState?.monitorsSummary?.monitorCounts?.down ?? 0}
|
|
|
|
|
/>
|
|
|
|
|
<StatusBox
|
|
|
|
|
title="paused"
|
|
|
|
|
value={monitorState?.monitorsSummary?.monitorCounts?.paused ?? 0}
|
|
|
|
|
/>
|
|
|
|
|
</Stack>
|
|
|
|
|
<Box
|
|
|
|
|
flex={1}
|
|
|
|
|
px={theme.spacing(10)}
|
|
|
|
|
py={theme.spacing(8)}
|
|
|
|
|
border={1}
|
|
|
|
|
borderColor={theme.palette.border.light}
|
|
|
|
|
borderRadius={theme.shape.borderRadius}
|
|
|
|
|
backgroundColor={theme.palette.background.main}
|
|
|
|
|
>
|
|
|
|
|
<Stack
|
|
|
|
|
direction="row"
|
|
|
|
|
alignItems="center"
|
|
|
|
|
mb={theme.spacing(8)}
|
|
|
|
|
>
|
|
|
|
|
<Typography
|
|
|
|
|
component="h2"
|
|
|
|
|
variant="h2"
|
|
|
|
|
fontWeight={500}
|
|
|
|
|
letterSpacing={-0.2}
|
|
|
|
|
>
|
|
|
|
|
Actively monitoring
|
|
|
|
|
</Typography>
|
|
|
|
|
<Box
|
|
|
|
|
className="current-monitors-counter"
|
|
|
|
|
color={theme.palette.text.primary}
|
|
|
|
|
border={1}
|
|
|
|
|
borderColor={theme.palette.border.light}
|
|
|
|
|
backgroundColor={theme.palette.background.accent}
|
|
|
|
|
>
|
2024-10-18 15:45:50 -04:00
|
|
|
{totalMonitors}
|
2024-10-16 21:48:13 -04:00
|
|
|
</Box>
|
|
|
|
|
<Box
|
|
|
|
|
width="25%"
|
|
|
|
|
minWidth={150}
|
|
|
|
|
ml="auto"
|
|
|
|
|
>
|
|
|
|
|
<Search
|
2024-10-18 15:45:50 -04:00
|
|
|
options={monitorState.monitorsSummary.monitors}
|
2024-10-16 21:48:13 -04:00
|
|
|
filteredBy="name"
|
|
|
|
|
inputValue={search}
|
|
|
|
|
handleInputChange={handleSearch}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
</Stack>
|
2024-10-18 15:45:50 -04:00
|
|
|
<MonitorTable
|
|
|
|
|
isAdmin={isAdmin}
|
|
|
|
|
filter={debouncedFilter}
|
|
|
|
|
setLoading={setIsSearching}
|
|
|
|
|
isSearching={isSearching}
|
|
|
|
|
/>
|
2024-10-16 21:48:13 -04:00
|
|
|
</Box>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</Stack>
|
|
|
|
|
);
|
2024-08-27 15:18:18 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Monitors.propTypes = {
|
2024-10-16 21:48:13 -04:00
|
|
|
isAdmin: PropTypes.bool,
|
2024-08-27 15:18:18 -07:00
|
|
|
};
|
|
|
|
|
export default Monitors;
|