add timeframe header and monitorslist
This commit is contained in:
1 parent
395d7412eb
commit
105b4e124f
4 files changed
+137
-6
No files matched your search
@@ -0,0 +1,66 @@
|
|||||||
|
// Components
|
||||||
|
import { Stack, Box } from "@mui/material";
|
||||||
|
import Host from "../../../../../Components/Host";
|
||||||
|
import DePINStatusPageBarChart from "../../../../../Components/Charts/DePINStatusPageBarChart";
|
||||||
|
import { StatusLabel } from "../../../../../Components/Label";
|
||||||
|
|
||||||
|
//Utils
|
||||||
|
import { useTheme } from "@mui/material/styles";
|
||||||
|
import useUtils from "../../../../Uptime/Monitors/Hooks/useUtils";
|
||||||
|
import PropTypes from "prop-types";
|
||||||
|
const MonitorsList = ({
|
||||||
|
isLoading = false,
|
||||||
|
shouldRender = true,
|
||||||
|
monitors = [],
|
||||||
|
timeFrame,
|
||||||
|
}) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const { determineState } = useUtils();
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{monitors?.map((monitor) => {
|
||||||
|
const status = determineState(monitor);
|
||||||
|
return (
|
||||||
|
<Stack
|
||||||
|
key={monitor._id}
|
||||||
|
width="100%"
|
||||||
|
gap={theme.spacing(2)}
|
||||||
|
>
|
||||||
|
<Host
|
||||||
|
key={monitor._id}
|
||||||
|
url={monitor.url}
|
||||||
|
title={monitor.name}
|
||||||
|
percentageColor={monitor.percentageColor}
|
||||||
|
percentage={monitor.percentage}
|
||||||
|
/>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
alignItems="center"
|
||||||
|
gap={theme.spacing(20)}
|
||||||
|
>
|
||||||
|
<Box flex={9}>
|
||||||
|
<DePINStatusPageBarChart
|
||||||
|
checks={monitor?.checks?.slice().reverse()}
|
||||||
|
daysToShow={timeFrame}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
<Box flex={1}>
|
||||||
|
<StatusLabel
|
||||||
|
status={status}
|
||||||
|
text={status}
|
||||||
|
customStyles={{ textTransform: "capitalize" }}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
MonitorsList.propTypes = {
|
||||||
|
monitors: PropTypes.array.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default MonitorsList;
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import { Stack, Button, ButtonGroup } from "@mui/material";
|
||||||
|
import { RowContainer } from "../../../../../Components/StandardContainer";
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
|
||||||
|
const TimeFrameHeader = ({ timeFrame, setTimeFrame }) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
return (
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
justifyContent="flex-end"
|
||||||
|
>
|
||||||
|
<ButtonGroup>
|
||||||
|
<Button
|
||||||
|
variant="group"
|
||||||
|
filled={(timeFrame === 30).toString()}
|
||||||
|
onClick={() => setTimeFrame(30)}
|
||||||
|
>
|
||||||
|
30 days
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="group"
|
||||||
|
filled={(timeFrame === 60).toString()}
|
||||||
|
onClick={() => setTimeFrame(60)}
|
||||||
|
>
|
||||||
|
60 days
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="group"
|
||||||
|
filled={(timeFrame === 90).toString()}
|
||||||
|
onClick={() => setTimeFrame(90)}
|
||||||
|
>
|
||||||
|
90 days
|
||||||
|
</Button>
|
||||||
|
</ButtonGroup>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TimeFrameHeader;
|
||||||
@@ -2,25 +2,41 @@ import { useState, useEffect } from "react";
|
|||||||
import { networkService } from "../../../../main";
|
import { networkService } from "../../../../main";
|
||||||
import { createToast } from "../../../../Utils/toastUtils";
|
import { createToast } from "../../../../Utils/toastUtils";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import { useMonitorUtils } from "../../../../Hooks/useMonitorUtils";
|
||||||
|
|
||||||
const useStatusPageFetchByUrl = ({ url }) => {
|
const useStatusPageFetchByUrl = ({ url, timeFrame }) => {
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
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 [isPublished, setIsPublished] = useState(false);
|
||||||
const { authToken } = useSelector((state) => state.auth);
|
const { authToken } = useSelector((state) => state.auth);
|
||||||
|
const theme = useTheme();
|
||||||
|
const { getMonitorWithPercentage } = useMonitorUtils();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchStatusPageByUrl = async () => {
|
const fetchStatusPageByUrl = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await networkService.getStatusPageByUrl({
|
const response = await networkService.getDistributedStatusPageByUrl({
|
||||||
authToken,
|
authToken,
|
||||||
url,
|
url,
|
||||||
type: "distributed",
|
type: "distributed",
|
||||||
|
timeFrame,
|
||||||
});
|
});
|
||||||
if (!response?.data?.data) return;
|
if (!response?.data?.data) return;
|
||||||
const statusPage = response.data.data;
|
const statusPage = response.data.data;
|
||||||
setStatusPage(statusPage);
|
|
||||||
|
const monitorsWithPercentage = statusPage?.subMonitors.map((monitor) =>
|
||||||
|
getMonitorWithPercentage(monitor, theme)
|
||||||
|
);
|
||||||
|
|
||||||
|
const statusPageWithSubmonitorPercentages = {
|
||||||
|
...statusPage,
|
||||||
|
subMonitors: monitorsWithPercentage,
|
||||||
|
};
|
||||||
|
setStatusPage(statusPageWithSubmonitorPercentages);
|
||||||
|
|
||||||
setMonitorId(statusPage?.monitors[0]);
|
setMonitorId(statusPage?.monitors[0]);
|
||||||
setIsPublished(statusPage?.isPublished);
|
setIsPublished(statusPage?.isPublished);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -33,7 +49,7 @@ const useStatusPageFetchByUrl = ({ url }) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchStatusPageByUrl();
|
fetchStatusPageByUrl();
|
||||||
}, [authToken, url]);
|
}, [authToken, url, getMonitorWithPercentage, theme, timeFrame]);
|
||||||
|
|
||||||
return [isLoading, networkError, statusPage, monitorId, isPublished];
|
return [isLoading, networkError, statusPage, monitorId, isPublished];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import UptLogo from "../../../assets/icons/upt_logo.png";
|
|||||||
import PeopleAltOutlinedIcon from "@mui/icons-material/PeopleAltOutlined";
|
import PeopleAltOutlinedIcon from "@mui/icons-material/PeopleAltOutlined";
|
||||||
import InfoBox from "../../../Components/InfoBox";
|
import InfoBox from "../../../Components/InfoBox";
|
||||||
import StatusHeader from "../../DistributedUptime/Details/Components/StatusHeader";
|
import StatusHeader from "../../DistributedUptime/Details/Components/StatusHeader";
|
||||||
import MonitorsList from "../../StatusPage/Status/Components/MonitorsList";
|
import MonitorsList from "./Components/MonitorsList";
|
||||||
|
|
||||||
//Utils
|
//Utils
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
@@ -27,6 +27,7 @@ import { useStatusPageFetchByUrl } from "./Hooks/useStatusPageFetchByUrl";
|
|||||||
import { useStatusPageDelete } from "../../StatusPage/Status/Hooks/useStatusPageDelete";
|
import { useStatusPageDelete } from "../../StatusPage/Status/Hooks/useStatusPageDelete";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { useLocation } from "react-router-dom";
|
import { useLocation } from "react-router-dom";
|
||||||
|
import TimeFrameHeader from "./Components/TimeframeHeader";
|
||||||
|
|
||||||
const DistributedUptimeStatus = () => {
|
const DistributedUptimeStatus = () => {
|
||||||
const { url } = useParams();
|
const { url } = useParams();
|
||||||
@@ -37,6 +38,7 @@ const DistributedUptimeStatus = () => {
|
|||||||
// Local State
|
// Local State
|
||||||
const [dateRange, setDateRange] = useState("day");
|
const [dateRange, setDateRange] = useState("day");
|
||||||
const [isDeleteOpen, setIsDeleteOpen] = useState(false);
|
const [isDeleteOpen, setIsDeleteOpen] = useState(false);
|
||||||
|
const [timeFrame, setTimeFrame] = useState(30);
|
||||||
// Utils
|
// Utils
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@@ -49,6 +51,7 @@ const DistributedUptimeStatus = () => {
|
|||||||
isPublished,
|
isPublished,
|
||||||
] = useStatusPageFetchByUrl({
|
] = useStatusPageFetchByUrl({
|
||||||
url,
|
url,
|
||||||
|
timeFrame,
|
||||||
});
|
});
|
||||||
|
|
||||||
const [isLoading, networkError, connectionStatus, monitor, lastUpdateTrigger] =
|
const [isLoading, networkError, connectionStatus, monitor, lastUpdateTrigger] =
|
||||||
@@ -217,7 +220,14 @@ const DistributedUptimeStatus = () => {
|
|||||||
monitor={monitor}
|
monitor={monitor}
|
||||||
lastUpdateTrigger={lastUpdateTrigger}
|
lastUpdateTrigger={lastUpdateTrigger}
|
||||||
/>
|
/>
|
||||||
<MonitorsList monitors={statusPage?.subMonitors} />
|
<TimeFrameHeader
|
||||||
|
timeFrame={timeFrame}
|
||||||
|
setTimeFrame={setTimeFrame}
|
||||||
|
/>
|
||||||
|
<MonitorsList
|
||||||
|
monitors={statusPage?.subMonitors}
|
||||||
|
timeFrame={timeFrame}
|
||||||
|
/>
|
||||||
<Footer />
|
<Footer />
|
||||||
<Dialog
|
<Dialog
|
||||||
// open={isOpen.deleteStats}
|
// open={isOpen.deleteStats}
|
||||||
|
|||||||
Reference in new issue
Block a user