Added skeletons to monitor pages

This commit is contained in:
Daniel Cojocea committed 2024-08-07 16:45:49 -04:00
1 parent 0195d093d5
commit ecb6f6204c
5 files changed
+216 -34

No files matched your search

+65 -8
View File
@@ -4,7 +4,7 @@ import { useDispatch, useSelector } from "react-redux";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import Button from "../../../Components/Button"; import Button from "../../../Components/Button";
import Field from "../../../Components/Inputs/Field"; import Field from "../../../Components/Inputs/Field";
import { Box, Modal, Stack, Typography } from "@mui/material"; import { Box, Modal, Skeleton, Stack, Typography } from "@mui/material";
import WestRoundedIcon from "@mui/icons-material/WestRounded"; import WestRoundedIcon from "@mui/icons-material/WestRounded";
import GreenCheck from "../../../assets/icons/checkbox-green.svg?react"; import GreenCheck from "../../../assets/icons/checkbox-green.svg?react";
import RedCheck from "../../../assets/icons/checkbox-red.svg?react"; import RedCheck from "../../../assets/icons/checkbox-red.svg?react";
@@ -47,7 +47,7 @@ const Configure = () => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const { user, authToken } = useSelector((state) => state.auth); const { user, authToken } = useSelector((state) => state.auth);
const { monitors } = useSelector((state) => state.uptimeMonitors); const { monitors } = useSelector((state) => state.uptimeMonitors);
const [monitor, setMonitor] = useState(); const [monitor, setMonitor] = useState({});
const [duration, setDuration] = useState(0); const [duration, setDuration] = useState(0);
const [errors, setErrors] = useState({}); const [errors, setErrors] = useState({});
const { monitorId } = useParams(); const { monitorId } = useParams();
@@ -164,8 +164,13 @@ const Configure = () => {
var lastChecked = formatDurationRounded(getLastChecked(monitor?.checks)); var lastChecked = formatDurationRounded(getLastChecked(monitor?.checks));
let loading = Object.keys(monitor).length === 0;
return ( return (
<Box className="configure-monitor"> <Box className="configure-monitor">
{loading ? (
<Skeleton variant="rounded" width="15%" height={34} />
) : (
<Button <Button
level="tertiary" level="tertiary"
label="Back" label="Back"
@@ -174,7 +179,6 @@ const Configure = () => {
onClick={() => navigate(-1)} onClick={() => navigate(-1)}
sx={{ sx={{
backgroundColor: "#f4f4f4", backgroundColor: "#f4f4f4",
mb: theme.gap.medium,
px: theme.gap.ml, px: theme.gap.ml,
"& svg.MuiSvgIcon-root": { "& svg.MuiSvgIcon-root": {
mr: theme.gap.small, mr: theme.gap.small,
@@ -182,10 +186,39 @@ const Configure = () => {
}, },
}} }}
/> />
<form className="configure-monitor-form" noValidate spellCheck="false"> )}
<form
className="configure-monitor-form"
noValidate
spellCheck="false"
style={{
marginTop: theme.gap.medium,
}}
>
<Stack direction="row" gap={theme.gap.small} mt={theme.gap.small}> <Stack direction="row" gap={theme.gap.small} mt={theme.gap.small}>
{monitor?.status ? <GreenCheck /> : <RedCheck />} {loading ? (
<Box> <Skeleton
variant="circular"
style={{ minWidth: 24, minHeight: 24 }}
/>
) : monitor?.status ? (
<GreenCheck />
) : (
<RedCheck />
)}
<Box width="80%">
{loading ? (
<>
<Skeleton
variant="rounded"
width="50%"
height={24}
sx={{ mb: theme.gap.small }}
/>
<Skeleton variant="rounded" width="50%" height={18} />
</>
) : (
<>
{parsedUrl?.host ? ( {parsedUrl?.host ? (
<Typography <Typography
component="h1" component="h1"
@@ -211,6 +244,8 @@ const Configure = () => {
Checking every {duration}.{" "} Checking every {duration}.{" "}
{lastChecked ? `Last time checked ${lastChecked} ago.` : ""} {lastChecked ? `Last time checked ${lastChecked} ago.` : ""}
</Typography> </Typography>
</>
)}
</Box> </Box>
<Stack <Stack
direction="row" direction="row"
@@ -220,6 +255,12 @@ const Configure = () => {
alignSelf: "flex-end", alignSelf: "flex-end",
}} }}
> >
{loading ? (
<>
<Skeleton variant="rounded" width={150} height={34} />
</>
) : (
<>
<Button <Button
level="tertiary" level="tertiary"
label="Pause" label="Pause"
@@ -243,8 +284,18 @@ const Configure = () => {
}} }}
onClick={() => setIsOpen(true)} onClick={() => setIsOpen(true)}
/> />
</>
)}
</Stack> </Stack>
</Stack> </Stack>
{loading ? (
<>
<Skeleton variant="rounded" width="100%" height={200} />
<Skeleton variant="rounded" width="100%" height={200} />
<Skeleton variant="rounded" width="100%" height={200} />
</>
) : (
<>
<Stack <Stack
className="config-box" className="config-box"
direction="row" direction="row"
@@ -254,8 +305,8 @@ const Configure = () => {
<Box> <Box>
<Typography component="h2">General settings</Typography> <Typography component="h2">General settings</Typography>
<Typography component="p" sx={{ mt: theme.gap.small }}> <Typography component="p" sx={{ mt: theme.gap.small }}>
Here you can select the URL of the host, together with the type of Here you can select the URL of the host, together with the
monitor. type of monitor.
</Typography> </Typography>
</Box> </Box>
<Stack gap={theme.gap.xl}> <Stack gap={theme.gap.xl}>
@@ -363,13 +414,19 @@ const Configure = () => {
/> />
</Stack> </Stack>
</Stack> </Stack>
</>
)}
<Stack direction="row" justifyContent="flex-end"> <Stack direction="row" justifyContent="flex-end">
{loading ? (
<Skeleton variant="rounded" width="15%" height={34} />
) : (
<Button <Button
level="primary" level="primary"
label="Save" label="Save"
sx={{ px: theme.gap.large }} sx={{ px: theme.gap.large }}
onClick={handleSubmit} onClick={handleSubmit}
/> />
)}
</Stack> </Stack>
</form> </form>
<Modal <Modal
@@ -42,9 +42,6 @@
padding: var(--env-var-spacing-1) 18px; padding: var(--env-var-spacing-1) 18px;
background-color: var(--env-var-color-8); background-color: var(--env-var-color-8);
} }
.monitor-details .stat-box:not(:first-of-type) {
margin-left: var(--env-var-spacing-2);
}
.monitor-details .stat-box h6.MuiTypography-root { .monitor-details .stat-box h6.MuiTypography-root {
margin-bottom: var(--env-var-spacing-1); margin-bottom: var(--env-var-spacing-1);
} }
+109 -21
View File
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { Box, Stack, Typography, useTheme } from "@mui/material"; import { Box, Skeleton, Stack, Typography, useTheme } from "@mui/material";
import { useSelector } from "react-redux"; import { useSelector } from "react-redux";
import { useNavigate, useParams } from "react-router-dom"; import { useNavigate, useParams } from "react-router-dom";
import axiosInstance from "../../../Utils/axiosConfig"; import axiosInstance from "../../../Utils/axiosConfig";
@@ -30,6 +30,11 @@ const StatBox = ({ title, value }) => {
); );
}; };
StatBox.propTypes = {
title: PropTypes.string,
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
};
/** /**
* Details page component displaying monitor details and related information. * Details page component displaying monitor details and related information.
* @component * @component
@@ -158,8 +163,13 @@ const DetailsPage = () => {
}, 0); }, 0);
}; };
let loading = Object.keys(monitor).length === 0;
return ( return (
<Box className="monitor-details"> <Box className="monitor-details">
{loading ? (
<Skeleton variant="rounded" width="20%" height={34} />
) : (
<Button <Button
level="tertiary" level="tertiary"
label="Back to Monitors" label="Back to Monitors"
@@ -168,7 +178,6 @@ const DetailsPage = () => {
onClick={() => navigate("/monitors")} onClick={() => navigate("/monitors")}
sx={{ sx={{
backgroundColor: "#f4f4f4", backgroundColor: "#f4f4f4",
mb: theme.gap.medium,
px: theme.gap.ml, px: theme.gap.ml,
"& svg.MuiSvgIcon-root": { "& svg.MuiSvgIcon-root": {
mr: theme.gap.small, mr: theme.gap.small,
@@ -176,10 +185,32 @@ const DetailsPage = () => {
}, },
}} }}
/> />
<Stack gap={theme.gap.xl}> )}
<Stack gap={theme.gap.xl} mt={theme.gap.medium}>
<Stack direction="row" gap={theme.gap.small} mt={theme.gap.small}> <Stack direction="row" gap={theme.gap.small} mt={theme.gap.small}>
{monitor?.status ? <GreenCheck /> : <RedCheck />} {loading ? (
<Box> <Skeleton
variant="circular"
style={{ minWidth: 24, minHeight: 24 }}
/>
) : monitor?.status ? (
<GreenCheck />
) : (
<RedCheck />
)}
<Box width="80%">
{loading ? (
<>
<Skeleton variant="rounded" width="50%" height={24} />
<Skeleton
variant="rounded"
width="50%"
height={18}
sx={{ mt: theme.gap.small }}
/>
</>
) : (
<>
<Typography component="h1" sx={{ lineHeight: 1 }}> <Typography component="h1" sx={{ lineHeight: 1 }}>
{monitor.url?.replace(/^https?:\/\//, "") || "..."} {monitor.url?.replace(/^https?:\/\//, "") || "..."}
</Typography> </Typography>
@@ -194,18 +225,31 @@ const DetailsPage = () => {
> >
Your site is {monitor?.status ? "up" : "down"}. Your site is {monitor?.status ? "up" : "down"}.
</Typography>{" "} </Typography>{" "}
Checking every {formatDurationRounded(monitor?.interval)}. Last Checking every {formatDurationRounded(monitor?.interval)}.
time checked{" "} Last time checked{" "}
{formatDurationRounded(getLastChecked(monitor?.checks))} ago. {formatDurationRounded(getLastChecked(monitor?.checks))} ago.
</Typography> </Typography>
</>
)}
</Box> </Box>
{loading ? (
<Skeleton
variant="rounded"
width="20%"
height={34}
sx={{ alignSelf: "flex-end" }}
/>
) : (
<Button <Button
level="tertiary" level="tertiary"
label="Configure" label="Configure"
animate="rotate90" animate="rotate90"
img={ img={
<SettingsIcon <SettingsIcon
style={{ width: theme.gap.mlplus, height: theme.gap.mlplus }} style={{
minWidth: theme.gap.mlplus,
minHeight: theme.gap.mlplus,
}}
/> />
} }
onClick={() => navigate(`/monitors/configure/${monitorId}`)} onClick={() => navigate(`/monitors/configure/${monitorId}`)}
@@ -219,8 +263,21 @@ const DetailsPage = () => {
}, },
}} }}
/> />
)}
</Stack> </Stack>
<Stack direction="row" justifyContent="space-between"> <Stack
direction="row"
justifyContent="space-between"
gap={theme.gap.large}
>
{loading ? (
<>
<Skeleton variant="rounded" width="100%" height={80} />
<Skeleton variant="rounded" width="100%" height={80} />
<Skeleton variant="rounded" width="100%" height={80} />
</>
) : (
<>
<StatBox <StatBox
title="Currently up for" title="Currently up for"
value={formatDuration(calculateUptimeDuration(monitor.checks))} value={formatDuration(calculateUptimeDuration(monitor.checks))}
@@ -229,7 +286,12 @@ const DetailsPage = () => {
title="Last checked" title="Last checked"
value={`${formatDuration(getLastChecked(monitor.checks))} ago`} value={`${formatDuration(getLastChecked(monitor.checks))} ago`}
/> />
<StatBox title="Incidents" value={countIncidents(monitor.checks)} /> <StatBox
title="Incidents"
value={countIncidents(monitor.checks)}
/>
</>
)}
</Stack> </Stack>
<Box> <Box>
<Stack <Stack
@@ -237,6 +299,18 @@ const DetailsPage = () => {
justifyContent="space-between" justifyContent="space-between"
mb={theme.gap.ml} mb={theme.gap.ml}
> >
{loading ? (
<>
<Skeleton
variant="rounded"
width="20%"
height={24}
sx={{ alignSelf: "flex-end" }}
/>
<Skeleton variant="rounded" width="20%" height={34} />
</>
) : (
<>
<Typography component="h2" mb={theme.gap.small}> <Typography component="h2" mb={theme.gap.small}>
Response Times Response Times
</Typography> </Typography>
@@ -265,28 +339,42 @@ const DetailsPage = () => {
onClick={() => setFilter("month")} onClick={() => setFilter("month")}
sx={{ sx={{
backgroundColor: backgroundColor:
filter === "month" && theme.palette.otherColors.fillGray, filter === "month" &&
theme.palette.otherColors.fillGray,
}} }}
/> />
</ButtonGroup> </ButtonGroup>
</>
)}
</Stack> </Stack>
<Box sx={{ height: "200px" }}> <Box sx={{ height: "200px" }}>
<MonitorDetailsAreaChart checks={monitor.checks} filter={filter} /> {loading ? (
<Skeleton variant="rounded" width="100%" height="100%" />
) : (
<MonitorDetailsAreaChart
checks={monitor.checks}
filter={filter}
/>
)}
</Box> </Box>
</Box> </Box>
<Box> <Stack gap={theme.gap.ml}>
<Typography component="h2" mb={theme.gap.ml}> {loading ? (
History <>
</Typography> <Skeleton variant="rounded" width="20%" height={24} />
<Skeleton variant="rounded" width="100%" height={200} />
<Skeleton variant="rounded" width="100%" height={50} />
</>
) : (
<>
<Typography component="h2">History</Typography>
<BasicTable data={data} paginated={true} reversed={true} /> <BasicTable data={data} paginated={true} reversed={true} />
</Box> </>
)}
</Stack>
</Stack> </Stack>
</Box> </Box>
); );
}; };
StatBox.propTypes = {
title: PropTypes.string,
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
};
export default DetailsPage; export default DetailsPage;
+38 -2
View File
@@ -22,6 +22,7 @@ import {
Menu, Menu,
MenuItem, MenuItem,
Modal, Modal,
Skeleton,
Stack, Stack,
Typography, Typography,
} from "@mui/material"; } from "@mui/material";
@@ -204,9 +205,18 @@ const Monitors = () => {
}; };
}); });
let loading = monitorState.isLoading && monitorState.monitors.length === 0;
return ( return (
<Stack className="monitors" gap={theme.gap.large}> <Stack className="monitors" gap={theme.gap.large}>
<Stack direction="row" justifyContent="space-between" alignItems="center"> <Stack direction="row" justifyContent="space-between" alignItems="center">
{loading ? (
<>
<Skeleton variant="rounded" width="50%" height={36} />
<Skeleton variant="rounded" width="15%" height={36} />
</>
) : (
<>
<Typography component="h1"> <Typography component="h1">
Hello, {authState.user.firstName} Hello, {authState.user.firstName}
</Typography> </Typography>
@@ -217,25 +227,43 @@ const Monitors = () => {
navigate("/monitors/create"); navigate("/monitors/create");
}} }}
/> />
</>
)}
</Stack> </Stack>
<Stack <Stack
gap={theme.gap.large} gap={theme.gap.large}
direction="row" direction="row"
justifyContent="space-between" justifyContent="space-between"
> >
{loading ? (
<>
<Skeleton variant="rounded" width="100%" height={100} />
<Skeleton variant="rounded" width="100%" height={100} />
<Skeleton variant="rounded" width="100%" height={100} />
</>
) : (
<>
<ServerStatus title="Up" value={up} state="up" /> <ServerStatus title="Up" value={up} state="up" />
<ServerStatus title="Down" value={down} state="down" /> <ServerStatus title="Down" value={down} state="down" />
<ServerStatus title="Paused" value={0} state="pause" /> <ServerStatus title="Paused" value={0} state="pause" />
</>
)}
</Stack> </Stack>
<Stack <Stack
gap={theme.gap.large} gap={theme.gap.large}
p={theme.gap.xl} p={theme.gap.xl}
border={1}
borderColor={
loading ? "#f9fafb" : theme.palette.otherColors.graishWhite
}
backgroundColor={loading ? "#f9fafb" : "white"}
sx={{ sx={{
border: `solid 1px ${theme.palette.otherColors.graishWhite}`,
borderRadius: `${theme.shape.borderRadius}px`, borderRadius: `${theme.shape.borderRadius}px`,
backgroundColor: theme.palette.otherColors.white,
}} }}
> >
{loading ? (
<Skeleton variant="rounded" width="50%" height={25} />
) : (
<Stack direction="row" alignItems="center"> <Stack direction="row" alignItems="center">
<Typography component="h2">Current monitors</Typography> <Typography component="h2">Current monitors</Typography>
<Box className="current-monitors-counter"> <Box className="current-monitors-counter">
@@ -243,7 +271,15 @@ const Monitors = () => {
</Box> </Box>
{/* TODO - add search bar */} {/* TODO - add search bar */}
</Stack> </Stack>
)}
{loading ? (
<>
<Skeleton variant="rounded" width="100%" height={400} />
<Skeleton variant="rounded" width="100%" height={100} />
</>
) : (
<BasicTable data={data} paginated={true} /> <BasicTable data={data} paginated={true} />
)}
</Stack> </Stack>
<Menu <Menu
className="actions-menu" className="actions-menu"
+4
View File
@@ -161,6 +161,10 @@ button:focus-visible {
display: none; display: none;
} }
body .MuiSkeleton-root {
background-color: var(--env-var-color-15);
}
@media (prefers-color-scheme: light) { @media (prefers-color-scheme: light) {
:root { :root {
color: #213547; color: #213547;