Merge branch 'develop' into feat/fe/ttl
This commit is contained in:
8 files changed
+553
-209
No files matched your search
@@ -96,7 +96,12 @@ const Monitors = ({ isAdmin }) => {
|
|||||||
alignItems="center"
|
alignItems="center"
|
||||||
mb={theme.spacing(8)}
|
mb={theme.spacing(8)}
|
||||||
>
|
>
|
||||||
<Typography component="h2" variant="h2" letterSpacing={-0.5}>
|
<Typography
|
||||||
|
component="h2"
|
||||||
|
variant="h2"
|
||||||
|
fontWeight={500}
|
||||||
|
letterSpacing={-0.2}
|
||||||
|
>
|
||||||
Actively monitoring
|
Actively monitoring
|
||||||
</Typography>
|
</Typography>
|
||||||
<Box
|
<Box
|
||||||
|
|||||||
@@ -52,12 +52,35 @@ const useUtils = () => {
|
|||||||
"& h2": { color: theme.palette.warning.main },
|
"& h2": { color: theme.palette.warning.main },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
const pagespeedStyles = {
|
||||||
|
up: {
|
||||||
|
bg: theme.palette.success.bg,
|
||||||
|
light: theme.palette.success.light,
|
||||||
|
stroke: theme.palette.success.main,
|
||||||
|
},
|
||||||
|
down: {
|
||||||
|
bg: theme.palette.error.bg,
|
||||||
|
light: theme.palette.error.light,
|
||||||
|
stroke: theme.palette.error.main,
|
||||||
|
},
|
||||||
|
paused: {
|
||||||
|
bg: theme.palette.warning.bg,
|
||||||
|
light: theme.palette.warning.light,
|
||||||
|
stroke: theme.palette.warning.main,
|
||||||
|
},
|
||||||
|
pending: {
|
||||||
|
bg: theme.palette.warning.bg,
|
||||||
|
light: theme.palette.warning.light,
|
||||||
|
stroke: theme.palette.warning.main,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
determineState,
|
determineState,
|
||||||
statusColor,
|
statusColor,
|
||||||
statusMsg,
|
statusMsg,
|
||||||
pagespeedStatusMsg,
|
pagespeedStatusMsg,
|
||||||
|
pagespeedStyles,
|
||||||
statusStyles,
|
statusStyles,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,37 +1,7 @@
|
|||||||
.configure-pagespeed span.MuiTypography-root {
|
|
||||||
font-size: var(--env-var-font-size-small-plus);
|
|
||||||
}
|
|
||||||
.configure-pagespeed h3.MuiTypography-root {
|
|
||||||
font-weight: 500;
|
|
||||||
}
|
|
||||||
.configure-pagespeed .MuiBox-root > .field + p.MuiTypography-root {
|
|
||||||
font-size: var(--env-var-font-size-small-plus);
|
|
||||||
}
|
|
||||||
.configure-pagespeed .MuiBox-root > .field + p.MuiTypography-root,
|
|
||||||
.configure-pagespeed h3.MuiTypography-root > span.MuiTypography-root {
|
|
||||||
opacity: 0.6;
|
|
||||||
}
|
|
||||||
.configure-pagespeed .checkbox-wrapper {
|
|
||||||
margin-bottom: 1px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* to be removed */
|
|
||||||
.configure-pagespeed .section-disabled {
|
|
||||||
opacity: 0.4;
|
|
||||||
padding: 10px;
|
|
||||||
border-radius: 8px;
|
|
||||||
user-select: none;
|
|
||||||
pointer-events: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.configure-pagespeed button {
|
.configure-pagespeed button {
|
||||||
height: var(--env-var-height-2);
|
height: var(--env-var-height-2);
|
||||||
}
|
}
|
||||||
|
|
||||||
.configure-pagespeed h3.MuiTypography-root {
|
|
||||||
flex: 0.7;
|
|
||||||
}
|
|
||||||
|
|
||||||
.configure-pagespeed .field,
|
.configure-pagespeed .field,
|
||||||
.configure-pagespeed .section-disabled,
|
.configure-pagespeed .section-disabled,
|
||||||
.configure-pagespeed .select-wrapper {
|
.configure-pagespeed .select-wrapper {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { Box, Button, Modal, Stack, Typography } from "@mui/material";
|
import { Box, Button, Modal, Stack, Tooltip, Typography } from "@mui/material";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import { useNavigate, useParams } from "react-router";
|
import { useNavigate, useParams } from "react-router";
|
||||||
import {
|
import {
|
||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
import { monitorValidation } from "../../../Validation/validation";
|
import { monitorValidation } from "../../../Validation/validation";
|
||||||
import { createToast } from "../../../Utils/toastUtils";
|
import { createToast } from "../../../Utils/toastUtils";
|
||||||
import { logger } from "../../../Utils/Logger";
|
import { logger } from "../../../Utils/Logger";
|
||||||
|
import { ConfigBox } from "../../Monitors/styled";
|
||||||
import Field from "../../../Components/Inputs/Field";
|
import Field from "../../../Components/Inputs/Field";
|
||||||
import Select from "../../../Components/Inputs/Select";
|
import Select from "../../../Components/Inputs/Select";
|
||||||
import Checkbox from "../../../Components/Inputs/Checkbox";
|
import Checkbox from "../../../Components/Inputs/Checkbox";
|
||||||
@@ -22,20 +23,27 @@ import PulseDot from "../../../Components/Animated/PulseDot";
|
|||||||
import LoadingButton from "@mui/lab/LoadingButton";
|
import LoadingButton from "@mui/lab/LoadingButton";
|
||||||
import PlayCircleOutlineRoundedIcon from "@mui/icons-material/PlayCircleOutlineRounded";
|
import PlayCircleOutlineRoundedIcon from "@mui/icons-material/PlayCircleOutlineRounded";
|
||||||
import SkeletonLayout from "./skeleton";
|
import SkeletonLayout from "./skeleton";
|
||||||
import "./index.css";
|
|
||||||
import useUtils from "../../Monitors/utils";
|
import useUtils from "../../Monitors/utils";
|
||||||
|
import "./index.css";
|
||||||
|
|
||||||
const PageSpeedConfigure = () => {
|
const PageSpeedConfigure = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const MS_PER_MINUTE = 60000;
|
const MS_PER_MINUTE = 60000;
|
||||||
const { authToken } = useSelector((state) => state.auth);
|
const { user, authToken } = useSelector((state) => state.auth);
|
||||||
const { isLoading } = useSelector((state) => state.pageSpeedMonitors);
|
const { isLoading } = useSelector((state) => state.pageSpeedMonitors);
|
||||||
const { monitorId } = useParams();
|
const { monitorId } = useParams();
|
||||||
const [monitor, setMonitor] = useState({});
|
const [monitor, setMonitor] = useState({});
|
||||||
const [errors, setErrors] = useState({});
|
const [errors, setErrors] = useState({});
|
||||||
const { determineState, statusColor } = useUtils();
|
const { statusColor, pagespeedStatusMsg, determineState } = useUtils();
|
||||||
|
const idMap = {
|
||||||
|
"monitor-url": "url",
|
||||||
|
"monitor-name": "name",
|
||||||
|
"monitor-checks-http": "type",
|
||||||
|
"monitor-checks-ping": "type",
|
||||||
|
"notify-email-default": "notification-email",
|
||||||
|
};
|
||||||
|
|
||||||
const frequencies = [
|
const frequencies = [
|
||||||
{ _id: 3, name: "3 minutes" },
|
{ _id: 3, name: "3 minutes" },
|
||||||
@@ -68,24 +76,58 @@ const PageSpeedConfigure = () => {
|
|||||||
fetchMonitor();
|
fetchMonitor();
|
||||||
}, [dispatch, authToken, monitorId, navigate]);
|
}, [dispatch, authToken, monitorId, navigate]);
|
||||||
|
|
||||||
const handleChange = (event, id) => {
|
const handleChange = (event, name) => {
|
||||||
let { value } = event.target;
|
let { value, id } = event.target;
|
||||||
if (id === "interval") {
|
if (!name) name = idMap[id];
|
||||||
value = value * MS_PER_MINUTE;
|
|
||||||
|
if (name.includes("notification-")) {
|
||||||
|
name = name.replace("notification-", "");
|
||||||
|
let hasNotif = monitor.notifications.some(
|
||||||
|
(notification) => notification.type === name
|
||||||
|
);
|
||||||
|
setMonitor((prev) => {
|
||||||
|
const notifs = [...prev.notifications];
|
||||||
|
if (hasNotif) {
|
||||||
|
return {
|
||||||
|
...prev,
|
||||||
|
notifications: notifs.filter((notif) => notif.type !== name),
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
...prev,
|
||||||
|
notifications: [
|
||||||
|
...notifs,
|
||||||
|
name === "email"
|
||||||
|
? { type: name, address: value }
|
||||||
|
: // TODO - phone number
|
||||||
|
{ type: name, phone: value },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
if (name === "interval") {
|
||||||
|
value = value * MS_PER_MINUTE;
|
||||||
|
}
|
||||||
|
setMonitor((prev) => ({
|
||||||
|
...prev,
|
||||||
|
[name]: value,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const validation = monitorValidation.validate(
|
||||||
|
{ [name]: value },
|
||||||
|
{ abortEarly: false }
|
||||||
|
);
|
||||||
|
|
||||||
|
setErrors((prev) => {
|
||||||
|
const updatedErrors = { ...prev };
|
||||||
|
|
||||||
|
if (validation.error)
|
||||||
|
updatedErrors[name] = validation.error.details[0].message;
|
||||||
|
else delete updatedErrors[name];
|
||||||
|
return updatedErrors;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
setMonitor((prev) => ({ ...prev, [id]: value }));
|
|
||||||
|
|
||||||
const { error } = monitorValidation.validate(
|
|
||||||
{ [id]: value },
|
|
||||||
{ abortEarly: false }
|
|
||||||
);
|
|
||||||
|
|
||||||
setErrors((prev) => {
|
|
||||||
const newErrors = { ...prev };
|
|
||||||
if (error) newErrors[id] = error.details[0].message;
|
|
||||||
else delete newErrors[id];
|
|
||||||
return newErrors;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handlePause = async () => {
|
const handlePause = async () => {
|
||||||
@@ -128,7 +170,7 @@ const PageSpeedConfigure = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack className="configure-pagespeed" gap={theme.spacing(12)}>
|
<Stack className="configure-pagespeed" gap={theme.spacing(10)}>
|
||||||
{Object.keys(monitor).length === 0 ? (
|
{Object.keys(monitor).length === 0 ? (
|
||||||
<SkeletonLayout />
|
<SkeletonLayout />
|
||||||
) : (
|
) : (
|
||||||
@@ -146,22 +188,65 @@ const PageSpeedConfigure = () => {
|
|||||||
spellCheck="false"
|
spellCheck="false"
|
||||||
onSubmit={handleSave}
|
onSubmit={handleSave}
|
||||||
flex={1}
|
flex={1}
|
||||||
gap={theme.spacing(12)}
|
gap={theme.spacing(10)}
|
||||||
>
|
>
|
||||||
<Stack direction="row" gap={theme.spacing(2)}>
|
<Stack direction="row" gap={theme.spacing(2)}>
|
||||||
<PulseDot color={statusColor[determineState(monitor)]} />
|
|
||||||
<Box>
|
<Box>
|
||||||
<Typography component="h1" variant="h1" mb={theme.spacing(2)}>
|
<Typography component="h1" variant="h1">
|
||||||
{monitor?.url}
|
{monitor.name}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography
|
<Stack
|
||||||
component="span"
|
direction="row"
|
||||||
sx={{
|
alignItems="center"
|
||||||
color: statusColor[determineState(monitor)],
|
height="fit-content"
|
||||||
}}
|
gap={theme.spacing(2)}
|
||||||
>
|
>
|
||||||
Your pagespeed monitor is {determineState(monitor)}.
|
<Tooltip
|
||||||
</Typography>
|
title={pagespeedStatusMsg[determineState(monitor)]}
|
||||||
|
disableInteractive
|
||||||
|
slotProps={{
|
||||||
|
popper: {
|
||||||
|
modifiers: [
|
||||||
|
{
|
||||||
|
name: "offset",
|
||||||
|
options: {
|
||||||
|
offset: [0, -8],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box>
|
||||||
|
<PulseDot color={statusColor[determineState(monitor)]} />
|
||||||
|
</Box>
|
||||||
|
</Tooltip>
|
||||||
|
<Typography component="h2" variant="h2">
|
||||||
|
{monitor.url?.replace(/^https?:\/\//, "") || "..."}
|
||||||
|
</Typography>
|
||||||
|
<Typography
|
||||||
|
position="relative"
|
||||||
|
variant="body2"
|
||||||
|
ml={theme.spacing(6)}
|
||||||
|
mt={theme.spacing(1)}
|
||||||
|
sx={{
|
||||||
|
"&:before": {
|
||||||
|
position: "absolute",
|
||||||
|
content: `""`,
|
||||||
|
width: 4,
|
||||||
|
height: 4,
|
||||||
|
borderRadius: "50%",
|
||||||
|
backgroundColor: theme.palette.text.tertiary,
|
||||||
|
opacity: 0.8,
|
||||||
|
left: -10,
|
||||||
|
top: "50%",
|
||||||
|
transform: "translateY(-50%)",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Editting...
|
||||||
|
</Typography>
|
||||||
|
</Stack>
|
||||||
</Box>
|
</Box>
|
||||||
<Box alignSelf="flex-end" ml="auto">
|
<Box alignSelf="flex-end" ml="auto">
|
||||||
<LoadingButton
|
<LoadingButton
|
||||||
@@ -206,102 +291,116 @@ const PageSpeedConfigure = () => {
|
|||||||
</LoadingButton>
|
</LoadingButton>
|
||||||
</Box>
|
</Box>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Stack
|
<ConfigBox>
|
||||||
border={1}
|
<Box>
|
||||||
borderColor={theme.palette.border.light}
|
<Typography component="h2">General settings</Typography>
|
||||||
borderRadius={theme.shape.borderRadius}
|
<Typography component="p">
|
||||||
backgroundColor={theme.palette.background.main}
|
Here you can select the URL of the host, together with the
|
||||||
p={theme.spacing(20)}
|
type of monitor.
|
||||||
pl={theme.spacing(15)}
|
</Typography>
|
||||||
gap={theme.spacing(20)}
|
</Box>
|
||||||
sx={{
|
|
||||||
"& h3, & p": {
|
|
||||||
color: theme.palette.text.secondary,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Stack direction="row">
|
|
||||||
<Typography component="h3">Monitor display name</Typography>
|
|
||||||
<Field
|
|
||||||
type="text"
|
|
||||||
id="monitor-name"
|
|
||||||
placeholder="Example monitor"
|
|
||||||
value={monitor?.name || ""}
|
|
||||||
onChange={(event) => handleChange(event, "name")}
|
|
||||||
error={errors.name}
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
<Stack
|
<Stack
|
||||||
direction="row"
|
gap={theme.spacing(20)}
|
||||||
sx={{
|
sx={{
|
||||||
".MuiInputBase-root:has(> .Mui-disabled)": {
|
".MuiInputBase-root:has(> .Mui-disabled)": {
|
||||||
backgroundColor: theme.palette.background.accent,
|
backgroundColor: theme.palette.background.accent,
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Typography component="h3">URL</Typography>
|
|
||||||
<Field
|
<Field
|
||||||
type="url"
|
type="url"
|
||||||
id="monitor-url"
|
id="monitor-url"
|
||||||
|
label="URL"
|
||||||
placeholder="random.website.com"
|
placeholder="random.website.com"
|
||||||
value={monitor?.url?.replace("http://", "") || ""}
|
value={monitor?.url?.replace("http://", "") || ""}
|
||||||
onChange={(event) => handleChange(event, "url")}
|
onChange={handleChange}
|
||||||
error={errors.url}
|
error={errors.url}
|
||||||
disabled={true}
|
disabled={true}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
<Field
|
||||||
<Stack direction="row">
|
type="text"
|
||||||
<Typography component="h3">Check frequency</Typography>
|
id="monitor-name"
|
||||||
<Select
|
label="Monitor display name"
|
||||||
id="monitor-frequency"
|
placeholder="Example monitor"
|
||||||
items={frequencies}
|
isOptional={true}
|
||||||
value={monitor?.interval / MS_PER_MINUTE || 3}
|
value={monitor?.name || ""}
|
||||||
onChange={(event) => handleChange(event, "interval")}
|
onChange={handleChange}
|
||||||
|
error={errors.name}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Stack direction="row">
|
</ConfigBox>
|
||||||
<Typography component="h3">
|
<ConfigBox>
|
||||||
Incidents notifications{" "}
|
<Box>
|
||||||
<Typography component="span">(coming soon)</Typography>
|
<Typography component="h2">Incident notifications</Typography>
|
||||||
|
<Typography component="p">
|
||||||
|
When there is an incident, notify users.
|
||||||
</Typography>
|
</Typography>
|
||||||
<Stack
|
</Box>
|
||||||
className="section-disabled"
|
<Stack gap={theme.spacing(6)}>
|
||||||
backgroundColor={theme.palette.background.fill}
|
<Typography component="p">
|
||||||
>
|
When there is a new incident,
|
||||||
<Typography mb={theme.spacing(4)}>
|
</Typography>
|
||||||
When there is a new incident,
|
<Checkbox
|
||||||
</Typography>
|
id="notify-sms"
|
||||||
<Checkbox
|
label="Notify via SMS (coming soon)"
|
||||||
id="notify-sms"
|
isChecked={false}
|
||||||
label="Notify via SMS (coming soon)"
|
value=""
|
||||||
isChecked={false}
|
onChange={() => logger.warn("disabled")}
|
||||||
isDisabled={true}
|
isDisabled={true}
|
||||||
/>
|
/>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
id="notify-email"
|
id="notify-email-default"
|
||||||
label="Notify via email (to gorkem.cetin@bluewavelabs.ca)"
|
label={`Notify via email (to ${user.email})`}
|
||||||
isChecked={false}
|
isChecked={
|
||||||
/>
|
monitor?.notifications?.some(
|
||||||
<Checkbox
|
(notification) => notification.type === "email"
|
||||||
id="notify-emails"
|
) || false
|
||||||
label="Notify via email to following emails"
|
}
|
||||||
isChecked={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={() => logger.warn("disabled")}
|
||||||
|
isDisabled={true}
|
||||||
|
/>
|
||||||
|
{monitor?.notifications?.some(
|
||||||
|
(notification) => notification.type === "emails"
|
||||||
|
) ? (
|
||||||
<Box mx={theme.spacing(16)}>
|
<Box mx={theme.spacing(16)}>
|
||||||
<Field
|
<Field
|
||||||
id="notify-emails-list"
|
id="notify-email-list"
|
||||||
placeholder="notifications@gmail.com"
|
type="text"
|
||||||
|
placeholder="name@gmail.com"
|
||||||
value=""
|
value=""
|
||||||
onChange={() => logger.warn("disabled")}
|
onChange={() => logger.warn("disabled")}
|
||||||
error=""
|
|
||||||
/>
|
/>
|
||||||
<Typography mt={theme.spacing(4)}>
|
<Typography mt={theme.spacing(4)}>
|
||||||
You can separate multiple emails with a comma
|
You can separate multiple emails with a comma
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
</Stack>
|
) : (
|
||||||
|
""
|
||||||
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
</Stack>
|
</ConfigBox>
|
||||||
|
<ConfigBox>
|
||||||
|
<Box>
|
||||||
|
<Typography component="h2">Advanced settings</Typography>
|
||||||
|
</Box>
|
||||||
|
<Stack gap={theme.spacing(20)}>
|
||||||
|
<Select
|
||||||
|
id="monitor-frequency"
|
||||||
|
label="Check frequency"
|
||||||
|
items={frequencies}
|
||||||
|
value={monitor?.interval / MS_PER_MINUTE || 3}
|
||||||
|
onChange={(event) => handleChange(event, "interval")}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
</ConfigBox>
|
||||||
<Stack direction="row" justifyContent="flex-end" mt="auto">
|
<Stack direction="row" justifyContent="flex-end" mt="auto">
|
||||||
<LoadingButton
|
<LoadingButton
|
||||||
loading={isLoading}
|
loading={isLoading}
|
||||||
@@ -347,6 +446,7 @@ const PageSpeedConfigure = () => {
|
|||||||
id="modal-delete-pagespeed-monitor"
|
id="modal-delete-pagespeed-monitor"
|
||||||
component="h2"
|
component="h2"
|
||||||
variant="h2"
|
variant="h2"
|
||||||
|
fontWeight={500}
|
||||||
>
|
>
|
||||||
Do you really want to delete this monitor?
|
Do you really want to delete this monitor?
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|||||||
@@ -29,11 +29,13 @@ import PulseDot from "../../../Components/Animated/PulseDot";
|
|||||||
import PagespeedDetailsAreaChart from "./Charts/AreaChart";
|
import PagespeedDetailsAreaChart from "./Charts/AreaChart";
|
||||||
import Checkbox from "../../../Components/Inputs/Checkbox";
|
import Checkbox from "../../../Components/Inputs/Checkbox";
|
||||||
import PieChart from "./Charts/PieChart";
|
import PieChart from "./Charts/PieChart";
|
||||||
|
import useUtils from "../../Monitors/utils";
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
|
|
||||||
const PageSpeedDetails = () => {
|
const PageSpeedDetails = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const { statusColor, pagespeedStatusMsg, determineState } = useUtils();
|
||||||
const [monitor, setMonitor] = useState({});
|
const [monitor, setMonitor] = useState({});
|
||||||
const [audits, setAudits] = useState({});
|
const [audits, setAudits] = useState({});
|
||||||
const { monitorId } = useParams();
|
const { monitorId } = useParams();
|
||||||
@@ -109,11 +111,7 @@ const PageSpeedDetails = () => {
|
|||||||
gap={theme.spacing(2)}
|
gap={theme.spacing(2)}
|
||||||
>
|
>
|
||||||
<Tooltip
|
<Tooltip
|
||||||
title={
|
title={pagespeedStatusMsg[determineState(monitor)]}
|
||||||
monitor?.status
|
|
||||||
? "Your pagespeed monitor is live."
|
|
||||||
: "Your pagespeed monitor is down."
|
|
||||||
}
|
|
||||||
disableInteractive
|
disableInteractive
|
||||||
slotProps={{
|
slotProps={{
|
||||||
popper: {
|
popper: {
|
||||||
@@ -129,13 +127,7 @@ const PageSpeedDetails = () => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Box>
|
<Box>
|
||||||
<PulseDot
|
<PulseDot color={statusColor[determineState(monitor)]} />
|
||||||
color={
|
|
||||||
monitor?.status
|
|
||||||
? theme.palette.success.main
|
|
||||||
: theme.palette.error.main
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</Box>
|
</Box>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Typography component="h2" variant="h2">
|
<Typography component="h2" variant="h2">
|
||||||
|
|||||||
@@ -1,32 +1,220 @@
|
|||||||
|
import PropTypes from "prop-types";
|
||||||
import PageSpeedIcon from "../../assets/icons/page-speed.svg?react";
|
import PageSpeedIcon from "../../assets/icons/page-speed.svg?react";
|
||||||
import { StatusLabel } from "../../Components/Label";
|
import { StatusLabel } from "../../Components/Label";
|
||||||
import { Box, Grid, Stack, Typography } from "@mui/material";
|
import { Box, Grid, Stack, Typography } from "@mui/material";
|
||||||
import { useNavigate } from "react-router";
|
import { useNavigate } from "react-router";
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { formatDate, formatDurationRounded } from "../../Utils/timeUtils";
|
import { IconBox } from "./Details/styled";
|
||||||
import { getLastChecked } from "../../Utils/monitorUtils";
|
import {
|
||||||
|
Area,
|
||||||
|
AreaChart,
|
||||||
|
CartesianGrid,
|
||||||
|
ResponsiveContainer,
|
||||||
|
Tooltip,
|
||||||
|
} from "recharts";
|
||||||
|
import { useSelector } from "react-redux";
|
||||||
|
import {
|
||||||
|
formatDateWithTz,
|
||||||
|
formatDurationRounded,
|
||||||
|
formatDurationSplit,
|
||||||
|
} from "../../Utils/timeUtils";
|
||||||
import useUtils from "../Monitors/utils";
|
import useUtils from "../Monitors/utils";
|
||||||
import PropTypes from "prop-types";
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CustomToolTip displays a tooltip with formatted date and score information.
|
||||||
|
* @param {Object} props
|
||||||
|
* @param {Array} props.payload - Data to display in the tooltip
|
||||||
|
* @returns {JSX.Element} The rendered tooltip component
|
||||||
|
*/
|
||||||
|
const CustomToolTip = ({ payload }) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const uiTimezone = useSelector((state) => state.ui.timezone);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
backgroundColor: theme.palette.background.main,
|
||||||
|
border: 1,
|
||||||
|
borderColor: theme.palette.border.dark,
|
||||||
|
borderRadius: theme.shape.borderRadius,
|
||||||
|
py: theme.spacing(2),
|
||||||
|
px: theme.spacing(4),
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
sx={{
|
||||||
|
color: theme.palette.text.tertiary,
|
||||||
|
fontSize: 12,
|
||||||
|
fontWeight: 500,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{formatDateWithTz(
|
||||||
|
payload[0]?.payload.createdAt,
|
||||||
|
"ddd, MMMM D, YYYY, h:mm A",
|
||||||
|
uiTimezone
|
||||||
|
)}
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
alignItems="center"
|
||||||
|
gap={theme.spacing(3)}
|
||||||
|
mt={theme.spacing(1)}
|
||||||
|
sx={{
|
||||||
|
"& span": {
|
||||||
|
color: theme.palette.text.tertiary,
|
||||||
|
fontSize: 11,
|
||||||
|
fontWeight: 500,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box
|
||||||
|
width={theme.spacing(4)}
|
||||||
|
height={theme.spacing(4)}
|
||||||
|
backgroundColor={payload[0]?.color}
|
||||||
|
sx={{ borderRadius: "50%" }}
|
||||||
|
/>
|
||||||
|
<Typography
|
||||||
|
component="span"
|
||||||
|
textTransform="capitalize"
|
||||||
|
sx={{ opacity: 0.8 }}
|
||||||
|
>
|
||||||
|
{payload[0]?.name}
|
||||||
|
</Typography>{" "}
|
||||||
|
<Typography component="span">{payload[0]?.payload.score}</Typography>
|
||||||
|
</Stack>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
CustomToolTip.propTypes = {
|
||||||
|
payload: PropTypes.array,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes the raw data to include a score for each entry.
|
||||||
|
* @param {Array<Object>} data - The raw data array.
|
||||||
|
* @returns {Array<Object>} - The formatted data array with scores.
|
||||||
|
*/
|
||||||
|
const processData = (data) => {
|
||||||
|
if (data.length === 0) return [];
|
||||||
|
let formattedData = [];
|
||||||
|
|
||||||
|
const calculateScore = (entry) => {
|
||||||
|
return (
|
||||||
|
(entry.accessibility +
|
||||||
|
entry.bestPractices +
|
||||||
|
entry.performance +
|
||||||
|
entry.seo) /
|
||||||
|
4
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
data.forEach((entry) => {
|
||||||
|
entry = { ...entry, score: calculateScore(entry) };
|
||||||
|
formattedData.push(entry);
|
||||||
|
});
|
||||||
|
|
||||||
|
return formattedData;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders an area chart displaying page speed scores.
|
||||||
|
* @param {Object} props
|
||||||
|
* @param {Array<Object>} props.data - The raw data to be displayed in the chart.
|
||||||
|
* @param {string} props.status - The status of the page speed which determines the chart's color scheme.
|
||||||
|
* @returns {JSX.Element} - The rendered area chart.
|
||||||
|
*/
|
||||||
|
const PagespeedAreaChart = ({ data, status }) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const { pagespeedStyles } = useUtils();
|
||||||
|
|
||||||
|
const formattedData = processData(data);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ResponsiveContainer width="100%" minWidth={25} height={85}>
|
||||||
|
<AreaChart
|
||||||
|
width="100%"
|
||||||
|
height="100%"
|
||||||
|
data={formattedData}
|
||||||
|
margin={{ top: 10, bottom: -5 }}
|
||||||
|
style={{ cursor: "pointer" }}
|
||||||
|
>
|
||||||
|
<CartesianGrid
|
||||||
|
stroke={theme.palette.border.light}
|
||||||
|
strokeWidth={1}
|
||||||
|
strokeOpacity={1}
|
||||||
|
fill="transparent"
|
||||||
|
vertical={false}
|
||||||
|
/>
|
||||||
|
<Tooltip
|
||||||
|
cursor={{ stroke: theme.palette.border.light }}
|
||||||
|
content={<CustomToolTip />}
|
||||||
|
/>
|
||||||
|
<defs>
|
||||||
|
<linearGradient
|
||||||
|
id={`pagespeed-chart-${status}`}
|
||||||
|
x1="0"
|
||||||
|
y1="0"
|
||||||
|
x2="0"
|
||||||
|
y2="1"
|
||||||
|
>
|
||||||
|
<stop
|
||||||
|
offset="0%"
|
||||||
|
stopColor={pagespeedStyles[status].stroke}
|
||||||
|
stopOpacity={0.8}
|
||||||
|
/>
|
||||||
|
<stop
|
||||||
|
offset="100%"
|
||||||
|
stopColor={pagespeedStyles[status].light}
|
||||||
|
stopOpacity={0}
|
||||||
|
/>
|
||||||
|
</linearGradient>
|
||||||
|
</defs>
|
||||||
|
<Area
|
||||||
|
dataKey="score"
|
||||||
|
stroke={pagespeedStyles[status].stroke}
|
||||||
|
strokeWidth={1.5}
|
||||||
|
fill={`url(#pagespeed-chart-${status})`}
|
||||||
|
activeDot={{
|
||||||
|
stroke: pagespeedStyles[status].light,
|
||||||
|
fill: pagespeedStyles[status].stroke,
|
||||||
|
r: 4.5,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</AreaChart>
|
||||||
|
</ResponsiveContainer>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
PagespeedAreaChart.propTypes = {
|
||||||
|
data: PropTypes.arrayOf(
|
||||||
|
PropTypes.shape({
|
||||||
|
accessibility: PropTypes.number.isRequired,
|
||||||
|
bestPractices: PropTypes.number.isRequired,
|
||||||
|
performance: PropTypes.number.isRequired,
|
||||||
|
seo: PropTypes.number.isRequired,
|
||||||
|
})
|
||||||
|
).isRequired,
|
||||||
|
status: PropTypes.string.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders a card displaying monitor details and an area chart.
|
||||||
|
* @param {Object} props
|
||||||
|
* @param {Object} props.monitor - The monitor data to be displayed in the card.
|
||||||
|
* @returns {JSX.Element} - The rendered card.
|
||||||
|
*/
|
||||||
const Card = ({ monitor }) => {
|
const Card = ({ monitor }) => {
|
||||||
const { determineState, pagespeedStatusMsg } = useUtils();
|
const { determineState, pagespeedStatusMsg } = useUtils();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const monitorState = determineState(monitor);
|
const monitorState = determineState(monitor);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid
|
<Grid item lg={6} flexGrow={1}>
|
||||||
item
|
<Box
|
||||||
lg={6}
|
position="relative"
|
||||||
flexGrow={1}
|
|
||||||
sx={{
|
|
||||||
"&:hover > .MuiStack-root": {
|
|
||||||
backgroundColor: theme.palette.background.accent,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
gap={theme.spacing(6)}
|
|
||||||
p={theme.spacing(8)}
|
p={theme.spacing(8)}
|
||||||
onClick={() => navigate(`/pagespeed/${monitor._id}`)}
|
onClick={() => navigate(`/pagespeed/${monitor._id}`)}
|
||||||
border={1}
|
border={1}
|
||||||
@@ -34,41 +222,88 @@ const Card = ({ monitor }) => {
|
|||||||
borderRadius={theme.shape.borderRadius}
|
borderRadius={theme.shape.borderRadius}
|
||||||
backgroundColor={theme.palette.background.main}
|
backgroundColor={theme.palette.background.main}
|
||||||
sx={{
|
sx={{
|
||||||
|
display: "grid",
|
||||||
|
gridTemplateColumns: "34px 2fr 1fr",
|
||||||
|
columnGap: theme.spacing(5),
|
||||||
|
gridTemplateRows: "34px 1fr 3fr",
|
||||||
cursor: "pointer",
|
cursor: "pointer",
|
||||||
"& svg path": { stroke: theme.palette.other.icon, strokeWidth: 0.8 },
|
"&:hover": {
|
||||||
|
backgroundColor: theme.palette.background.accent,
|
||||||
|
},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<PageSpeedIcon
|
<IconBox>
|
||||||
style={{ width: theme.spacing(8), height: theme.spacing(8) }}
|
<PageSpeedIcon />
|
||||||
|
</IconBox>
|
||||||
|
<Typography
|
||||||
|
component="h2"
|
||||||
|
variant="h2"
|
||||||
|
fontWeight={500}
|
||||||
|
alignSelf="center"
|
||||||
|
>
|
||||||
|
{monitor.name}
|
||||||
|
</Typography>
|
||||||
|
<StatusLabel
|
||||||
|
status={monitorState}
|
||||||
|
text={pagespeedStatusMsg[monitorState] || "Pending..."}
|
||||||
|
customStyles={{
|
||||||
|
width: "max-content",
|
||||||
|
textTransform: "capitalize",
|
||||||
|
alignSelf: "flex-start",
|
||||||
|
justifySelf: "flex-end",
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
<Box flex={1}>
|
<Typography
|
||||||
<Stack direction="row" justifyContent="space-between">
|
variant="body2"
|
||||||
<Typography
|
mt={theme.spacing(-2)}
|
||||||
component="h2"
|
sx={{ gridColumnStart: 2 }}
|
||||||
mb={theme.spacing(2)}
|
>
|
||||||
fontSize={16}
|
{monitor.url}
|
||||||
color={theme.palette.primary.main}
|
</Typography>
|
||||||
>
|
<Box
|
||||||
{monitor.name}
|
mx={theme.spacing(-8)}
|
||||||
</Typography>
|
mt={theme.spacing(4)}
|
||||||
<StatusLabel
|
mb={theme.spacing(-8)}
|
||||||
status={monitorState}
|
sx={{ gridColumnStart: 1, gridColumnEnd: 4 }}
|
||||||
text={pagespeedStatusMsg[monitorState] || "Pending..."}
|
>
|
||||||
customStyles={{ textTransform: "capitalize" }}
|
<PagespeedAreaChart data={monitor.checks} status={monitorState} />
|
||||||
/>
|
</Box>
|
||||||
</Stack>
|
<Box
|
||||||
<Typography>{monitor.url.replace(/^https?:\/\//, "")}</Typography>
|
position="absolute"
|
||||||
<Typography mt={theme.spacing(12)}>
|
bottom={0}
|
||||||
<Typography component="span" variant="body2" fontWeight={600}>
|
py={theme.spacing(1)}
|
||||||
Last checked:{" "}
|
px={theme.spacing(4)}
|
||||||
</Typography>
|
borderTop={1}
|
||||||
{formatDate(getLastChecked(monitor.checks, false))}{" "}
|
borderRight={1}
|
||||||
<Typography component="span" variant="body2" fontStyle="italic">
|
borderColor={theme.palette.border.light}
|
||||||
({formatDurationRounded(getLastChecked(monitor.checks))} ago)
|
backgroundColor={theme.palette.background.accent}
|
||||||
</Typography>
|
sx={{
|
||||||
|
pointerEvents: "none",
|
||||||
|
userSelect: "none",
|
||||||
|
borderTopRightRadius: 8,
|
||||||
|
borderBottomLeftRadius: 4,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography fontSize={11} color={theme.palette.text.accent}>
|
||||||
|
Checking every{" "}
|
||||||
|
{(() => {
|
||||||
|
const { time, format } = formatDurationSplit(monitor?.interval);
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Typography
|
||||||
|
component="span"
|
||||||
|
fontSize={12}
|
||||||
|
color={theme.palette.text.primary}
|
||||||
|
>
|
||||||
|
{time}{" "}
|
||||||
|
</Typography>
|
||||||
|
{format}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
})()}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
</Stack>
|
</Box>
|
||||||
</Grid>
|
</Grid>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
.page-speed h2.MuiTypography-root {
|
|
||||||
line-height: 1.1;
|
|
||||||
}
|
|
||||||
.page-speed .label {
|
.page-speed .label {
|
||||||
padding: 7px;
|
padding: 7px;
|
||||||
height: 22px;
|
height: 24px;
|
||||||
font-size: var(--env-var-font-size-small);
|
font-size: var(--env-var-font-size-small);
|
||||||
}
|
}
|
||||||
.page-speed:not(:has([class*="fallback__"])) button {
|
.page-speed:not(:has([class*="fallback__"])) button {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Box, Button, Grid, Stack } from "@mui/material";
|
import { Box, Button, Grid, Stack } from "@mui/material";
|
||||||
import { useEffect } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import { getPageSpeedByTeamId } from "../../Features/PageSpeedMonitor/pageSpeedMonitorSlice";
|
import { getPageSpeedByTeamId } from "../../Features/PageSpeedMonitor/pageSpeedMonitorSlice";
|
||||||
@@ -11,24 +11,51 @@ import Breadcrumbs from "../../Components/Breadcrumbs";
|
|||||||
import Greeting from "../../Utils/greeting";
|
import Greeting from "../../Utils/greeting";
|
||||||
import SkeletonLayout from "./skeleton";
|
import SkeletonLayout from "./skeleton";
|
||||||
import Card from "./card";
|
import Card from "./card";
|
||||||
|
import { networkService } from "../../main";
|
||||||
|
|
||||||
const PageSpeed = ({ isAdmin }) => {
|
const PageSpeed = ({ isAdmin }) => {
|
||||||
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 { user, authToken } = useSelector((state) => state.auth);
|
||||||
const { monitorsSummary, isLoading } = useSelector(
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
(state) => state.pageSpeedMonitors
|
const [monitors, setMonitors] = useState([]);
|
||||||
);
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(getPageSpeedByTeamId(authToken));
|
dispatch(getPageSpeedByTeamId(authToken));
|
||||||
}, [authToken, dispatch]);
|
}, [authToken, dispatch]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchMonitors = async () => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true);
|
||||||
|
const res = await networkService.getMonitorsByTeamId(
|
||||||
|
authToken,
|
||||||
|
user.teamId,
|
||||||
|
10,
|
||||||
|
["pagespeed"],
|
||||||
|
null,
|
||||||
|
"desc",
|
||||||
|
true,
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
if (res?.data?.data?.monitors) {
|
||||||
|
setMonitors(res.data.data.monitors);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchMonitors();
|
||||||
|
}, []);
|
||||||
|
|
||||||
// will show skeletons only on initial load
|
// 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
|
// since monitor state is being added to redux persist, there's no reason to display skeletons on every render
|
||||||
let isActuallyLoading = isLoading && monitorsSummary?.monitors?.length === 0;
|
let isActuallyLoading = isLoading && monitors?.length === 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
className="page-speed"
|
className="page-speed"
|
||||||
@@ -46,14 +73,8 @@ const PageSpeed = ({ isAdmin }) => {
|
|||||||
>
|
>
|
||||||
{isActuallyLoading ? (
|
{isActuallyLoading ? (
|
||||||
<SkeletonLayout />
|
<SkeletonLayout />
|
||||||
) : monitorsSummary?.monitors?.length !== 0 ? (
|
) : monitors?.length !== 0 ? (
|
||||||
<Box
|
<Box>
|
||||||
sx={{
|
|
||||||
"& p": {
|
|
||||||
color: theme.palette.text.secondary,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Box mb={theme.spacing(12)}>
|
<Box mb={theme.spacing(12)}>
|
||||||
<Breadcrumbs list={[{ name: `pagespeed`, path: "/pagespeed" }]} />
|
<Breadcrumbs list={[{ name: `pagespeed`, path: "/pagespeed" }]} />
|
||||||
<Stack
|
<Stack
|
||||||
@@ -67,13 +88,14 @@ const PageSpeed = ({ isAdmin }) => {
|
|||||||
variant="contained"
|
variant="contained"
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() => navigate("/pagespeed/create")}
|
onClick={() => navigate("/pagespeed/create")}
|
||||||
|
sx={{ whiteSpace: "nowrap" }}
|
||||||
>
|
>
|
||||||
Create new
|
Create new
|
||||||
</Button>
|
</Button>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Box>
|
</Box>
|
||||||
<Grid container spacing={theme.spacing(12)}>
|
<Grid container spacing={theme.spacing(12)}>
|
||||||
{monitorsSummary?.monitors?.map((monitor) => (
|
{monitors?.map((monitor) => (
|
||||||
<Card monitor={monitor} key={monitor._id} />
|
<Card monitor={monitor} key={monitor._id} />
|
||||||
))}
|
))}
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
Reference in new issue
Block a user