Merge pull request #564 from bluewave-labs/feat/loading-skeletons
Loading skeletons
This commit is contained in:
8 files changed
+1094
-721
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import { Typography, ButtonGroup, Stack, Box } from "@mui/material";
|
import { Typography, ButtonGroup, Stack, Box, Skeleton } from "@mui/material";
|
||||||
import WestRoundedIcon from "@mui/icons-material/WestRounded";
|
import WestRoundedIcon from "@mui/icons-material/WestRounded";
|
||||||
import Button from "../../Components/Button";
|
import Button from "../../Components/Button";
|
||||||
import axiosInstance from "../../Utils/axiosConfig";
|
import axiosInstance from "../../Utils/axiosConfig";
|
||||||
@@ -12,12 +12,39 @@ import Select from "../../Components/Inputs/Select";
|
|||||||
|
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders a skeleton layout.
|
||||||
|
*
|
||||||
|
* @returns {JSX.Element}
|
||||||
|
*/
|
||||||
|
const SkeletonLayout = () => {
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Stack direction="row" alignItems="center" gap={theme.gap.medium}>
|
||||||
|
<Skeleton variant="rounded" width={150} height={34} />
|
||||||
|
<Skeleton variant="rounded" width="15%" height={34} />
|
||||||
|
<Skeleton
|
||||||
|
variant="rounded"
|
||||||
|
width="20%"
|
||||||
|
height={34}
|
||||||
|
sx={{ ml: "auto" }}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
<Skeleton variant="rounded" width="100%" height={300} />
|
||||||
|
<Skeleton variant="rounded" width="100%" height={100} />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const Incidents = () => {
|
const Incidents = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const authState = useSelector((state) => state.auth);
|
const authState = useSelector((state) => state.auth);
|
||||||
const [monitors, setMonitors] = useState({});
|
const [monitors, setMonitors] = useState({});
|
||||||
const [selectedMonitor, setSelectedMonitor] = useState("0");
|
const [selectedMonitor, setSelectedMonitor] = useState("0");
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
// TODO do something with these filters
|
// TODO do something with these filters
|
||||||
const [filter, setFilter] = useState("all");
|
const [filter, setFilter] = useState("all");
|
||||||
@@ -34,6 +61,7 @@ const Incidents = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchIncidents = async () => {
|
const fetchIncidents = async () => {
|
||||||
|
setLoading(true);
|
||||||
const res = await axiosInstance.get(
|
const res = await axiosInstance.get(
|
||||||
`/monitors/user/${authState.user._id}?status=false`,
|
`/monitors/user/${authState.user._id}?status=false`,
|
||||||
{
|
{
|
||||||
@@ -51,6 +79,7 @@ const Incidents = () => {
|
|||||||
}, {});
|
}, {});
|
||||||
setMonitors(monitorLookup);
|
setMonitors(monitorLookup);
|
||||||
}
|
}
|
||||||
|
setLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
fetchIncidents();
|
fetchIncidents();
|
||||||
@@ -92,8 +121,8 @@ const Incidents = () => {
|
|||||||
data: <StatusLabel status="down" text="Down" />,
|
data: <StatusLabel status="down" text="Down" />,
|
||||||
},
|
},
|
||||||
{ id: idx + 1, data: new Date(incident.createdAt).toLocaleString() },
|
{ id: idx + 1, data: new Date(incident.createdAt).toLocaleString() },
|
||||||
{ id: idx + 2, data: incident.statusCode },
|
{ id: idx + 2, data: monitors[incident.monitorId].name },
|
||||||
{ id: idx + 3, data: monitors[incident.monitorId].name },
|
{ id: idx + 3, data: incident.statusCode },
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -102,7 +131,9 @@ const Incidents = () => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Stack className="incidents" gap={theme.gap.large}>
|
<Stack className="incidents" gap={theme.gap.large}>
|
||||||
{hasAnyIncidents ? (
|
{loading ? (
|
||||||
|
<SkeletonLayout />
|
||||||
|
) : hasAnyIncidents ? (
|
||||||
<>
|
<>
|
||||||
<Stack direction="row" alignItems="center" gap={theme.gap.medium}>
|
<Stack direction="row" alignItems="center" gap={theme.gap.medium}>
|
||||||
<Typography component="h1">Incident history for: </Typography>
|
<Typography component="h1">Incident history for: </Typography>
|
||||||
@@ -155,8 +186,7 @@ const Incidents = () => {
|
|||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<Stack alignItems="center" mt={theme.gap.xxl} gap={theme.gap.small}>
|
<Box>
|
||||||
<Typography>No incidents, yet.</Typography>
|
|
||||||
<Button
|
<Button
|
||||||
level="tertiary"
|
level="tertiary"
|
||||||
label="Back"
|
label="Back"
|
||||||
@@ -165,15 +195,25 @@ const Incidents = () => {
|
|||||||
onClick={() => navigate(-1)}
|
onClick={() => navigate(-1)}
|
||||||
sx={{
|
sx={{
|
||||||
backgroundColor: theme.palette.otherColors.fillGray,
|
backgroundColor: theme.palette.otherColors.fillGray,
|
||||||
mb: theme.gap.medium,
|
|
||||||
px: theme.gap.ml,
|
px: theme.gap.ml,
|
||||||
|
mb: theme.gap.ml,
|
||||||
"& svg.MuiSvgIcon-root": {
|
"& svg.MuiSvgIcon-root": {
|
||||||
mr: theme.gap.small,
|
mr: theme.gap.small,
|
||||||
fill: theme.palette.otherColors.slateGray,
|
fill: theme.palette.otherColors.slateGray,
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
<Box
|
||||||
|
padding={theme.gap.xxl}
|
||||||
|
gap={theme.gap.small}
|
||||||
|
border={1}
|
||||||
|
borderRadius={`${theme.shape.borderRadius}px`}
|
||||||
|
borderColor={theme.palette.otherColors.graishWhite}
|
||||||
|
backgroundColor={theme.palette.otherColors.white}
|
||||||
|
>
|
||||||
|
<Typography textAlign="center">No incidents, yet.</Typography>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
)}
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -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";
|
||||||
@@ -36,6 +36,54 @@ const parseUrl = (url) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders a skeleton layout.
|
||||||
|
*
|
||||||
|
* @returns {JSX.Element}
|
||||||
|
*/
|
||||||
|
const SkeletonLayout = () => {
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Skeleton variant="rounded" width="15%" height={34} />
|
||||||
|
<Stack gap={theme.gap.xl} mt={theme.gap.medium}>
|
||||||
|
<Stack direction="row" gap={theme.gap.small} mt={theme.gap.small}>
|
||||||
|
<Skeleton
|
||||||
|
variant="circular"
|
||||||
|
style={{ minWidth: 24, minHeight: 24 }}
|
||||||
|
/>
|
||||||
|
<Box width="80%">
|
||||||
|
<Skeleton
|
||||||
|
variant="rounded"
|
||||||
|
width="50%"
|
||||||
|
height={24}
|
||||||
|
sx={{ mb: theme.gap.small }}
|
||||||
|
/>
|
||||||
|
<Skeleton variant="rounded" width="50%" height={18} />
|
||||||
|
</Box>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
gap={theme.gap.medium}
|
||||||
|
sx={{
|
||||||
|
ml: "auto",
|
||||||
|
alignSelf: "flex-end",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Skeleton variant="rounded" width={150} height={34} />
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
<Skeleton variant="rounded" width="100%" height={200} />
|
||||||
|
<Skeleton variant="rounded" width="100%" height={200} />
|
||||||
|
<Skeleton variant="rounded" width="100%" height={200} />
|
||||||
|
<Stack direction="row" justifyContent="flex-end">
|
||||||
|
<Skeleton variant="rounded" width="15%" height={34} />
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configure page displays monitor configurations and allows for editing actions.
|
* Configure page displays monitor configurations and allows for editing actions.
|
||||||
* @component
|
* @component
|
||||||
@@ -47,7 +95,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,214 +212,228 @@ 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">
|
||||||
<Button
|
{loading ? (
|
||||||
level="tertiary"
|
<SkeletonLayout />
|
||||||
label="Back"
|
) : (
|
||||||
animate="slideLeft"
|
<>
|
||||||
img={<WestRoundedIcon />}
|
<Button
|
||||||
onClick={() => navigate(-1)}
|
level="tertiary"
|
||||||
sx={{
|
label="Back"
|
||||||
backgroundColor: "#f4f4f4",
|
animate="slideLeft"
|
||||||
mb: theme.gap.medium,
|
img={<WestRoundedIcon />}
|
||||||
px: theme.gap.ml,
|
onClick={() => navigate(-1)}
|
||||||
"& svg.MuiSvgIcon-root": {
|
|
||||||
mr: theme.gap.small,
|
|
||||||
fill: theme.palette.otherColors.slateGray,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<form className="configure-monitor-form" noValidate spellCheck="false">
|
|
||||||
<Stack direction="row" gap={theme.gap.small} mt={theme.gap.small}>
|
|
||||||
{monitor?.status ? <GreenCheck /> : <RedCheck />}
|
|
||||||
<Box>
|
|
||||||
{parsedUrl?.host ? (
|
|
||||||
<Typography
|
|
||||||
component="h1"
|
|
||||||
mb={theme.gap.small}
|
|
||||||
sx={{ lineHeight: 1 }}
|
|
||||||
>
|
|
||||||
{parsedUrl.host || "..."}
|
|
||||||
</Typography>
|
|
||||||
) : (
|
|
||||||
""
|
|
||||||
)}
|
|
||||||
<Typography lineHeight={parsedUrl?.host ? 1 : theme.gap.large}>
|
|
||||||
<Typography
|
|
||||||
component="span"
|
|
||||||
sx={{
|
|
||||||
color: monitor?.status
|
|
||||||
? "var(--env-var-color-17)"
|
|
||||||
: "var(--env-var-color-24)",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Your site is {monitor?.status ? "up" : "down"}.
|
|
||||||
</Typography>{" "}
|
|
||||||
Checking every {duration}.{" "}
|
|
||||||
{lastChecked ? `Last time checked ${lastChecked} ago.` : ""}
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
gap={theme.gap.medium}
|
|
||||||
sx={{
|
sx={{
|
||||||
ml: "auto",
|
backgroundColor: "#f4f4f4",
|
||||||
alignSelf: "flex-end",
|
px: theme.gap.ml,
|
||||||
|
"& svg.MuiSvgIcon-root": {
|
||||||
|
mr: theme.gap.small,
|
||||||
|
fill: theme.palette.otherColors.slateGray,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<form
|
||||||
|
className="configure-monitor-form"
|
||||||
|
noValidate
|
||||||
|
spellCheck="false"
|
||||||
|
style={{
|
||||||
|
marginTop: theme.gap.medium,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Button
|
<Stack direction="row" gap={theme.gap.small} mt={theme.gap.small}>
|
||||||
level="tertiary"
|
{monitor?.status ? <GreenCheck /> : <RedCheck />}
|
||||||
label="Pause"
|
<Box>
|
||||||
animate="rotate180"
|
{parsedUrl?.host ? (
|
||||||
img={<PauseCircleOutlineIcon />}
|
<Typography
|
||||||
sx={{
|
component="h1"
|
||||||
backgroundColor: "#f4f4f4",
|
mb={theme.gap.small}
|
||||||
pl: theme.gap.small,
|
sx={{ lineHeight: 1 }}
|
||||||
pr: theme.gap.medium,
|
>
|
||||||
"& svg": {
|
{parsedUrl.host || "..."}
|
||||||
mr: theme.gap.xs,
|
</Typography>
|
||||||
},
|
) : (
|
||||||
}}
|
""
|
||||||
/>
|
)}
|
||||||
<Button
|
<Typography lineHeight={parsedUrl?.host ? 1 : theme.gap.large}>
|
||||||
level="error"
|
<Typography
|
||||||
label="Remove"
|
component="span"
|
||||||
sx={{
|
sx={{
|
||||||
boxShadow: "none",
|
color: monitor?.status
|
||||||
px: theme.gap.ml,
|
? "var(--env-var-color-17)"
|
||||||
}}
|
: "var(--env-var-color-24)",
|
||||||
onClick={() => setIsOpen(true)}
|
}}
|
||||||
/>
|
>
|
||||||
</Stack>
|
Your site is {monitor?.status ? "up" : "down"}.
|
||||||
</Stack>
|
</Typography>{" "}
|
||||||
<Stack
|
Checking every {duration}.{" "}
|
||||||
className="config-box"
|
{lastChecked ? `Last time checked ${lastChecked} ago.` : ""}
|
||||||
direction="row"
|
|
||||||
justifyContent="space-between"
|
|
||||||
gap={theme.gap.xxl}
|
|
||||||
>
|
|
||||||
<Box>
|
|
||||||
<Typography component="h2">General settings</Typography>
|
|
||||||
<Typography component="p" sx={{ mt: theme.gap.small }}>
|
|
||||||
Here you can select the URL of the host, together with the type of
|
|
||||||
monitor.
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
<Stack gap={theme.gap.xl}>
|
|
||||||
<Field
|
|
||||||
type={monitor?.type === "http" ? "url" : "text"}
|
|
||||||
https={protocol === "https"}
|
|
||||||
id="monitor-url"
|
|
||||||
label="URL to monitor"
|
|
||||||
placeholder="google.com"
|
|
||||||
value={parsedUrl?.host || monitor?.url || ""}
|
|
||||||
disabled={true}
|
|
||||||
error={errors["url"]}
|
|
||||||
/>
|
|
||||||
<Field
|
|
||||||
type="text"
|
|
||||||
id="monitor-name"
|
|
||||||
label="Friendly name"
|
|
||||||
isOptional={true}
|
|
||||||
placeholder="Google"
|
|
||||||
value={monitor?.name || ""}
|
|
||||||
onChange={handleChange}
|
|
||||||
error={errors["name"]}
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
</Stack>
|
|
||||||
<Stack
|
|
||||||
className="config-box"
|
|
||||||
direction="row"
|
|
||||||
justifyContent="space-between"
|
|
||||||
gap={theme.gap.xxl}
|
|
||||||
>
|
|
||||||
<Box>
|
|
||||||
<Typography component="h2">Incident notifications</Typography>
|
|
||||||
<Typography component="p" mt={theme.gap.small}>
|
|
||||||
When there is an incident, notify users.
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
<Stack gap={theme.gap.medium}>
|
|
||||||
<Typography component="p" mt={theme.gap.small}>
|
|
||||||
When there is a new incident,
|
|
||||||
</Typography>
|
|
||||||
<Checkbox
|
|
||||||
id="notify-sms"
|
|
||||||
label="Notify via SMS (coming soon)"
|
|
||||||
isChecked={false}
|
|
||||||
value=""
|
|
||||||
onChange={() => console.log("disabled")}
|
|
||||||
isDisabled={true}
|
|
||||||
/>
|
|
||||||
<Checkbox
|
|
||||||
id="notify-email-default"
|
|
||||||
label={`Notify via email (to ${user.email})`}
|
|
||||||
isChecked={
|
|
||||||
monitor?.notifications?.some(
|
|
||||||
(notification) => notification.type === "email"
|
|
||||||
) || false
|
|
||||||
}
|
|
||||||
value={user?.email}
|
|
||||||
onChange={(event) => handleChange(event)}
|
|
||||||
/>
|
|
||||||
<Checkbox
|
|
||||||
id="notify-email"
|
|
||||||
label="Also notify via email to multiple addresses (coming soon)"
|
|
||||||
isChecked={false}
|
|
||||||
value=""
|
|
||||||
onChange={() => console.log("disabled")}
|
|
||||||
isDisabled={true}
|
|
||||||
/>
|
|
||||||
{monitor?.notifications?.some(
|
|
||||||
(notification) => notification.type === "emails"
|
|
||||||
) ? (
|
|
||||||
<Box mx={`calc(${theme.gap.ml} * 2)`}>
|
|
||||||
<Field
|
|
||||||
id="notify-email-list"
|
|
||||||
type="text"
|
|
||||||
placeholder="name@gmail.com"
|
|
||||||
value=""
|
|
||||||
onChange={() => console.log("disabled")}
|
|
||||||
/>
|
|
||||||
<Typography mt={theme.gap.small}>
|
|
||||||
You can separate multiple emails with a comma
|
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
) : (
|
<Stack
|
||||||
""
|
direction="row"
|
||||||
)}
|
gap={theme.gap.medium}
|
||||||
</Stack>
|
sx={{
|
||||||
</Stack>
|
ml: "auto",
|
||||||
<Stack
|
alignSelf: "flex-end",
|
||||||
className="config-box"
|
}}
|
||||||
direction="row"
|
>
|
||||||
justifyContent="space-between"
|
<Button
|
||||||
gap={theme.gap.xxl}
|
level="tertiary"
|
||||||
>
|
label="Pause"
|
||||||
<Box>
|
animate="rotate180"
|
||||||
<Typography component="h2">Advanced settings</Typography>
|
img={<PauseCircleOutlineIcon />}
|
||||||
</Box>
|
sx={{
|
||||||
<Stack gap={theme.gap.xl}>
|
backgroundColor: "#f4f4f4",
|
||||||
<Select
|
pl: theme.gap.small,
|
||||||
id="monitor-interval-configure"
|
pr: theme.gap.medium,
|
||||||
label="Check frequency"
|
"& svg": {
|
||||||
value={monitor?.interval / MS_PER_MINUTE || 1}
|
mr: theme.gap.xs,
|
||||||
onChange={(event) => handleChange(event, "interval")}
|
},
|
||||||
items={frequencies}
|
}}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
<Button
|
||||||
</Stack>
|
level="error"
|
||||||
<Stack direction="row" justifyContent="flex-end">
|
label="Remove"
|
||||||
<Button
|
sx={{
|
||||||
level="primary"
|
boxShadow: "none",
|
||||||
label="Save"
|
px: theme.gap.ml,
|
||||||
sx={{ px: theme.gap.large }}
|
}}
|
||||||
onClick={handleSubmit}
|
onClick={() => setIsOpen(true)}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
</form>
|
</Stack>
|
||||||
|
<Stack
|
||||||
|
className="config-box"
|
||||||
|
direction="row"
|
||||||
|
justifyContent="space-between"
|
||||||
|
gap={theme.gap.xxl}
|
||||||
|
>
|
||||||
|
<Box>
|
||||||
|
<Typography component="h2">General settings</Typography>
|
||||||
|
<Typography component="p" sx={{ mt: theme.gap.small }}>
|
||||||
|
Here you can select the URL of the host, together with the
|
||||||
|
type of monitor.
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
<Stack gap={theme.gap.xl}>
|
||||||
|
<Field
|
||||||
|
type={monitor?.type === "http" ? "url" : "text"}
|
||||||
|
https={protocol === "https"}
|
||||||
|
id="monitor-url"
|
||||||
|
label="URL to monitor"
|
||||||
|
placeholder="google.com"
|
||||||
|
value={parsedUrl?.host || monitor?.url || ""}
|
||||||
|
disabled={true}
|
||||||
|
error={errors["url"]}
|
||||||
|
/>
|
||||||
|
<Field
|
||||||
|
type="text"
|
||||||
|
id="monitor-name"
|
||||||
|
label="Friendly name"
|
||||||
|
isOptional={true}
|
||||||
|
placeholder="Google"
|
||||||
|
value={monitor?.name || ""}
|
||||||
|
onChange={handleChange}
|
||||||
|
error={errors["name"]}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
<Stack
|
||||||
|
className="config-box"
|
||||||
|
direction="row"
|
||||||
|
justifyContent="space-between"
|
||||||
|
gap={theme.gap.xxl}
|
||||||
|
>
|
||||||
|
<Box>
|
||||||
|
<Typography component="h2">Incident notifications</Typography>
|
||||||
|
<Typography component="p" mt={theme.gap.small}>
|
||||||
|
When there is an incident, notify users.
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
<Stack gap={theme.gap.medium}>
|
||||||
|
<Typography component="p" mt={theme.gap.small}>
|
||||||
|
When there is a new incident,
|
||||||
|
</Typography>
|
||||||
|
<Checkbox
|
||||||
|
id="notify-sms"
|
||||||
|
label="Notify via SMS (coming soon)"
|
||||||
|
isChecked={false}
|
||||||
|
value=""
|
||||||
|
onChange={() => console.log("disabled")}
|
||||||
|
isDisabled={true}
|
||||||
|
/>
|
||||||
|
<Checkbox
|
||||||
|
id="notify-email-default"
|
||||||
|
label={`Notify via email (to ${user.email})`}
|
||||||
|
isChecked={
|
||||||
|
monitor?.notifications?.some(
|
||||||
|
(notification) => notification.type === "email"
|
||||||
|
) || false
|
||||||
|
}
|
||||||
|
value={user?.email}
|
||||||
|
onChange={(event) => handleChange(event)}
|
||||||
|
/>
|
||||||
|
<Checkbox
|
||||||
|
id="notify-email"
|
||||||
|
label="Also notify via email to multiple addresses (coming soon)"
|
||||||
|
isChecked={false}
|
||||||
|
value=""
|
||||||
|
onChange={() => console.log("disabled")}
|
||||||
|
isDisabled={true}
|
||||||
|
/>
|
||||||
|
{monitor?.notifications?.some(
|
||||||
|
(notification) => notification.type === "emails"
|
||||||
|
) ? (
|
||||||
|
<Box mx={`calc(${theme.gap.ml} * 2)`}>
|
||||||
|
<Field
|
||||||
|
id="notify-email-list"
|
||||||
|
type="text"
|
||||||
|
placeholder="name@gmail.com"
|
||||||
|
value=""
|
||||||
|
onChange={() => console.log("disabled")}
|
||||||
|
/>
|
||||||
|
<Typography mt={theme.gap.small}>
|
||||||
|
You can separate multiple emails with a comma
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
) : (
|
||||||
|
""
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
<Stack
|
||||||
|
className="config-box"
|
||||||
|
direction="row"
|
||||||
|
justifyContent="space-between"
|
||||||
|
gap={theme.gap.xxl}
|
||||||
|
>
|
||||||
|
<Box>
|
||||||
|
<Typography component="h2">Advanced settings</Typography>
|
||||||
|
</Box>
|
||||||
|
<Stack gap={theme.gap.xl}>
|
||||||
|
<Select
|
||||||
|
id="monitor-interval-configure"
|
||||||
|
label="Check frequency"
|
||||||
|
value={monitor?.interval / MS_PER_MINUTE || 1}
|
||||||
|
onChange={(event) => handleChange(event, "interval")}
|
||||||
|
items={frequencies}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
<Stack direction="row" justifyContent="flex-end">
|
||||||
|
<Button
|
||||||
|
level="primary"
|
||||||
|
label="Save"
|
||||||
|
sx={{ px: theme.gap.large }}
|
||||||
|
onClick={handleSubmit}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
</form>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
<Modal
|
<Modal
|
||||||
aria-labelledby="modal-delete-monitor"
|
aria-labelledby="modal-delete-monitor"
|
||||||
aria-describedby="delete-monitor-confirmation"
|
aria-describedby="delete-monitor-confirmation"
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,81 @@ const StatBox = ({ title, value }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
StatBox.propTypes = {
|
||||||
|
title: PropTypes.string,
|
||||||
|
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders a skeleton layout.
|
||||||
|
*
|
||||||
|
* @returns {JSX.Element}
|
||||||
|
*/
|
||||||
|
const SkeletonLayout = () => {
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Skeleton variant="rounded" width="20%" height={34} />
|
||||||
|
<Stack gap={theme.gap.xl} mt={theme.gap.medium}>
|
||||||
|
<Stack direction="row" gap={theme.gap.small} mt={theme.gap.small}>
|
||||||
|
<Skeleton
|
||||||
|
variant="circular"
|
||||||
|
style={{ minWidth: 24, minHeight: 24 }}
|
||||||
|
/>
|
||||||
|
<Box width="80%">
|
||||||
|
<Skeleton variant="rounded" width="50%" height={24} />
|
||||||
|
<Skeleton
|
||||||
|
variant="rounded"
|
||||||
|
width="50%"
|
||||||
|
height={18}
|
||||||
|
sx={{ mt: theme.gap.small }}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
<Skeleton
|
||||||
|
variant="rounded"
|
||||||
|
width="20%"
|
||||||
|
height={34}
|
||||||
|
sx={{ alignSelf: "flex-end" }}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
justifyContent="space-between"
|
||||||
|
gap={theme.gap.large}
|
||||||
|
>
|
||||||
|
<Skeleton variant="rounded" width="100%" height={80} />
|
||||||
|
<Skeleton variant="rounded" width="100%" height={80} />
|
||||||
|
<Skeleton variant="rounded" width="100%" height={80} />
|
||||||
|
</Stack>
|
||||||
|
<Box>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
justifyContent="space-between"
|
||||||
|
mb={theme.gap.ml}
|
||||||
|
>
|
||||||
|
<Skeleton
|
||||||
|
variant="rounded"
|
||||||
|
width="20%"
|
||||||
|
height={24}
|
||||||
|
sx={{ alignSelf: "flex-end" }}
|
||||||
|
/>
|
||||||
|
<Skeleton variant="rounded" width="20%" height={34} />
|
||||||
|
</Stack>
|
||||||
|
<Box sx={{ height: "200px" }}>
|
||||||
|
<Skeleton variant="rounded" width="100%" height="100%" />
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
<Stack gap={theme.gap.ml}>
|
||||||
|
<Skeleton variant="rounded" width="20%" height={24} />
|
||||||
|
<Skeleton variant="rounded" width="100%" height={200} />
|
||||||
|
<Skeleton variant="rounded" width="100%" height={50} />
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Details page component displaying monitor details and related information.
|
* Details page component displaying monitor details and related information.
|
||||||
* @component
|
* @component
|
||||||
@@ -158,135 +233,150 @@ const DetailsPage = () => {
|
|||||||
}, 0);
|
}, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let loading = Object.keys(monitor).length === 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box className="monitor-details">
|
<Box className="monitor-details">
|
||||||
<Button
|
{loading ? (
|
||||||
level="tertiary"
|
<SkeletonLayout />
|
||||||
label="Back to Monitors"
|
) : (
|
||||||
animate="slideLeft"
|
<>
|
||||||
img={<WestRoundedIcon />}
|
|
||||||
onClick={() => navigate("/monitors")}
|
|
||||||
sx={{
|
|
||||||
backgroundColor: "#f4f4f4",
|
|
||||||
mb: theme.gap.medium,
|
|
||||||
px: theme.gap.ml,
|
|
||||||
"& svg.MuiSvgIcon-root": {
|
|
||||||
mr: theme.gap.small,
|
|
||||||
fill: theme.palette.otherColors.slateGray,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<Stack gap={theme.gap.xl}>
|
|
||||||
<Stack direction="row" gap={theme.gap.small} mt={theme.gap.small}>
|
|
||||||
{monitor?.status ? <GreenCheck /> : <RedCheck />}
|
|
||||||
<Box>
|
|
||||||
<Typography component="h1" sx={{ lineHeight: 1 }}>
|
|
||||||
{monitor.url?.replace(/^https?:\/\//, "") || "..."}
|
|
||||||
</Typography>
|
|
||||||
<Typography mt={theme.gap.small}>
|
|
||||||
<Typography
|
|
||||||
component="span"
|
|
||||||
sx={{
|
|
||||||
color: monitor?.status
|
|
||||||
? "var(--env-var-color-17)"
|
|
||||||
: "var(--env-var-color-24)",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Your site is {monitor?.status ? "up" : "down"}.
|
|
||||||
</Typography>{" "}
|
|
||||||
Checking every {formatDurationRounded(monitor?.interval)}. Last
|
|
||||||
time checked{" "}
|
|
||||||
{formatDurationRounded(getLastChecked(monitor?.checks))} ago.
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
<Button
|
<Button
|
||||||
level="tertiary"
|
level="tertiary"
|
||||||
label="Configure"
|
label="Back to Monitors"
|
||||||
animate="rotate90"
|
animate="slideLeft"
|
||||||
img={
|
img={<WestRoundedIcon />}
|
||||||
<SettingsIcon
|
onClick={() => navigate("/monitors")}
|
||||||
style={{ width: theme.gap.mlplus, height: theme.gap.mlplus }}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
onClick={() => navigate(`/monitors/configure/${monitorId}`)}
|
|
||||||
sx={{
|
sx={{
|
||||||
ml: "auto",
|
|
||||||
alignSelf: "flex-end",
|
|
||||||
backgroundColor: "#f4f4f4",
|
backgroundColor: "#f4f4f4",
|
||||||
px: theme.gap.medium,
|
px: theme.gap.ml,
|
||||||
"& svg": {
|
"& svg.MuiSvgIcon-root": {
|
||||||
mr: "6px",
|
mr: theme.gap.small,
|
||||||
|
fill: theme.palette.otherColors.slateGray,
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
<Stack gap={theme.gap.xl} mt={theme.gap.medium}>
|
||||||
<Stack direction="row" justifyContent="space-between">
|
<Stack direction="row" gap={theme.gap.small} mt={theme.gap.small}>
|
||||||
<StatBox
|
{monitor?.status ? <GreenCheck /> : <RedCheck />}
|
||||||
title="Currently up for"
|
<Box>
|
||||||
value={formatDuration(calculateUptimeDuration(monitor.checks))}
|
<Typography component="h1" sx={{ lineHeight: 1 }}>
|
||||||
/>
|
{monitor.url?.replace(/^https?:\/\//, "") || "..."}
|
||||||
<StatBox
|
</Typography>
|
||||||
title="Last checked"
|
<Typography mt={theme.gap.small}>
|
||||||
value={`${formatDuration(getLastChecked(monitor.checks))} ago`}
|
<Typography
|
||||||
/>
|
component="span"
|
||||||
<StatBox title="Incidents" value={countIncidents(monitor.checks)} />
|
sx={{
|
||||||
</Stack>
|
color: monitor?.status
|
||||||
<Box>
|
? "var(--env-var-color-17)"
|
||||||
<Stack
|
: "var(--env-var-color-24)",
|
||||||
direction="row"
|
}}
|
||||||
justifyContent="space-between"
|
>
|
||||||
mb={theme.gap.ml}
|
Your site is {monitor?.status ? "up" : "down"}.
|
||||||
>
|
</Typography>{" "}
|
||||||
<Typography component="h2" mb={theme.gap.small}>
|
Checking every {formatDurationRounded(monitor?.interval)}.
|
||||||
Response Times
|
Last time checked{" "}
|
||||||
</Typography>
|
{formatDurationRounded(getLastChecked(monitor?.checks))} ago.
|
||||||
<ButtonGroup>
|
</Typography>
|
||||||
|
</Box>
|
||||||
<Button
|
<Button
|
||||||
level="secondary"
|
level="tertiary"
|
||||||
label="Day"
|
label="Configure"
|
||||||
onClick={() => setFilter("day")}
|
animate="rotate90"
|
||||||
|
img={
|
||||||
|
<SettingsIcon
|
||||||
|
style={{
|
||||||
|
minWidth: theme.gap.mlplus,
|
||||||
|
minHeight: theme.gap.mlplus,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
onClick={() => navigate(`/monitors/configure/${monitorId}`)}
|
||||||
sx={{
|
sx={{
|
||||||
backgroundColor:
|
ml: "auto",
|
||||||
filter === "day" && theme.palette.otherColors.fillGray,
|
alignSelf: "flex-end",
|
||||||
|
backgroundColor: "#f4f4f4",
|
||||||
|
px: theme.gap.medium,
|
||||||
|
"& svg": {
|
||||||
|
mr: "6px",
|
||||||
|
},
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Button
|
</Stack>
|
||||||
level="secondary"
|
<Stack
|
||||||
label="Week"
|
direction="row"
|
||||||
onClick={() => setFilter("week")}
|
justifyContent="space-between"
|
||||||
sx={{
|
gap={theme.gap.large}
|
||||||
backgroundColor:
|
>
|
||||||
filter === "week" && theme.palette.otherColors.fillGray,
|
<StatBox
|
||||||
}}
|
title="Currently up for"
|
||||||
|
value={formatDuration(calculateUptimeDuration(monitor.checks))}
|
||||||
/>
|
/>
|
||||||
<Button
|
<StatBox
|
||||||
level="secondary"
|
title="Last checked"
|
||||||
label="Month"
|
value={`${formatDuration(getLastChecked(monitor.checks))} ago`}
|
||||||
onClick={() => setFilter("month")}
|
|
||||||
sx={{
|
|
||||||
backgroundColor:
|
|
||||||
filter === "month" && theme.palette.otherColors.fillGray,
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</ButtonGroup>
|
<StatBox
|
||||||
|
title="Incidents"
|
||||||
|
value={countIncidents(monitor.checks)}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
<Box>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
justifyContent="space-between"
|
||||||
|
mb={theme.gap.ml}
|
||||||
|
>
|
||||||
|
<Typography component="h2" mb={theme.gap.small}>
|
||||||
|
Response Times
|
||||||
|
</Typography>
|
||||||
|
<ButtonGroup>
|
||||||
|
<Button
|
||||||
|
level="secondary"
|
||||||
|
label="Day"
|
||||||
|
onClick={() => setFilter("day")}
|
||||||
|
sx={{
|
||||||
|
backgroundColor:
|
||||||
|
filter === "day" && theme.palette.otherColors.fillGray,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
level="secondary"
|
||||||
|
label="Week"
|
||||||
|
onClick={() => setFilter("week")}
|
||||||
|
sx={{
|
||||||
|
backgroundColor:
|
||||||
|
filter === "week" && theme.palette.otherColors.fillGray,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
level="secondary"
|
||||||
|
label="Month"
|
||||||
|
onClick={() => setFilter("month")}
|
||||||
|
sx={{
|
||||||
|
backgroundColor:
|
||||||
|
filter === "month" &&
|
||||||
|
theme.palette.otherColors.fillGray,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</ButtonGroup>
|
||||||
|
</Stack>
|
||||||
|
<Box sx={{ height: "200px" }}>
|
||||||
|
<MonitorDetailsAreaChart
|
||||||
|
checks={monitor.checks}
|
||||||
|
filter={filter}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
<Stack gap={theme.gap.ml}>
|
||||||
|
<Typography component="h2">History</Typography>
|
||||||
|
<BasicTable data={data} paginated={true} reversed={true} />
|
||||||
|
</Stack>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Box sx={{ height: "200px" }}>
|
</>
|
||||||
<MonitorDetailsAreaChart checks={monitor.checks} filter={filter} />
|
)}
|
||||||
</Box>
|
|
||||||
</Box>
|
|
||||||
<Box>
|
|
||||||
<Typography component="h2" mb={theme.gap.ml}>
|
|
||||||
History
|
|
||||||
</Typography>
|
|
||||||
<BasicTable data={data} paginated={true} reversed={true} />
|
|
||||||
</Box>
|
|
||||||
</Stack>
|
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
StatBox.propTypes = {
|
|
||||||
title: PropTypes.string,
|
|
||||||
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
||||||
};
|
|
||||||
export default DetailsPage;
|
export default DetailsPage;
|
||||||
@@ -22,6 +22,7 @@ import {
|
|||||||
Menu,
|
Menu,
|
||||||
MenuItem,
|
MenuItem,
|
||||||
Modal,
|
Modal,
|
||||||
|
Skeleton,
|
||||||
Stack,
|
Stack,
|
||||||
Typography,
|
Typography,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
@@ -71,6 +72,38 @@ const Host = ({ params }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders a skeleton layout.
|
||||||
|
*
|
||||||
|
* @returns {JSX.Element}
|
||||||
|
*/
|
||||||
|
const SkeletonLayout = () => {
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Stack direction="row" justifyContent="space-between" alignItems="center">
|
||||||
|
<Skeleton variant="rounded" width="50%" height={36} />
|
||||||
|
<Skeleton variant="rounded" width="15%" height={36} />
|
||||||
|
</Stack>
|
||||||
|
<Stack
|
||||||
|
gap={theme.gap.large}
|
||||||
|
direction="row"
|
||||||
|
justifyContent="space-between"
|
||||||
|
>
|
||||||
|
<Skeleton variant="rounded" width="100%" height={100} />
|
||||||
|
<Skeleton variant="rounded" width="100%" height={100} />
|
||||||
|
<Skeleton variant="rounded" width="100%" height={100} />
|
||||||
|
</Stack>
|
||||||
|
<Stack gap={theme.gap.large} p={theme.gap.xl} backgroundColor="#f9fafb">
|
||||||
|
<Skeleton variant="rounded" width="50%" height={25} />
|
||||||
|
<Skeleton variant="rounded" width="100%" height={300} />
|
||||||
|
<Skeleton variant="rounded" width="100%" height={100} />
|
||||||
|
</Stack>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const Monitors = () => {
|
const Monitors = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@@ -204,47 +237,60 @@ 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">
|
{loading ? (
|
||||||
<Typography component="h1">
|
<SkeletonLayout />
|
||||||
Hello, {authState.user.firstName}
|
) : (
|
||||||
</Typography>
|
<>
|
||||||
<Button
|
<Stack
|
||||||
level="primary"
|
direction="row"
|
||||||
label="Create new monitor"
|
justifyContent="space-between"
|
||||||
onClick={() => {
|
alignItems="center"
|
||||||
navigate("/monitors/create");
|
>
|
||||||
}}
|
<Typography component="h1">
|
||||||
/>
|
Hello, {authState.user.firstName}
|
||||||
</Stack>
|
</Typography>
|
||||||
<Stack
|
<Button
|
||||||
gap={theme.gap.large}
|
level="primary"
|
||||||
direction="row"
|
label="Create new monitor"
|
||||||
justifyContent="space-between"
|
onClick={() => {
|
||||||
>
|
navigate("/monitors/create");
|
||||||
<ServerStatus title="Up" value={up} state="up" />
|
}}
|
||||||
<ServerStatus title="Down" value={down} state="down" />
|
/>
|
||||||
<ServerStatus title="Paused" value={0} state="pause" />
|
</Stack>
|
||||||
</Stack>
|
<Stack
|
||||||
<Stack
|
gap={theme.gap.large}
|
||||||
gap={theme.gap.large}
|
direction="row"
|
||||||
p={theme.gap.xl}
|
justifyContent="space-between"
|
||||||
sx={{
|
>
|
||||||
border: `solid 1px ${theme.palette.otherColors.graishWhite}`,
|
<ServerStatus title="Up" value={up} state="up" />
|
||||||
borderRadius: `${theme.shape.borderRadius}px`,
|
<ServerStatus title="Down" value={down} state="down" />
|
||||||
backgroundColor: theme.palette.otherColors.white,
|
<ServerStatus title="Paused" value={0} state="pause" />
|
||||||
}}
|
</Stack>
|
||||||
>
|
<Stack
|
||||||
<Stack direction="row" alignItems="center">
|
gap={theme.gap.large}
|
||||||
<Typography component="h2">Current monitors</Typography>
|
p={theme.gap.xl}
|
||||||
<Box className="current-monitors-counter">
|
border={1}
|
||||||
{monitorState.monitors.length}
|
borderColor={theme.palette.otherColors.graishWhite}
|
||||||
</Box>
|
backgroundColor={theme.palette.otherColors.white}
|
||||||
{/* TODO - add search bar */}
|
sx={{
|
||||||
</Stack>
|
borderRadius: `${theme.shape.borderRadius}px`,
|
||||||
<BasicTable data={data} paginated={true} />
|
}}
|
||||||
</Stack>
|
>
|
||||||
|
<Stack direction="row" alignItems="center">
|
||||||
|
<Typography component="h2">Current monitors</Typography>
|
||||||
|
<Box className="current-monitors-counter">
|
||||||
|
{monitorState.monitors.length}
|
||||||
|
</Box>
|
||||||
|
{/* TODO - add search bar */}
|
||||||
|
</Stack>
|
||||||
|
<BasicTable data={data} paginated={true} />
|
||||||
|
</Stack>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
<Menu
|
<Menu
|
||||||
className="actions-menu"
|
className="actions-menu"
|
||||||
anchorEl={anchorEl}
|
anchorEl={anchorEl}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Box, Stack, Typography } from "@mui/material";
|
import { Box, Skeleton, Stack, Typography } from "@mui/material";
|
||||||
import { PieChart } from "@mui/x-charts/PieChart";
|
import { PieChart } from "@mui/x-charts/PieChart";
|
||||||
import { useDrawingArea } from "@mui/x-charts";
|
import { useDrawingArea } from "@mui/x-charts";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
@@ -126,6 +126,53 @@ const PieValueLabel = ({ value, startAngle, endAngle, color, highlighted }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders a skeleton layout.
|
||||||
|
*
|
||||||
|
* @returns {JSX.Element}
|
||||||
|
*/
|
||||||
|
const SkeletonLayout = () => {
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Skeleton variant="rounded" width="15%" height={34} />
|
||||||
|
<Stack direction="row" gap={theme.gap.small}>
|
||||||
|
<Skeleton variant="circular" style={{ minWidth: 24, minHeight: 24 }} />
|
||||||
|
<Box width="80%">
|
||||||
|
<Skeleton variant="rounded" width="50%" height={24} />
|
||||||
|
<Skeleton
|
||||||
|
variant="rounded"
|
||||||
|
width="50%"
|
||||||
|
height={18}
|
||||||
|
sx={{ mt: theme.gap.small }}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
<Skeleton
|
||||||
|
variant="rounded"
|
||||||
|
width="15%"
|
||||||
|
height={34}
|
||||||
|
sx={{ alignSelf: "flex-end" }}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
justifyContent="space-between"
|
||||||
|
gap={theme.gap.xl}
|
||||||
|
flexWrap="wrap"
|
||||||
|
>
|
||||||
|
<Skeleton variant="rounded" width="30%" height={90} sx={{ flex: 1 }} />
|
||||||
|
<Skeleton variant="rounded" width="30%" height={90} sx={{ flex: 1 }} />
|
||||||
|
<Skeleton variant="rounded" width="30%" height={90} sx={{ flex: 1 }} />
|
||||||
|
</Stack>
|
||||||
|
<Skeleton variant="rounded" width="25%" height={24} />
|
||||||
|
<Skeleton variant="rounded" width="100%" height={300} />
|
||||||
|
<Skeleton variant="rounded" width="25%" height={24} />
|
||||||
|
<Skeleton variant="rounded" width="100%" height={300} />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const PageSpeedDetails = () => {
|
const PageSpeedDetails = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@@ -136,17 +183,22 @@ const PageSpeedDetails = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchMonitor = async () => {
|
const fetchMonitor = async () => {
|
||||||
const res = await axiosInstance.get(
|
try {
|
||||||
`/monitors/${monitorId}?sortOrder=desc`,
|
const res = await axiosInstance.get(
|
||||||
{
|
`/monitors/${monitorId}?sortOrder=desc`,
|
||||||
headers: {
|
{
|
||||||
Authorization: `Bearer ${authToken}`,
|
headers: {
|
||||||
},
|
Authorization: `Bearer ${authToken}`,
|
||||||
}
|
},
|
||||||
);
|
}
|
||||||
|
);
|
||||||
|
|
||||||
setMonitor(res.data.data);
|
setMonitor(res.data.data);
|
||||||
setAudits(res.data.data.checks[0].audits);
|
setAudits(res.data.data.checks[0].audits);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching pagespeed monitor of id: " + monitorId);
|
||||||
|
navigate("/not-found");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fetchMonitor();
|
fetchMonitor();
|
||||||
@@ -244,360 +296,373 @@ const PageSpeedDetails = () => {
|
|||||||
const [highlightedItem, setHighLightedItem] = useState(null);
|
const [highlightedItem, setHighLightedItem] = useState(null);
|
||||||
const [expand, setExpand] = useState(false);
|
const [expand, setExpand] = useState(false);
|
||||||
|
|
||||||
|
let loading = Object.keys(monitor).length === 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack className="page-speed-details" gap={theme.gap.large}>
|
<Stack className="page-speed-details" gap={theme.gap.large}>
|
||||||
<Button
|
{loading ? (
|
||||||
level="tertiary"
|
<SkeletonLayout />
|
||||||
label="Back"
|
) : (
|
||||||
animate="slideLeft"
|
<>
|
||||||
img={<WestRoundedIcon />}
|
<Button
|
||||||
onClick={() => navigate("/pagespeed")}
|
level="tertiary"
|
||||||
sx={{
|
label="Back"
|
||||||
width: "fit-content",
|
animate="slideLeft"
|
||||||
backgroundColor: theme.palette.otherColors.fillGray,
|
img={<WestRoundedIcon />}
|
||||||
px: theme.gap.ml,
|
onClick={() => navigate("/pagespeed")}
|
||||||
"& svg.MuiSvgIcon-root": {
|
|
||||||
mr: theme.gap.small,
|
|
||||||
fill: theme.palette.otherColors.slateGray,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
gap={theme.gap.small}
|
|
||||||
justifyContent="space-between"
|
|
||||||
>
|
|
||||||
<GreenCheck />
|
|
||||||
<Box>
|
|
||||||
<Typography component="h1" mb={theme.gap.xs} sx={{ lineHeight: 1 }}>
|
|
||||||
{monitor?.url}
|
|
||||||
</Typography>
|
|
||||||
<Typography
|
|
||||||
component="span"
|
|
||||||
sx={{ color: "var(--env-var-color-17)" }}
|
|
||||||
>
|
|
||||||
Your pagespeed monitor is live.
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
<Button
|
|
||||||
level="tertiary"
|
|
||||||
label="Configure"
|
|
||||||
animate="rotate90"
|
|
||||||
img={
|
|
||||||
<SettingsIcon
|
|
||||||
style={{ width: theme.gap.mlplus, height: theme.gap.mlplus }}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
onClick={() => navigate(`/pagespeed/configure/${monitorId}`)}
|
|
||||||
sx={{
|
|
||||||
ml: "auto",
|
|
||||||
alignSelf: "flex-end",
|
|
||||||
backgroundColor: theme.palette.otherColors.fillGray,
|
|
||||||
px: theme.gap.medium,
|
|
||||||
"& svg": {
|
|
||||||
mr: "6px",
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
justifyContent="space-between"
|
|
||||||
gap={theme.gap.xl}
|
|
||||||
flexWrap="wrap"
|
|
||||||
>
|
|
||||||
<StatBox
|
|
||||||
icon={<LastCheckedIcon />}
|
|
||||||
title="Last checked"
|
|
||||||
value={
|
|
||||||
<>
|
|
||||||
{formatDate(getLastChecked(monitor?.checks, false))}{" "}
|
|
||||||
<Typography
|
|
||||||
component="span"
|
|
||||||
fontStyle="italic"
|
|
||||||
sx={{ opacity: 0.8 }}
|
|
||||||
>
|
|
||||||
({formatDurationRounded(getLastChecked(monitor?.checks))} ago)
|
|
||||||
</Typography>
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<StatBox
|
|
||||||
icon={<ClockIcon />}
|
|
||||||
title="Checks since"
|
|
||||||
value={
|
|
||||||
<>
|
|
||||||
{formatDate(new Date(monitor?.createdAt))}{" "}
|
|
||||||
<Typography
|
|
||||||
component="span"
|
|
||||||
fontStyle="italic"
|
|
||||||
sx={{ opacity: 0.8 }}
|
|
||||||
>
|
|
||||||
(
|
|
||||||
{formatDurationRounded(
|
|
||||||
new Date() - new Date(monitor?.createdAt)
|
|
||||||
)}{" "}
|
|
||||||
ago)
|
|
||||||
</Typography>
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
></StatBox>
|
|
||||||
<StatBox
|
|
||||||
icon={<IntervalCheckIcon />}
|
|
||||||
title="Checks every"
|
|
||||||
value={formatDurationRounded(monitor?.interval)}
|
|
||||||
></StatBox>
|
|
||||||
</Stack>
|
|
||||||
<Typography component="h2">Score history</Typography>
|
|
||||||
<Box height="300px">
|
|
||||||
<PageSpeedLineChart pageSpeedChecks={monitor?.checks?.slice(0, 25)} />
|
|
||||||
</Box>
|
|
||||||
<Typography component="h2">Performance report</Typography>
|
|
||||||
<Stack direction="row" alignItems="center" overflow="hidden">
|
|
||||||
<Stack
|
|
||||||
alignItems="center"
|
|
||||||
textAlign="center"
|
|
||||||
minWidth="300px"
|
|
||||||
flex={1}
|
|
||||||
px={theme.gap.xl}
|
|
||||||
py={theme.gap.ml}
|
|
||||||
>
|
|
||||||
<Box onMouseLeave={() => setExpand(false)}>
|
|
||||||
{expand ? (
|
|
||||||
<PieChart
|
|
||||||
series={[
|
|
||||||
{
|
|
||||||
data: [
|
|
||||||
{
|
|
||||||
value: 100,
|
|
||||||
color: colorMap.bg,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
outerRadius: 67,
|
|
||||||
cx: pieSize.width / 2,
|
|
||||||
},
|
|
||||||
...pieData,
|
|
||||||
]}
|
|
||||||
width={pieSize.width}
|
|
||||||
height={pieSize.height}
|
|
||||||
margin={{ left: 0, top: 0, right: 0, bottom: 0 }}
|
|
||||||
onHighlightChange={setHighLightedItem}
|
|
||||||
slotProps={{
|
|
||||||
legend: { hidden: true },
|
|
||||||
}}
|
|
||||||
tooltip={{ trigger: "none" }}
|
|
||||||
sx={{
|
|
||||||
"&:has(.MuiPieArcLabel-faded) .pie-label": {
|
|
||||||
fill: "rgba(0,0,0,0) !important",
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<PieCenterLabel
|
|
||||||
value={performance}
|
|
||||||
color={colorMap.text}
|
|
||||||
setExpand={setExpand}
|
|
||||||
/>
|
|
||||||
{pieData?.map((pie) => (
|
|
||||||
<PieValueLabel
|
|
||||||
key={pie.id}
|
|
||||||
value={Math.round(pie.data[0].value * 10) / 10}
|
|
||||||
startAngle={pie.startAngle}
|
|
||||||
endAngle={pie.endAngle}
|
|
||||||
color={pie.data[0].color}
|
|
||||||
highlighted={highlightedItem?.seriesId === pie.id}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</PieChart>
|
|
||||||
) : (
|
|
||||||
<PieChart
|
|
||||||
series={[
|
|
||||||
{
|
|
||||||
data: [
|
|
||||||
{
|
|
||||||
value: 100,
|
|
||||||
color: colorMap.bg,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
outerRadius: 67,
|
|
||||||
cx: pieSize.width / 2,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: [
|
|
||||||
{
|
|
||||||
value: performance,
|
|
||||||
color: colorMap.stroke,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
innerRadius: 63,
|
|
||||||
outerRadius: 70,
|
|
||||||
paddingAngle: 5,
|
|
||||||
cornerRadius: 2,
|
|
||||||
startAngle: 0,
|
|
||||||
endAngle: (performance / 100) * 360,
|
|
||||||
cx: pieSize.width / 2,
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
width={pieSize.width}
|
|
||||||
height={pieSize.height}
|
|
||||||
margin={{ left: 0, top: 0, right: 0, bottom: 0 }}
|
|
||||||
tooltip={{ trigger: "none" }}
|
|
||||||
>
|
|
||||||
<PieCenterLabel
|
|
||||||
value={performance}
|
|
||||||
color={colorMap.text}
|
|
||||||
setExpand={setExpand}
|
|
||||||
/>
|
|
||||||
</PieChart>
|
|
||||||
)}
|
|
||||||
</Box>
|
|
||||||
<Typography mt={theme.gap.medium}>
|
|
||||||
Values are estimated and may vary.{" "}
|
|
||||||
<Typography
|
|
||||||
component="span"
|
|
||||||
sx={{
|
|
||||||
color: theme.palette.primary.main,
|
|
||||||
fontWeight: 500,
|
|
||||||
textDecoration: "underline",
|
|
||||||
cursor: "pointer",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
See calculator
|
|
||||||
</Typography>
|
|
||||||
</Typography>
|
|
||||||
</Stack>
|
|
||||||
<Box
|
|
||||||
px={theme.gap.xl}
|
|
||||||
py={theme.gap.ml}
|
|
||||||
height="100%"
|
|
||||||
flex={1}
|
|
||||||
sx={{
|
|
||||||
borderLeft: `solid 1px ${theme.palette.otherColors.graishWhite}`,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Typography
|
|
||||||
mb={theme.gap.medium}
|
|
||||||
pb={theme.gap.ml}
|
|
||||||
color={theme.palette.secondary.main}
|
|
||||||
textAlign="center"
|
|
||||||
sx={{
|
sx={{
|
||||||
borderBottom: `solid 1px ${theme.palette.otherColors.graishWhite}`,
|
width: "fit-content",
|
||||||
borderBottomStyle: "dashed",
|
backgroundColor: theme.palette.otherColors.fillGray,
|
||||||
|
px: theme.gap.ml,
|
||||||
|
"& svg.MuiSvgIcon-root": {
|
||||||
|
mr: theme.gap.small,
|
||||||
|
fill: theme.palette.otherColors.slateGray,
|
||||||
|
},
|
||||||
}}
|
}}
|
||||||
>
|
/>
|
||||||
The{" "}
|
<Stack direction="row" gap={theme.gap.small}>
|
||||||
<Typography
|
<GreenCheck />
|
||||||
component="span"
|
<Box>
|
||||||
|
<Typography
|
||||||
|
component="h1"
|
||||||
|
mb={theme.gap.xs}
|
||||||
|
sx={{ lineHeight: 1 }}
|
||||||
|
>
|
||||||
|
{monitor?.url}
|
||||||
|
</Typography>
|
||||||
|
<Typography
|
||||||
|
component="span"
|
||||||
|
sx={{ color: "var(--env-var-color-17)" }}
|
||||||
|
>
|
||||||
|
Your pagespeed monitor is live.
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
<Button
|
||||||
|
level="tertiary"
|
||||||
|
label="Configure"
|
||||||
|
animate="rotate90"
|
||||||
|
img={
|
||||||
|
<SettingsIcon
|
||||||
|
style={{ width: theme.gap.mlplus, height: theme.gap.mlplus }}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
onClick={() => navigate(`/pagespeed/configure/${monitorId}`)}
|
||||||
sx={{
|
sx={{
|
||||||
color: theme.palette.primary.main,
|
ml: "auto",
|
||||||
fontWeight: 500,
|
alignSelf: "flex-end",
|
||||||
textDecoration: "underline",
|
backgroundColor: theme.palette.otherColors.fillGray,
|
||||||
cursor: "pointer",
|
px: theme.gap.medium,
|
||||||
|
"& svg": {
|
||||||
|
mr: "6px",
|
||||||
|
},
|
||||||
}}
|
}}
|
||||||
>
|
/>
|
||||||
performance score is calculated
|
</Stack>
|
||||||
</Typography>{" "}
|
|
||||||
directly from these{" "}
|
|
||||||
<Typography component="span" fontWeight={600}>
|
|
||||||
metrics
|
|
||||||
</Typography>
|
|
||||||
.
|
|
||||||
</Typography>
|
|
||||||
<Stack
|
<Stack
|
||||||
direction="row"
|
direction="row"
|
||||||
|
justifyContent="space-between"
|
||||||
|
gap={theme.gap.xl}
|
||||||
flexWrap="wrap"
|
flexWrap="wrap"
|
||||||
pt={theme.gap.ml}
|
|
||||||
gap={theme.gap.ml}
|
|
||||||
>
|
>
|
||||||
{Object.keys(audits).map((key) => {
|
<StatBox
|
||||||
if (key === "_id") return;
|
icon={<LastCheckedIcon />}
|
||||||
|
title="Last checked"
|
||||||
let audit = audits[key];
|
value={
|
||||||
let metricParams = getColors(audit.score * 100);
|
<>
|
||||||
|
{formatDate(getLastChecked(monitor?.checks, false))}{" "}
|
||||||
let shape = (
|
<Typography
|
||||||
<Box
|
component="span"
|
||||||
sx={{
|
fontStyle="italic"
|
||||||
width: theme.gap.medium,
|
sx={{ opacity: 0.8 }}
|
||||||
height: theme.gap.medium,
|
>
|
||||||
borderRadius: "50%",
|
({formatDurationRounded(getLastChecked(monitor?.checks))}{" "}
|
||||||
backgroundColor: metricParams.stroke,
|
ago)
|
||||||
}}
|
</Typography>
|
||||||
></Box>
|
</>
|
||||||
);
|
|
||||||
if (metricParams.shape === "square")
|
|
||||||
shape = (
|
|
||||||
<Box
|
|
||||||
sx={{
|
|
||||||
width: theme.gap.medium,
|
|
||||||
height: theme.gap.medium,
|
|
||||||
backgroundColor: metricParams.stroke,
|
|
||||||
}}
|
|
||||||
></Box>
|
|
||||||
);
|
|
||||||
else if (metricParams.shape === "triangle")
|
|
||||||
shape = (
|
|
||||||
<Box
|
|
||||||
sx={{
|
|
||||||
width: 0,
|
|
||||||
height: 0,
|
|
||||||
ml: `calc((${theme.gap.medium} - ${theme.gap.small}) / -2)`,
|
|
||||||
borderLeft: `${theme.gap.small} solid transparent`,
|
|
||||||
borderRight: `${theme.gap.small} solid transparent`,
|
|
||||||
borderBottom: `${theme.gap.medium} solid ${metricParams.stroke}`,
|
|
||||||
}}
|
|
||||||
></Box>
|
|
||||||
);
|
|
||||||
|
|
||||||
// Find the position where the number ends and the unit begins
|
|
||||||
const match = audit.displayValue.match(/(\d+\.?\d*)\s*([a-zA-Z]+)/);
|
|
||||||
let value;
|
|
||||||
let unit;
|
|
||||||
if (match) {
|
|
||||||
value = match[1];
|
|
||||||
unit = match[2];
|
|
||||||
} else {
|
|
||||||
value = audit.displayValue;
|
|
||||||
}
|
}
|
||||||
|
/>
|
||||||
return (
|
<StatBox
|
||||||
<Stack
|
icon={<ClockIcon />}
|
||||||
className="metric"
|
title="Checks since"
|
||||||
key={`${key}-box`}
|
value={
|
||||||
direction="row"
|
<>
|
||||||
gap={theme.gap.small}
|
{formatDate(new Date(monitor?.createdAt))}{" "}
|
||||||
>
|
<Typography
|
||||||
{shape}
|
component="span"
|
||||||
<Box>
|
fontStyle="italic"
|
||||||
<Typography sx={{ lineHeight: 1 }}>
|
sx={{ opacity: 0.8 }}
|
||||||
{audit.title}
|
>
|
||||||
</Typography>
|
(
|
||||||
<Typography
|
{formatDurationRounded(
|
||||||
component="span"
|
new Date() - new Date(monitor?.createdAt)
|
||||||
sx={{
|
)}{" "}
|
||||||
color: metricParams.text,
|
ago)
|
||||||
fontSize: "16px",
|
</Typography>
|
||||||
fontWeight: 600,
|
</>
|
||||||
}}
|
}
|
||||||
>
|
></StatBox>
|
||||||
{value}
|
<StatBox
|
||||||
<Typography
|
icon={<IntervalCheckIcon />}
|
||||||
component="span"
|
title="Checks every"
|
||||||
ml="2px"
|
value={formatDurationRounded(monitor?.interval)}
|
||||||
sx={{
|
></StatBox>
|
||||||
color: theme.palette.secondary.main,
|
|
||||||
fontSize: "13px",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{unit}
|
|
||||||
</Typography>
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</Stack>
|
</Stack>
|
||||||
</Box>
|
<Typography component="h2">Score history</Typography>
|
||||||
</Stack>
|
<Box height="300px">
|
||||||
|
<PageSpeedLineChart
|
||||||
|
pageSpeedChecks={monitor?.checks?.slice(0, 25)}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
<Typography component="h2">Performance report</Typography>
|
||||||
|
<Stack direction="row" alignItems="center" overflow="hidden">
|
||||||
|
<Stack
|
||||||
|
alignItems="center"
|
||||||
|
textAlign="center"
|
||||||
|
minWidth="300px"
|
||||||
|
flex={1}
|
||||||
|
px={theme.gap.xl}
|
||||||
|
py={theme.gap.ml}
|
||||||
|
>
|
||||||
|
<Box onMouseLeave={() => setExpand(false)}>
|
||||||
|
{expand ? (
|
||||||
|
<PieChart
|
||||||
|
series={[
|
||||||
|
{
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
value: 100,
|
||||||
|
color: colorMap.bg,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
outerRadius: 67,
|
||||||
|
cx: pieSize.width / 2,
|
||||||
|
},
|
||||||
|
...pieData,
|
||||||
|
]}
|
||||||
|
width={pieSize.width}
|
||||||
|
height={pieSize.height}
|
||||||
|
margin={{ left: 0, top: 0, right: 0, bottom: 0 }}
|
||||||
|
onHighlightChange={setHighLightedItem}
|
||||||
|
slotProps={{
|
||||||
|
legend: { hidden: true },
|
||||||
|
}}
|
||||||
|
tooltip={{ trigger: "none" }}
|
||||||
|
sx={{
|
||||||
|
"&:has(.MuiPieArcLabel-faded) .pie-label": {
|
||||||
|
fill: "rgba(0,0,0,0) !important",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<PieCenterLabel
|
||||||
|
value={performance}
|
||||||
|
color={colorMap.text}
|
||||||
|
setExpand={setExpand}
|
||||||
|
/>
|
||||||
|
{pieData?.map((pie) => (
|
||||||
|
<PieValueLabel
|
||||||
|
key={pie.id}
|
||||||
|
value={Math.round(pie.data[0].value * 10) / 10}
|
||||||
|
startAngle={pie.startAngle}
|
||||||
|
endAngle={pie.endAngle}
|
||||||
|
color={pie.data[0].color}
|
||||||
|
highlighted={highlightedItem?.seriesId === pie.id}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</PieChart>
|
||||||
|
) : (
|
||||||
|
<PieChart
|
||||||
|
series={[
|
||||||
|
{
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
value: 100,
|
||||||
|
color: colorMap.bg,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
outerRadius: 67,
|
||||||
|
cx: pieSize.width / 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
value: performance,
|
||||||
|
color: colorMap.stroke,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
innerRadius: 63,
|
||||||
|
outerRadius: 70,
|
||||||
|
paddingAngle: 5,
|
||||||
|
cornerRadius: 2,
|
||||||
|
startAngle: 0,
|
||||||
|
endAngle: (performance / 100) * 360,
|
||||||
|
cx: pieSize.width / 2,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
width={pieSize.width}
|
||||||
|
height={pieSize.height}
|
||||||
|
margin={{ left: 0, top: 0, right: 0, bottom: 0 }}
|
||||||
|
tooltip={{ trigger: "none" }}
|
||||||
|
>
|
||||||
|
<PieCenterLabel
|
||||||
|
value={performance}
|
||||||
|
color={colorMap.text}
|
||||||
|
setExpand={setExpand}
|
||||||
|
/>
|
||||||
|
</PieChart>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
<Typography mt={theme.gap.medium}>
|
||||||
|
Values are estimated and may vary.{" "}
|
||||||
|
<Typography
|
||||||
|
component="span"
|
||||||
|
sx={{
|
||||||
|
color: theme.palette.primary.main,
|
||||||
|
fontWeight: 500,
|
||||||
|
textDecoration: "underline",
|
||||||
|
cursor: "pointer",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
See calculator
|
||||||
|
</Typography>
|
||||||
|
</Typography>
|
||||||
|
</Stack>
|
||||||
|
<Box
|
||||||
|
px={theme.gap.xl}
|
||||||
|
py={theme.gap.ml}
|
||||||
|
height="100%"
|
||||||
|
flex={1}
|
||||||
|
sx={{
|
||||||
|
borderLeft: `solid 1px ${theme.palette.otherColors.graishWhite}`,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
mb={theme.gap.medium}
|
||||||
|
pb={theme.gap.ml}
|
||||||
|
color={theme.palette.secondary.main}
|
||||||
|
textAlign="center"
|
||||||
|
sx={{
|
||||||
|
borderBottom: `solid 1px ${theme.palette.otherColors.graishWhite}`,
|
||||||
|
borderBottomStyle: "dashed",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
The{" "}
|
||||||
|
<Typography
|
||||||
|
component="span"
|
||||||
|
sx={{
|
||||||
|
color: theme.palette.primary.main,
|
||||||
|
fontWeight: 500,
|
||||||
|
textDecoration: "underline",
|
||||||
|
cursor: "pointer",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
performance score is calculated
|
||||||
|
</Typography>{" "}
|
||||||
|
directly from these{" "}
|
||||||
|
<Typography component="span" fontWeight={600}>
|
||||||
|
metrics
|
||||||
|
</Typography>
|
||||||
|
.
|
||||||
|
</Typography>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
flexWrap="wrap"
|
||||||
|
pt={theme.gap.ml}
|
||||||
|
gap={theme.gap.ml}
|
||||||
|
>
|
||||||
|
{Object.keys(audits).map((key) => {
|
||||||
|
if (key === "_id") return;
|
||||||
|
|
||||||
|
let audit = audits[key];
|
||||||
|
let metricParams = getColors(audit.score * 100);
|
||||||
|
|
||||||
|
let shape = (
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
width: theme.gap.medium,
|
||||||
|
height: theme.gap.medium,
|
||||||
|
borderRadius: "50%",
|
||||||
|
backgroundColor: metricParams.stroke,
|
||||||
|
}}
|
||||||
|
></Box>
|
||||||
|
);
|
||||||
|
if (metricParams.shape === "square")
|
||||||
|
shape = (
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
width: theme.gap.medium,
|
||||||
|
height: theme.gap.medium,
|
||||||
|
backgroundColor: metricParams.stroke,
|
||||||
|
}}
|
||||||
|
></Box>
|
||||||
|
);
|
||||||
|
else if (metricParams.shape === "triangle")
|
||||||
|
shape = (
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
width: 0,
|
||||||
|
height: 0,
|
||||||
|
ml: `calc((${theme.gap.medium} - ${theme.gap.small}) / -2)`,
|
||||||
|
borderLeft: `${theme.gap.small} solid transparent`,
|
||||||
|
borderRight: `${theme.gap.small} solid transparent`,
|
||||||
|
borderBottom: `${theme.gap.medium} solid ${metricParams.stroke}`,
|
||||||
|
}}
|
||||||
|
></Box>
|
||||||
|
);
|
||||||
|
|
||||||
|
// Find the position where the number ends and the unit begins
|
||||||
|
const match = audit.displayValue.match(
|
||||||
|
/(\d+\.?\d*)\s*([a-zA-Z]+)/
|
||||||
|
);
|
||||||
|
let value;
|
||||||
|
let unit;
|
||||||
|
if (match) {
|
||||||
|
value = match[1];
|
||||||
|
unit = match[2];
|
||||||
|
} else {
|
||||||
|
value = audit.displayValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Stack
|
||||||
|
className="metric"
|
||||||
|
key={`${key}-box`}
|
||||||
|
direction="row"
|
||||||
|
gap={theme.gap.small}
|
||||||
|
>
|
||||||
|
{shape}
|
||||||
|
<Box>
|
||||||
|
<Typography sx={{ lineHeight: 1 }}>
|
||||||
|
{audit.title}
|
||||||
|
</Typography>
|
||||||
|
<Typography
|
||||||
|
component="span"
|
||||||
|
sx={{
|
||||||
|
color: metricParams.text,
|
||||||
|
fontSize: "16px",
|
||||||
|
fontWeight: 600,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{value}
|
||||||
|
<Typography
|
||||||
|
component="span"
|
||||||
|
ml="2px"
|
||||||
|
sx={{
|
||||||
|
color: theme.palette.secondary.main,
|
||||||
|
fontSize: "13px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{unit}
|
||||||
|
</Typography>
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</Stack>
|
||||||
|
</Box>
|
||||||
|
</Stack>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Box, Grid, Stack, Typography } from "@mui/material";
|
import { Box, Grid, Skeleton, Stack, Typography } from "@mui/material";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { formatDate, formatDurationRounded } from "../../Utils/timeUtils";
|
import { formatDate, formatDurationRounded } from "../../Utils/timeUtils";
|
||||||
@@ -57,20 +57,89 @@ const Card = ({ data }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders a skeleton layout.
|
||||||
|
*
|
||||||
|
* @returns {JSX.Element}
|
||||||
|
*/
|
||||||
|
const SkeletonLayout = () => {
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Stack gap={theme.gap.xs}>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
justifyContent="space-between"
|
||||||
|
mb={theme.gap.large}
|
||||||
|
>
|
||||||
|
<Box width="80%">
|
||||||
|
<Skeleton variant="rounded" width="25%" height={24} />
|
||||||
|
<Skeleton
|
||||||
|
variant="rounded"
|
||||||
|
width="50%"
|
||||||
|
height={19.5}
|
||||||
|
sx={{ mt: theme.gap.xs }}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
<Skeleton
|
||||||
|
variant="rounded"
|
||||||
|
width="20%"
|
||||||
|
height={34}
|
||||||
|
sx={{ alignSelf: "flex-end" }}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
<Stack direction="row" flexWrap="wrap" gap={theme.gap.large}>
|
||||||
|
<Skeleton
|
||||||
|
variant="rounded"
|
||||||
|
width="100%"
|
||||||
|
height={120}
|
||||||
|
sx={{ flex: "35%" }}
|
||||||
|
/>
|
||||||
|
<Skeleton
|
||||||
|
variant="rounded"
|
||||||
|
width="100%"
|
||||||
|
height={120}
|
||||||
|
sx={{ flex: "35%" }}
|
||||||
|
/>
|
||||||
|
<Skeleton
|
||||||
|
variant="rounded"
|
||||||
|
width="100%"
|
||||||
|
height={120}
|
||||||
|
sx={{ flex: "35%" }}
|
||||||
|
/>
|
||||||
|
<Skeleton
|
||||||
|
variant="rounded"
|
||||||
|
width="100%"
|
||||||
|
height={120}
|
||||||
|
sx={{ flex: "35%" }}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const PageSpeed = () => {
|
const PageSpeed = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const { authToken } = useSelector((state) => state.auth);
|
const { authToken } = useSelector((state) => state.auth);
|
||||||
const { monitors } = useSelector((state) => state.pageSpeedMonitors);
|
const { monitors, isLoading } = useSelector(
|
||||||
|
(state) => state.pageSpeedMonitors
|
||||||
|
);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(getPageSpeedByUserId(authToken));
|
dispatch(getPageSpeedByUserId(authToken));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// will show skeletons only on initial load
|
||||||
|
// since monitor state is being added to redux persist, there's no reason to display skeletons on every render
|
||||||
|
let isActuallyLoading = isLoading && monitors.length === 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box className="page-speed">
|
<Box className="page-speed">
|
||||||
{monitors?.length !== 0 ? (
|
{isActuallyLoading ? (
|
||||||
|
<SkeletonLayout />
|
||||||
|
) : monitors?.length !== 0 ? (
|
||||||
<Stack gap={theme.gap.xs}>
|
<Stack gap={theme.gap.xs}>
|
||||||
<Stack
|
<Stack
|
||||||
direction="row"
|
direction="row"
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in new issue
Block a user