[PageSpeed]: Removed Create and Configure folders, Polished Setup folder to ensure consistency with manual testing
This commit is contained in:
1 parent
f00d7275e5
commit
b45df68ece
7 files changed
+367
-1104
No files matched your search
@@ -1,9 +0,0 @@
|
|||||||
.configure-pagespeed button {
|
|
||||||
height: var(--env-var-height-2);
|
|
||||||
}
|
|
||||||
|
|
||||||
.configure-pagespeed .field,
|
|
||||||
.configure-pagespeed .section-disabled,
|
|
||||||
.configure-pagespeed .select-wrapper {
|
|
||||||
flex: 1;
|
|
||||||
}
|
|
||||||
@@ -1,351 +0,0 @@
|
|||||||
// Components
|
|
||||||
import { Box, Stack, Tooltip, Typography, Button } from "@mui/material";
|
|
||||||
import ConfigBox from "../../../Components/ConfigBox";
|
|
||||||
import Select from "../../../Components/Inputs/Select";
|
|
||||||
import TextInput from "../../../Components/Inputs/TextInput";
|
|
||||||
import PauseCircleOutlineIcon from "@mui/icons-material/PauseCircleOutline";
|
|
||||||
import Breadcrumbs from "../../../Components/Breadcrumbs";
|
|
||||||
import PulseDot from "../../../Components/Animated/PulseDot";
|
|
||||||
import PlayCircleOutlineRoundedIcon from "@mui/icons-material/PlayCircleOutlineRounded";
|
|
||||||
import SkeletonLayout from "./skeleton";
|
|
||||||
import NotificationsConfig from "../../../Components/NotificationConfig";
|
|
||||||
import Dialog from "../../../Components/Dialog";
|
|
||||||
|
|
||||||
// Utils
|
|
||||||
import { useState } from "react";
|
|
||||||
import { useTheme } from "@emotion/react";
|
|
||||||
import { useParams } from "react-router";
|
|
||||||
import { monitorValidation } from "../../../Validation/validation";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { useMonitorUtils } from "../../../Hooks/useMonitorUtils";
|
|
||||||
import { useGetNotificationsByTeamId } from "../../../Hooks/useNotifications";
|
|
||||||
import {
|
|
||||||
useFetchMonitorById,
|
|
||||||
useDeleteMonitor,
|
|
||||||
useUpdateMonitor,
|
|
||||||
usePauseMonitor,
|
|
||||||
} from "../../../Hooks/monitorHooks";
|
|
||||||
const PageSpeedConfigure = () => {
|
|
||||||
// Redux state
|
|
||||||
|
|
||||||
// Local state
|
|
||||||
const [monitor, setMonitor] = useState({});
|
|
||||||
const [errors, setErrors] = useState({});
|
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
|
||||||
const [updateTrigger, setUpdateTrigger] = useState(false);
|
|
||||||
|
|
||||||
// Utils
|
|
||||||
const theme = useTheme();
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const MS_PER_MINUTE = 60000;
|
|
||||||
const { monitorId } = useParams();
|
|
||||||
const { statusColor, pagespeedStatusMsg, determineState } = useMonitorUtils();
|
|
||||||
|
|
||||||
const [notifications, notificationsAreLoading, notificationsError] =
|
|
||||||
useGetNotificationsByTeamId();
|
|
||||||
|
|
||||||
const [isLoading] = useFetchMonitorById({ monitorId, setMonitor, updateTrigger });
|
|
||||||
const [deleteMonitor, isDeleting] = useDeleteMonitor();
|
|
||||||
const [updateMonitor, isUpdating] = useUpdateMonitor();
|
|
||||||
const [pauseMonitor, isPausing] = usePauseMonitor();
|
|
||||||
|
|
||||||
const frequencies = [
|
|
||||||
{ _id: 3, name: "3 minutes" },
|
|
||||||
{ _id: 5, name: "5 minutes" },
|
|
||||||
{ _id: 10, name: "10 minutes" },
|
|
||||||
{ _id: 20, name: "20 minutes" },
|
|
||||||
{ _id: 60, name: "1 hour" },
|
|
||||||
{ _id: 1440, name: "1 day" },
|
|
||||||
{ _id: 10080, name: "1 week" },
|
|
||||||
];
|
|
||||||
|
|
||||||
// Handlers
|
|
||||||
const triggerUpdate = () => {
|
|
||||||
setUpdateTrigger(!updateTrigger);
|
|
||||||
};
|
|
||||||
|
|
||||||
const onChange = (event) => {
|
|
||||||
let { value, name } = event.target;
|
|
||||||
|
|
||||||
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;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const handlePause = async () => {
|
|
||||||
await pauseMonitor({ monitorId, triggerUpdate });
|
|
||||||
};
|
|
||||||
|
|
||||||
const onSubmit = async (event) => {
|
|
||||||
event.preventDefault();
|
|
||||||
await updateMonitor({ monitor, redirect: "/pagespeed" });
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleRemove = async (event) => {
|
|
||||||
event.preventDefault();
|
|
||||||
await deleteMonitor({ monitor, redirect: "/pagespeed" });
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Stack
|
|
||||||
className="configure-pagespeed"
|
|
||||||
gap={theme.spacing(10)}
|
|
||||||
>
|
|
||||||
{Object.keys(monitor).length === 0 ? (
|
|
||||||
<SkeletonLayout />
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<Breadcrumbs
|
|
||||||
list={[
|
|
||||||
{ name: "pagespeed", path: "/pagespeed" },
|
|
||||||
{ name: "details", path: `/pagespeed/${monitorId}` },
|
|
||||||
{ name: "configure", path: `/pagespeed/configure/${monitorId}` },
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
<Stack
|
|
||||||
component="form"
|
|
||||||
noValidate
|
|
||||||
spellCheck="false"
|
|
||||||
onSubmit={onSubmit}
|
|
||||||
flex={1}
|
|
||||||
gap={theme.spacing(10)}
|
|
||||||
>
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
gap={theme.spacing(2)}
|
|
||||||
>
|
|
||||||
<Box>
|
|
||||||
<Typography
|
|
||||||
component="h1"
|
|
||||||
variant="monitorName"
|
|
||||||
>
|
|
||||||
{monitor.name}
|
|
||||||
</Typography>
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
alignItems="center"
|
|
||||||
height="fit-content"
|
|
||||||
gap={theme.spacing(2)}
|
|
||||||
>
|
|
||||||
<Tooltip
|
|
||||||
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="monitorUrl"
|
|
||||||
>
|
|
||||||
{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.primary.contrastTextTertiary,
|
|
||||||
opacity: 0.8,
|
|
||||||
left: -10,
|
|
||||||
top: "50%",
|
|
||||||
transform: "translateY(-50%)",
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t("editing")}
|
|
||||||
</Typography>
|
|
||||||
</Stack>
|
|
||||||
</Box>
|
|
||||||
<Box
|
|
||||||
alignSelf="flex-end"
|
|
||||||
ml="auto"
|
|
||||||
>
|
|
||||||
<Button
|
|
||||||
onClick={handlePause}
|
|
||||||
loading={isLoading}
|
|
||||||
variant="contained"
|
|
||||||
color="secondary"
|
|
||||||
sx={{
|
|
||||||
pl: theme.spacing(4),
|
|
||||||
pr: theme.spacing(6),
|
|
||||||
"& svg": {
|
|
||||||
mr: theme.spacing(2),
|
|
||||||
"& path": {
|
|
||||||
stroke: theme.palette.primary.contrastTextTertiary,
|
|
||||||
strokeWidth: 0.1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{monitor?.isActive ? (
|
|
||||||
<>
|
|
||||||
<PauseCircleOutlineIcon />
|
|
||||||
{t("pause")}
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<PlayCircleOutlineRoundedIcon />
|
|
||||||
{t("resume")}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
loading={isLoading}
|
|
||||||
variant="contained"
|
|
||||||
color="error"
|
|
||||||
onClick={() => setIsOpen(true)}
|
|
||||||
sx={{
|
|
||||||
ml: theme.spacing(6),
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t("remove")}
|
|
||||||
</Button>
|
|
||||||
</Box>
|
|
||||||
</Stack>
|
|
||||||
<ConfigBox>
|
|
||||||
<Box>
|
|
||||||
<Typography
|
|
||||||
component="h2"
|
|
||||||
variant="h2"
|
|
||||||
>
|
|
||||||
{t("settingsGeneralSettings")}
|
|
||||||
</Typography>
|
|
||||||
<Typography component="p">
|
|
||||||
{t("pageSpeedConfigureSettingsDescription")}
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
<Stack
|
|
||||||
gap={theme.spacing(20)}
|
|
||||||
sx={{
|
|
||||||
".MuiInputBase-root:has(> .Mui-disabled)": {
|
|
||||||
backgroundColor: theme.palette.tertiary.main,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<TextInput
|
|
||||||
name="url"
|
|
||||||
type="url"
|
|
||||||
label={t("url")}
|
|
||||||
placeholder="random.website.com"
|
|
||||||
value={monitor?.url || ""}
|
|
||||||
onChange={onChange}
|
|
||||||
error={errors.url ? true : false}
|
|
||||||
helperText={errors.url}
|
|
||||||
disabled={true}
|
|
||||||
/>
|
|
||||||
<TextInput
|
|
||||||
name="name"
|
|
||||||
type="text"
|
|
||||||
label={t("monitorDisplayName")}
|
|
||||||
placeholder="Example monitor"
|
|
||||||
isOptional={true}
|
|
||||||
value={monitor?.name || ""}
|
|
||||||
onChange={onChange}
|
|
||||||
error={errors.name ? true : false}
|
|
||||||
helperText={errors.name}
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
</ConfigBox>
|
|
||||||
<ConfigBox>
|
|
||||||
<Box>
|
|
||||||
<Typography component="h2">{t("notificationConfig.title")}</Typography>
|
|
||||||
<Typography component="p">
|
|
||||||
{t("notificationConfig.description")}
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
<NotificationsConfig
|
|
||||||
notifications={notifications}
|
|
||||||
setMonitor={setMonitor}
|
|
||||||
setNotifications={monitor.notifications}
|
|
||||||
/>
|
|
||||||
</ConfigBox>
|
|
||||||
<ConfigBox>
|
|
||||||
<Box>
|
|
||||||
<Typography
|
|
||||||
component="h2"
|
|
||||||
variant="h2"
|
|
||||||
>
|
|
||||||
{t("distributedUptimeCreateAdvancedSettings")}
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
<Stack gap={theme.spacing(20)}>
|
|
||||||
<Select
|
|
||||||
name="interval"
|
|
||||||
label={t("checkFrequency")}
|
|
||||||
items={frequencies}
|
|
||||||
value={monitor?.interval / MS_PER_MINUTE || 3}
|
|
||||||
onChange={onChange}
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
</ConfigBox>
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
justifyContent="flex-end"
|
|
||||||
mt="auto"
|
|
||||||
>
|
|
||||||
<Button
|
|
||||||
loading={isLoading || isDeleting || isUpdating || isPausing}
|
|
||||||
type="submit"
|
|
||||||
variant="contained"
|
|
||||||
color="accent"
|
|
||||||
sx={{ px: theme.spacing(12) }}
|
|
||||||
>
|
|
||||||
{t("settingsSave")}
|
|
||||||
</Button>
|
|
||||||
</Stack>
|
|
||||||
</Stack>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
<Dialog
|
|
||||||
open={isOpen}
|
|
||||||
theme={theme}
|
|
||||||
title={t("deleteDialogTitle")}
|
|
||||||
description={t("deleteDialogDescription")}
|
|
||||||
onCancel={() => setIsOpen(false)}
|
|
||||||
confirmationButtonLabel={t("delete")}
|
|
||||||
onConfirm={handleRemove}
|
|
||||||
isLoading={isLoading || isDeleting || isUpdating || isPausing}
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default PageSpeedConfigure;
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
import { Box, Skeleton, Stack } from "@mui/material";
|
|
||||||
import { useTheme } from "@emotion/react";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Renders a skeleton layout.
|
|
||||||
*
|
|
||||||
* @returns {JSX.Element}
|
|
||||||
*/
|
|
||||||
const SkeletonLayout = () => {
|
|
||||||
const theme = useTheme();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Skeleton
|
|
||||||
variant="rounded"
|
|
||||||
width="15%"
|
|
||||||
height={34}
|
|
||||||
/>
|
|
||||||
<Stack
|
|
||||||
gap={theme.spacing(20)}
|
|
||||||
mt={theme.spacing(6)}
|
|
||||||
maxWidth="1000px"
|
|
||||||
>
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
gap={theme.spacing(4)}
|
|
||||||
mt={theme.spacing(4)}
|
|
||||||
>
|
|
||||||
<Skeleton
|
|
||||||
variant="circular"
|
|
||||||
style={{ minWidth: 24, minHeight: 24 }}
|
|
||||||
/>
|
|
||||||
<Box width="80%">
|
|
||||||
<Skeleton
|
|
||||||
variant="rounded"
|
|
||||||
width="50%"
|
|
||||||
height={24}
|
|
||||||
sx={{ mb: theme.spacing(4) }}
|
|
||||||
/>
|
|
||||||
<Skeleton
|
|
||||||
variant="rounded"
|
|
||||||
width="50%"
|
|
||||||
height={18}
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
gap={theme.spacing(6)}
|
|
||||||
sx={{
|
|
||||||
ml: "auto",
|
|
||||||
alignSelf: "flex-end",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Skeleton
|
|
||||||
variant="rounded"
|
|
||||||
width={100}
|
|
||||||
height={34}
|
|
||||||
/>
|
|
||||||
<Skeleton
|
|
||||||
variant="rounded"
|
|
||||||
width={100}
|
|
||||||
height={34}
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
</Stack>
|
|
||||||
<Skeleton
|
|
||||||
variant="rounded"
|
|
||||||
width="100%"
|
|
||||||
height={500}
|
|
||||||
/>
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
justifyContent="flex-end"
|
|
||||||
>
|
|
||||||
<Skeleton
|
|
||||||
variant="rounded"
|
|
||||||
width="15%"
|
|
||||||
height={34}
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
</Stack>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default SkeletonLayout;
|
|
||||||
Whitespace-only changes.
@@ -1,312 +0,0 @@
|
|||||||
//Components
|
|
||||||
import Box from "@mui/material/Box";
|
|
||||||
import Stack from "@mui/material/Stack";
|
|
||||||
import Typography from "@mui/material/Typography";
|
|
||||||
import Button from "@mui/material/Button";
|
|
||||||
import ButtonGroup from "@mui/material/ButtonGroup";
|
|
||||||
import Breadcrumbs from "../../../Components/Breadcrumbs";
|
|
||||||
import TextInput from "../../../Components/Inputs/TextInput";
|
|
||||||
import { HttpAdornment } from "../../../Components/Inputs/TextInput/Adornments";
|
|
||||||
import ConfigBox from "../../../Components/ConfigBox";
|
|
||||||
import Radio from "../../../Components/Inputs/Radio";
|
|
||||||
import Select from "../../../Components/Inputs/Select";
|
|
||||||
import NotificationsConfig from "../../../Components/NotificationConfig";
|
|
||||||
|
|
||||||
// Utils
|
|
||||||
import { useState } from "react";
|
|
||||||
import { useSelector } from "react-redux";
|
|
||||||
import { monitorValidation } from "../../../Validation/validation";
|
|
||||||
import { parseDomainName } from "../../../Utils/monitorUtils";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { useGetNotificationsByTeamId } from "../../../Hooks/useNotifications";
|
|
||||||
import { useTheme } from "@emotion/react";
|
|
||||||
import { createToast } from "../../../Utils/toastUtils";
|
|
||||||
import { useCreateMonitor } from "../../../Hooks/monitorHooks";
|
|
||||||
|
|
||||||
const MS_PER_MINUTE = 60000;
|
|
||||||
|
|
||||||
const CRUMBS = [
|
|
||||||
{ name: "pagespeed", path: "/pagespeed" },
|
|
||||||
{ name: "create", path: `/pagespeed/create` },
|
|
||||||
];
|
|
||||||
|
|
||||||
const SELECT_VALUES = [
|
|
||||||
{ _id: 3, name: "3 minutes" },
|
|
||||||
{ _id: 5, name: "5 minutes" },
|
|
||||||
{ _id: 10, name: "10 minutes" },
|
|
||||||
{ _id: 20, name: "20 minutes" },
|
|
||||||
{ _id: 60, name: "1 hour" },
|
|
||||||
{ _id: 1440, name: "1 day" },
|
|
||||||
{ _id: 10080, name: "1 week" },
|
|
||||||
];
|
|
||||||
|
|
||||||
const CreatePageSpeed = () => {
|
|
||||||
// State
|
|
||||||
const [monitor, setMonitor] = useState({
|
|
||||||
url: "",
|
|
||||||
name: "",
|
|
||||||
type: "pagespeed",
|
|
||||||
notifications: [],
|
|
||||||
interval: 3,
|
|
||||||
});
|
|
||||||
|
|
||||||
const [https, setHttps] = useState(true);
|
|
||||||
const [errors, setErrors] = useState({});
|
|
||||||
const { user } = useSelector((state) => state.auth);
|
|
||||||
const [notifications, notificationsAreLoading, error] = useGetNotificationsByTeamId();
|
|
||||||
|
|
||||||
// Setup
|
|
||||||
const theme = useTheme();
|
|
||||||
const [createMonitor, isCreating] = useCreateMonitor();
|
|
||||||
|
|
||||||
// Handlers
|
|
||||||
const onSubmit = async (event) => {
|
|
||||||
event.preventDefault();
|
|
||||||
let form = {
|
|
||||||
url: `http${https ? "s" : ""}://` + monitor.url,
|
|
||||||
name: monitor.name === "" ? monitor.url : monitor.name,
|
|
||||||
type: monitor.type,
|
|
||||||
interval: monitor.interval * MS_PER_MINUTE,
|
|
||||||
};
|
|
||||||
|
|
||||||
const { error } = monitorValidation.validate(form, {
|
|
||||||
abortEarly: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (error) {
|
|
||||||
const newErrors = {};
|
|
||||||
error.details.forEach((err) => {
|
|
||||||
newErrors[err.path[0]] = err.message;
|
|
||||||
});
|
|
||||||
setErrors(newErrors);
|
|
||||||
createToast({ body: "Please check the form for errors." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
form = {
|
|
||||||
...form,
|
|
||||||
description: form.name,
|
|
||||||
notifications: monitor.notifications,
|
|
||||||
};
|
|
||||||
|
|
||||||
await createMonitor({ monitor: form, redirect: "/pagespeed" });
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleChange = (event) => {
|
|
||||||
const { value, name } = event.target;
|
|
||||||
setMonitor({
|
|
||||||
...monitor,
|
|
||||||
[name]: value,
|
|
||||||
});
|
|
||||||
|
|
||||||
const { error } = monitorValidation.validate(
|
|
||||||
{ [name]: value },
|
|
||||||
{ abortEarly: false }
|
|
||||||
);
|
|
||||||
|
|
||||||
setErrors((prev) => ({
|
|
||||||
...prev,
|
|
||||||
...(error ? { [name]: error.details[0].message } : { [name]: undefined }),
|
|
||||||
}));
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleBlur = (event) => {
|
|
||||||
const { name } = event.target;
|
|
||||||
if (name === "url") {
|
|
||||||
const { value } = event.target;
|
|
||||||
if (monitor.name !== "") {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setMonitor((prev) => ({
|
|
||||||
...prev,
|
|
||||||
name: parseDomainName(value),
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const { t } = useTranslation();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Box
|
|
||||||
className="create-monitor"
|
|
||||||
sx={{
|
|
||||||
"& h1": {
|
|
||||||
color: theme.palette.primary.contrastText,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Breadcrumbs list={CRUMBS} />
|
|
||||||
<Stack
|
|
||||||
component="form"
|
|
||||||
className="create-monitor-form"
|
|
||||||
onSubmit={onSubmit}
|
|
||||||
noValidate
|
|
||||||
spellCheck="false"
|
|
||||||
gap={theme.spacing(12)}
|
|
||||||
mt={theme.spacing(6)}
|
|
||||||
>
|
|
||||||
<Typography
|
|
||||||
component="h1"
|
|
||||||
variant="h1"
|
|
||||||
>
|
|
||||||
<Typography
|
|
||||||
component="span"
|
|
||||||
fontSize="inherit"
|
|
||||||
>
|
|
||||||
{t("createYour")}{" "}
|
|
||||||
</Typography>
|
|
||||||
<Typography
|
|
||||||
component="span"
|
|
||||||
fontSize="inherit"
|
|
||||||
fontWeight="inherit"
|
|
||||||
color={theme.palette.primary.contrastTextSecondary}
|
|
||||||
>
|
|
||||||
{t("pageSpeedMonitor")}
|
|
||||||
</Typography>
|
|
||||||
</Typography>
|
|
||||||
<ConfigBox>
|
|
||||||
<Box>
|
|
||||||
<Typography
|
|
||||||
component="h2"
|
|
||||||
variant="h2"
|
|
||||||
>
|
|
||||||
{t("settingsGeneralSettings")}
|
|
||||||
</Typography>
|
|
||||||
<Typography component="p">{t("distributedUptimeCreateSelectURL")}</Typography>
|
|
||||||
</Box>
|
|
||||||
<Stack gap={theme.spacing(15)}>
|
|
||||||
<TextInput
|
|
||||||
type={"url"}
|
|
||||||
name="url"
|
|
||||||
id="monitor-url"
|
|
||||||
label="URL to monitor"
|
|
||||||
startAdornment={<HttpAdornment https={https} />}
|
|
||||||
placeholder="google.com"
|
|
||||||
value={monitor.url}
|
|
||||||
onChange={handleChange}
|
|
||||||
onBlur={handleBlur}
|
|
||||||
error={errors["url"] ? true : false}
|
|
||||||
helperText={errors["url"]}
|
|
||||||
/>
|
|
||||||
<TextInput
|
|
||||||
type="text"
|
|
||||||
id="monitor-name"
|
|
||||||
name="name"
|
|
||||||
label="Display name"
|
|
||||||
isOptional={true}
|
|
||||||
placeholder="Google"
|
|
||||||
value={monitor.name}
|
|
||||||
onChange={handleChange}
|
|
||||||
error={errors["name"] ? true : false}
|
|
||||||
helperText={errors["name"]}
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
</ConfigBox>
|
|
||||||
<ConfigBox>
|
|
||||||
<Box>
|
|
||||||
<Typography
|
|
||||||
component="h2"
|
|
||||||
variant="h2"
|
|
||||||
>
|
|
||||||
{t("distributedUptimeCreateChecks")}
|
|
||||||
</Typography>
|
|
||||||
<Typography component="p">
|
|
||||||
{t("distributedUptimeCreateChecksDescription")}
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
<Stack gap={theme.spacing(12)}>
|
|
||||||
<Stack gap={theme.spacing(6)}>
|
|
||||||
<Radio
|
|
||||||
id="monitor-checks-http"
|
|
||||||
title="PageSpeed"
|
|
||||||
desc="Use the Lighthouse PageSpeed API to monitor your website"
|
|
||||||
size="small"
|
|
||||||
value="http"
|
|
||||||
checked={monitor.type === "pagespeed"}
|
|
||||||
/>
|
|
||||||
<ButtonGroup sx={{ ml: "32px" }}>
|
|
||||||
<Button
|
|
||||||
variant="group"
|
|
||||||
filled={https.toString()}
|
|
||||||
onClick={() => setHttps(true)}
|
|
||||||
>
|
|
||||||
{t("https")}
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
variant="group" // Why does this work?
|
|
||||||
filled={(!https).toString()} // There's nothing in the docs about this either
|
|
||||||
onClick={() => setHttps(false)}
|
|
||||||
>
|
|
||||||
{t("http")}
|
|
||||||
</Button>
|
|
||||||
</ButtonGroup>
|
|
||||||
</Stack>
|
|
||||||
{errors["type"] ? (
|
|
||||||
<Box className="error-container">
|
|
||||||
<Typography
|
|
||||||
component="p"
|
|
||||||
className="input-error"
|
|
||||||
color={theme.palette.error.contrastText}
|
|
||||||
>
|
|
||||||
{errors["type"]}
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
) : (
|
|
||||||
""
|
|
||||||
)}
|
|
||||||
</Stack>
|
|
||||||
</ConfigBox>
|
|
||||||
<ConfigBox>
|
|
||||||
<Box>
|
|
||||||
<Typography
|
|
||||||
component="h2"
|
|
||||||
variant="h2"
|
|
||||||
>
|
|
||||||
{t("notificationConfig.title")}
|
|
||||||
</Typography>
|
|
||||||
<Typography component="p">{t("notificationConfig.description")}</Typography>
|
|
||||||
</Box>
|
|
||||||
<NotificationsConfig
|
|
||||||
notifications={notifications}
|
|
||||||
setMonitor={setMonitor}
|
|
||||||
/>
|
|
||||||
</ConfigBox>
|
|
||||||
<ConfigBox>
|
|
||||||
<Box>
|
|
||||||
<Typography
|
|
||||||
component="h2"
|
|
||||||
variant="h2"
|
|
||||||
>
|
|
||||||
{t("distributedUptimeCreateAdvancedSettings")}
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
<Stack gap={theme.spacing(12)}>
|
|
||||||
<Select
|
|
||||||
id="monitor-interval"
|
|
||||||
name="interval"
|
|
||||||
label="Check frequency"
|
|
||||||
value={monitor.interval || 3}
|
|
||||||
onChange={handleChange}
|
|
||||||
items={SELECT_VALUES}
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
</ConfigBox>
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
justifyContent="flex-end"
|
|
||||||
>
|
|
||||||
<Button
|
|
||||||
type="submit"
|
|
||||||
variant="contained"
|
|
||||||
color="accent"
|
|
||||||
disabled={!Object.values(errors).every((value) => value === undefined)}
|
|
||||||
loading={isCreating}
|
|
||||||
>
|
|
||||||
{t("createMonitor")}
|
|
||||||
</Button>
|
|
||||||
</Stack>
|
|
||||||
</Stack>
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
export default CreatePageSpeed;
|
|
||||||
@@ -34,8 +34,9 @@ import {
|
|||||||
usePauseMonitor,
|
usePauseMonitor,
|
||||||
} from "../../../Hooks/monitorHooks";
|
} from "../../../Hooks/monitorHooks";
|
||||||
|
|
||||||
|
// Constants
|
||||||
const MS_PER_MINUTE = 60000;
|
const MS_PER_MINUTE = 60000;
|
||||||
const SELECT_VALUES = [
|
const FREQUENCIES = [
|
||||||
{ _id: 3, name: "3 minutes" },
|
{ _id: 3, name: "3 minutes" },
|
||||||
{ _id: 5, name: "5 minutes" },
|
{ _id: 5, name: "5 minutes" },
|
||||||
{ _id: 10, name: "10 minutes" },
|
{ _id: 10, name: "10 minutes" },
|
||||||
@@ -45,107 +46,75 @@ const SELECT_VALUES = [
|
|||||||
{ _id: 10080, name: "1 week" },
|
{ _id: 10080, name: "1 week" },
|
||||||
];
|
];
|
||||||
|
|
||||||
const PageSpeedSetup = ({ monitor }) => {
|
const PageSpeedSetup = ({ configure }) => {
|
||||||
const isConfigure = monitor;
|
const isConfigure = configure;
|
||||||
const { t } = useTranslation();
|
|
||||||
const theme = useTheme();
|
|
||||||
const { monitorId } = useParams();
|
const { monitorId } = useParams();
|
||||||
const { statusColor, pagespeedStatusMsg, determineState } = useMonitorUtils();
|
const CRUMBS = [
|
||||||
const [notifications, notificationsAreLoading] = useGetNotificationsByTeamId();
|
{ name: "pagespeed", path: "/pagespeed" },
|
||||||
const [https, setHttps] = useState(true);
|
...(isConfigure
|
||||||
const [errors, setErrors] = useState({});
|
? [
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
{ name: "details", path: `/pagespeed/${monitorId}` },
|
||||||
const [updateTrigger, setUpdateTrigger] = useState(false);
|
{ name: "configure", path: `/pagespeed/setup/${monitorId}` },
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
]
|
||||||
const [isDeleting, setIsDeleting] = useState(false);
|
: [{ name: "create", path: `/pagespeed/create` }]),
|
||||||
const [isUpdating, setIsUpdating] = useState(false);
|
];
|
||||||
const [isPausing, setIsPausing] = useState(false);
|
|
||||||
|
|
||||||
// Monitor state
|
// States
|
||||||
const [monitorData, setMonitorData] = useState({
|
const [monitor, setMonitor] = useState(isConfigure ? {} : {
|
||||||
url: "",
|
url: "",
|
||||||
name: "",
|
name: "",
|
||||||
type: "pagespeed",
|
type: "pagespeed",
|
||||||
notifications: [],
|
notifications: [],
|
||||||
interval: 3,
|
interval: 180000,
|
||||||
});
|
});
|
||||||
|
const [https, setHttps] = useState(true);
|
||||||
|
const [errors, setErrors] = useState({});
|
||||||
|
|
||||||
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
|
const [updateTrigger, setUpdateTrigger] = useState(false);
|
||||||
|
const [isDeleting, setIsDeleting] = useState(false);
|
||||||
|
const [isUpdating, setIsUpdating] = useState(false);
|
||||||
|
const [isPausing, setIsPausing] = useState(false);
|
||||||
|
|
||||||
|
// Setup
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
|
const { user } = useSelector((state) => state.auth);
|
||||||
|
const {
|
||||||
|
statusColor,
|
||||||
|
pagespeedStatusMsg,
|
||||||
|
determineState
|
||||||
|
} = useMonitorUtils();
|
||||||
|
const [
|
||||||
|
notifications,
|
||||||
|
notificationsAreLoading,
|
||||||
|
notificationsError
|
||||||
|
] = useGetNotificationsByTeamId();
|
||||||
|
|
||||||
// Hooks for API actions
|
// Hooks for API actions
|
||||||
const [createMonitor, isCreating] = useCreateMonitor();
|
const [createMonitor, isCreating] = useCreateMonitor();
|
||||||
const [fetchMonitor] = monitor
|
const [isLoading] = isConfigure
|
||||||
? useFetchMonitorById({ monitorId, setMonitor: setMonitorData, updateTrigger })
|
? useFetchMonitorById({ monitorId, setMonitor, updateTrigger })
|
||||||
: [null];
|
: [false];
|
||||||
const [deleteMonitor] = useDeleteMonitor();
|
const [deleteMonitor] = useDeleteMonitor();
|
||||||
const [updateMonitor] = useUpdateMonitor();
|
const [updateMonitor] = useUpdateMonitor();
|
||||||
const [pauseMonitor] = usePauseMonitor();
|
const [pauseMonitor] = usePauseMonitor();
|
||||||
|
|
||||||
const frequencies = [
|
|
||||||
{ _id: 3, name: "3 minutes" },
|
|
||||||
{ _id: 5, name: "5 minutes" },
|
|
||||||
{ _id: 10, name: "10 minutes" },
|
|
||||||
{ _id: 20, name: "20 minutes" },
|
|
||||||
{ _id: 60, name: "1 hour" },
|
|
||||||
{ _id: 1440, name: "1 day" },
|
|
||||||
{ _id: 10080, name: "1 week" },
|
|
||||||
];
|
|
||||||
|
|
||||||
// Fetch monitor if in configure mode
|
|
||||||
useEffect(() => {
|
|
||||||
if (monitor && monitorId && typeof fetchMonitor === 'function') {
|
|
||||||
setIsLoading(true);
|
|
||||||
fetchMonitor().finally(() => setIsLoading(false));
|
|
||||||
}
|
|
||||||
}, [monitor, monitorId, updateTrigger, fetchMonitor]);
|
|
||||||
|
|
||||||
// Handlers
|
// Handlers
|
||||||
|
|
||||||
const handleChange = (event) => {
|
|
||||||
let { value, name } = event.target;
|
|
||||||
if (name === "interval") {
|
|
||||||
value = value * MS_PER_MINUTE;
|
|
||||||
}
|
|
||||||
setMonitorData((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;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleBlur = (event) => {
|
|
||||||
const { name, value } = event.target;
|
|
||||||
if (name === "url" && monitorData.name === "") {
|
|
||||||
setMonitorData((prev) => ({ ...prev, name: parseDomainName(value) }));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onSubmit = async (event) => {
|
const onSubmit = async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (isConfigure) {
|
if (isConfigure) {
|
||||||
setIsUpdating(true);
|
await updateMonitor({ monitor, redirect: "/pagespeed" });
|
||||||
await updateMonitor({ monitor: monitorData, redirect: "/pagespeed" });
|
|
||||||
setIsUpdating(false);
|
|
||||||
} else {
|
} else {
|
||||||
let form = {
|
let form = {
|
||||||
url: `http${https ? "s" : ""}://` + monitorData.url,
|
url: `http${https ? "s" : ""}://` + monitor.url,
|
||||||
name: monitorData.name === "" ? monitorData.url : monitorData.name,
|
name: monitor.name === "" ? monitor.url : monitor.name,
|
||||||
type: monitorData.type,
|
type: monitor.type,
|
||||||
interval: monitorData.interval * MS_PER_MINUTE,
|
interval: monitor.interval,
|
||||||
description: monitorData.name === "" ? monitorData.url : monitorData.name,
|
|
||||||
notifications: monitorData.notifications,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const { error } = monitorValidation.validate(form, { abortEarly: false });
|
const { error } = monitorValidation.validate(form, { abortEarly: false });
|
||||||
if (error) {
|
if (error) {
|
||||||
const newErrors = {};
|
const newErrors = {};
|
||||||
@@ -156,296 +125,350 @@ const PageSpeedSetup = ({ monitor }) => {
|
|||||||
createToast({ body: "Please check the form for errors." });
|
createToast({ body: "Please check the form for errors." });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setIsLoading(true);
|
|
||||||
|
form = {
|
||||||
|
...form,
|
||||||
|
description: form.name,
|
||||||
|
notifications: monitor.notifications,
|
||||||
|
};
|
||||||
await createMonitor({ monitor: form, redirect: "/pagespeed" });
|
await createMonitor({ monitor: form, redirect: "/pagespeed" });
|
||||||
setIsLoading(false);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleChange = (event) => {
|
||||||
|
let { value, name } = event.target;
|
||||||
|
|
||||||
|
if (name === "interval") {
|
||||||
|
value = value * MS_PER_MINUTE;
|
||||||
|
}
|
||||||
|
|
||||||
|
setMonitor({
|
||||||
|
...monitor,
|
||||||
|
[name]: value
|
||||||
|
});
|
||||||
|
|
||||||
|
const { error } = monitorValidation.validate(
|
||||||
|
{ [name]: value },
|
||||||
|
{ abortEarly: false }
|
||||||
|
);
|
||||||
|
setErrors((prev) => ({
|
||||||
|
...prev,
|
||||||
|
...(error ? { [name]: error.details[0].message } : { [name]: undefined})
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleBlur = (event) => {
|
||||||
|
const { name, value } = event.target;
|
||||||
|
if (name === "url" && monitor.name === "") {
|
||||||
|
setMonitor((prev) => ({ ...prev, name: parseDomainName(value) }));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const triggerUpdate = () => {
|
||||||
|
setUpdateTrigger(!updateTrigger);
|
||||||
|
};
|
||||||
|
|
||||||
const handlePause = async () => {
|
const handlePause = async () => {
|
||||||
setIsPausing(true);
|
await pauseMonitor({ monitorId, triggerUpdate });
|
||||||
await pauseMonitor({ monitorId, triggerUpdate: () => setUpdateTrigger((u) => !u) });
|
|
||||||
setIsPausing(false);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRemove = async (event) => {
|
const handleRemove = async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
setIsDeleting(true);
|
await deleteMonitor({ monitor, redirect: "/pagespeed" });
|
||||||
await deleteMonitor({ monitor: monitorData, redirect: "/pagespeed" });
|
|
||||||
setIsDeleting(false);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Loading skeleton
|
// // Loading skeleton
|
||||||
if (isConfigure && (isLoading || !monitorData._id)) {
|
// if (isConfigure && (isLoading || !monitor._id)) {
|
||||||
return <SkeletonLayout />;
|
// return <SkeletonLayout />;
|
||||||
}
|
// }
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
className={isConfigure ? "configure-pagespeed" : "create-monitor"}
|
className={isConfigure ? "configure-pagespeed" : "create-monitor"}
|
||||||
|
// gap={theme.spacing(10)}
|
||||||
sx={{
|
sx={{
|
||||||
"& h1": { color: theme.palette.primary.contrastText },
|
"& h1": { color: theme.palette.primary.contrastText },
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Breadcrumbs
|
{Object.keys(monitor).length === 0 ? (
|
||||||
list={
|
<SkeletonLayout />
|
||||||
isConfigure
|
) : (
|
||||||
? [
|
<>
|
||||||
{ name: "pagespeed", path: "/pagespeed" },
|
<Breadcrumbs
|
||||||
{ name: "details", path: `/pagespeed/${monitorId}` },
|
list={ CRUMBS }
|
||||||
{ name: "configure", path: `/pagespeed/setup/${monitorId}` },
|
/>
|
||||||
]
|
<Stack
|
||||||
: [
|
component="form"
|
||||||
{ name: "pagespeed", path: "/pagespeed" },
|
className={isConfigure ? "" : "create-monitor-form"}
|
||||||
{ name: "create", path: `/pagespeed/setup` },
|
onSubmit={onSubmit}
|
||||||
]
|
noValidate
|
||||||
}
|
spellCheck="false"
|
||||||
/>
|
gap={theme.spacing(12)}
|
||||||
<Stack
|
mt={theme.spacing(6)}
|
||||||
component="form"
|
>
|
||||||
className={isConfigure ? undefined : "create-monitor-form"}
|
<Stack direction="row" gap={theme.spacing(2)}>
|
||||||
onSubmit={onSubmit}
|
<Box>
|
||||||
noValidate
|
<Typography component="h1" variant="h1">
|
||||||
spellCheck="false"
|
<Typography
|
||||||
gap={theme.spacing(12)}
|
component="span"
|
||||||
mt={theme.spacing(6)}
|
fontSize="inherit"
|
||||||
>
|
color={isConfigure ? theme.palette.primary.contrastTextSecondary : undefined}
|
||||||
<Typography component="h1" variant="h1">
|
>
|
||||||
<Typography component="span" fontSize="inherit">
|
{isConfigure ? monitor.name : t("createYour") + " "}
|
||||||
{isConfigure ? monitorData.name : t("createYour") + " "}
|
</Typography>
|
||||||
</Typography>
|
{ !isConfigure
|
||||||
{ !isConfigure
|
? (
|
||||||
? (
|
<Typography
|
||||||
<Typography
|
component="span"
|
||||||
component="span"
|
fontSize="inherit"
|
||||||
fontSize="inherit"
|
fontWeight="inherit"
|
||||||
fontWeight="inherit"
|
color={theme.palette.primary.contrastTextSecondary}
|
||||||
color={theme.palette.primary.contrastTextSecondary}
|
>
|
||||||
>
|
{t("pageSpeedMonitor")}
|
||||||
{t("pageSpeedMonitor")}
|
</Typography>
|
||||||
</Typography>
|
)
|
||||||
)
|
: <></>
|
||||||
: <></>
|
}
|
||||||
}
|
</Typography>
|
||||||
</Typography>
|
{isConfigure && (
|
||||||
{isConfigure && (
|
<Stack direction="row" alignItems="center" height="fit-content" gap={theme.spacing(2)}>
|
||||||
<Stack direction="row" gap={theme.spacing(2)}>
|
<Tooltip
|
||||||
<Box>
|
title={pagespeedStatusMsg[determineState(monitor)]}
|
||||||
<Stack direction="row" alignItems="center" height="fit-content" gap={theme.spacing(2)}>
|
disableInteractive
|
||||||
<Tooltip
|
slotProps={{
|
||||||
title={pagespeedStatusMsg[determineState(monitorData)]}
|
popper: {
|
||||||
disableInteractive
|
modifiers: [
|
||||||
slotProps={{
|
{
|
||||||
popper: {
|
name: "offset",
|
||||||
modifiers: [
|
options: { offset: [0, -8] },
|
||||||
{
|
},
|
||||||
name: "offset",
|
],
|
||||||
options: { offset: [0, -8] },
|
|
||||||
},
|
},
|
||||||
],
|
}}
|
||||||
},
|
>
|
||||||
}}
|
<Box>
|
||||||
>
|
<PulseDot color={statusColor[determineState(monitor)]} />
|
||||||
<Box>
|
</Box>
|
||||||
<PulseDot color={statusColor[determineState(monitorData)]} />
|
</Tooltip>
|
||||||
</Box>
|
<Typography component="h2" variant="monitorUrl">
|
||||||
</Tooltip>
|
{monitor.url?.replace(/^https?:\/\//, "") || "..."}
|
||||||
<Typography component="h2" variant="monitorUrl">
|
</Typography>
|
||||||
{monitorData.url?.replace(/^https?:\/\//, "") || "..."}
|
<Typography
|
||||||
</Typography>
|
position="relative"
|
||||||
<Typography
|
variant="body2"
|
||||||
position="relative"
|
ml={theme.spacing(6)}
|
||||||
variant="body2"
|
mt={theme.spacing(1)}
|
||||||
ml={theme.spacing(6)}
|
sx={{
|
||||||
mt={theme.spacing(1)}
|
"&:before": {
|
||||||
sx={{
|
position: "absolute",
|
||||||
"&:before": {
|
content: `""`,
|
||||||
position: "absolute",
|
width: 4,
|
||||||
content: `""`,
|
height: 4,
|
||||||
width: 4,
|
borderRadius: "50%",
|
||||||
height: 4,
|
backgroundColor: theme.palette.primary.contrastTextTertiary,
|
||||||
borderRadius: "50%",
|
opacity: 0.8,
|
||||||
backgroundColor: theme.palette.primary.contrastTextTertiary,
|
left: -10,
|
||||||
opacity: 0.8,
|
top: "50%",
|
||||||
left: -10,
|
transform: "translateY(-50%)",
|
||||||
top: "50%",
|
},
|
||||||
transform: "translateY(-50%)",
|
}}
|
||||||
},
|
>
|
||||||
}}
|
{t("editing")}
|
||||||
>
|
</Typography>
|
||||||
{t("editing")}
|
</Stack>
|
||||||
</Typography>
|
|
||||||
</Stack>
|
|
||||||
</Box>
|
|
||||||
<Box alignSelf="flex-end" ml="auto">
|
|
||||||
<Button
|
|
||||||
onClick={handlePause}
|
|
||||||
loading={isLoading}
|
|
||||||
variant="contained"
|
|
||||||
color="secondary"
|
|
||||||
sx={{
|
|
||||||
pl: theme.spacing(4),
|
|
||||||
pr: theme.spacing(6),
|
|
||||||
"& svg": {
|
|
||||||
mr: theme.spacing(2),
|
|
||||||
"& path": {
|
|
||||||
stroke: theme.palette.primary.contrastTextTertiary,
|
|
||||||
strokeWidth: 0.1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{monitorData?.isActive ? (
|
|
||||||
<>
|
|
||||||
<PauseCircleOutlineIcon />
|
|
||||||
{t("pause")}
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<PlayCircleOutlineRoundedIcon />
|
|
||||||
{t("resume")}
|
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Box>
|
||||||
<Button
|
{isConfigure && (
|
||||||
loading={isLoading}
|
<Box alignSelf="flex-end" ml="auto">
|
||||||
variant="contained"
|
<Button
|
||||||
color="error"
|
onClick={handlePause}
|
||||||
onClick={() => setIsOpen(true)}
|
loading={isLoading}
|
||||||
sx={{ ml: theme.spacing(6) }}
|
variant="contained"
|
||||||
|
color="secondary"
|
||||||
|
sx={{
|
||||||
|
pl: theme.spacing(4),
|
||||||
|
pr: theme.spacing(6),
|
||||||
|
"& svg": {
|
||||||
|
mr: theme.spacing(2),
|
||||||
|
"& path": {
|
||||||
|
stroke: theme.palette.primary.contrastTextTertiary,
|
||||||
|
strokeWidth: 0.1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{monitor?.isActive ? (
|
||||||
|
<>
|
||||||
|
<PauseCircleOutlineIcon />
|
||||||
|
{t("pause")}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<PlayCircleOutlineRoundedIcon />
|
||||||
|
{t("resume")}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
loading={isLoading}
|
||||||
|
variant="contained"
|
||||||
|
color="error"
|
||||||
|
onClick={() => setIsOpen(true)}
|
||||||
|
sx={{ ml: theme.spacing(6) }}
|
||||||
|
>
|
||||||
|
{t("remove")}
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
<ConfigBox>
|
||||||
|
<Box>
|
||||||
|
<Typography component="h2" variant="h2">
|
||||||
|
{t("settingsGeneralSettings")}
|
||||||
|
</Typography>
|
||||||
|
<Typography component="p">
|
||||||
|
{t("pageSpeedConfigureSettingsDescription")}
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
<Stack
|
||||||
|
gap={isConfigure ? theme.spacing(20) : theme.spacing(15)}
|
||||||
|
sx={{
|
||||||
|
".MuiInputBase-root:has(> .Mui-disabled)": {
|
||||||
|
backgroundColor: theme.palette.tertiary.main,
|
||||||
|
},
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{t("remove")}
|
<TextInput
|
||||||
</Button>
|
type={"url"}
|
||||||
</Box>
|
name="url"
|
||||||
</Stack>
|
id="monitor-url"
|
||||||
)}
|
label={isConfigure ? t("url") : "URL to monitor"}
|
||||||
<ConfigBox>
|
startAdornment={!isConfigure ? <HttpAdornment https={https} /> : undefined}
|
||||||
<Box>
|
placeholder="random.website.com"
|
||||||
<Typography component="h2" variant="h2">
|
value={monitor.url || ""}
|
||||||
{t("settingsGeneralSettings")}
|
onChange={handleChange}
|
||||||
</Typography>
|
onBlur={!isConfigure ? handleBlur : undefined}
|
||||||
<Typography component="p">
|
error={!!errors["url"]}
|
||||||
{isConfigure ? t("pageSpeedConfigureSettingsDescription") : t("distributedUptimeCreateSelectURL")}
|
helperText={errors["url"]}
|
||||||
</Typography>
|
disabled={isConfigure}
|
||||||
</Box>
|
/>
|
||||||
<Stack gap={isConfigure ? theme.spacing(20) : theme.spacing(15)}>
|
<TextInput
|
||||||
<TextInput
|
type="text"
|
||||||
type={"url"}
|
id="monitor-name"
|
||||||
name="url"
|
name="name"
|
||||||
id="monitor-url"
|
label={t("monitorDisplayName")}
|
||||||
label={t("url")}
|
isOptional={true}
|
||||||
startAdornment={!isConfigure ? <HttpAdornment https={https} /> : undefined}
|
placeholder="Google"
|
||||||
placeholder={isConfigure ? "random.website.com" : "google.com"}
|
value={monitor.name || ""}
|
||||||
value={monitorData.url || ""}
|
onChange={handleChange}
|
||||||
onChange={handleChange}
|
error={!!errors["name"]}
|
||||||
onBlur={!isConfigure ? handleBlur : undefined}
|
helperText={errors["name"]}
|
||||||
error={!!errors["url"]}
|
|
||||||
helperText={errors["url"]}
|
|
||||||
disabled={isConfigure}
|
|
||||||
/>
|
|
||||||
<TextInput
|
|
||||||
type="text"
|
|
||||||
id="monitor-name"
|
|
||||||
name="name"
|
|
||||||
label={t("monitorDisplayName")}
|
|
||||||
isOptional={true}
|
|
||||||
placeholder={isConfigure ? "Example monitor" : "Google"}
|
|
||||||
value={monitorData.name || ""}
|
|
||||||
onChange={handleChange}
|
|
||||||
error={!!errors["name"]}
|
|
||||||
helperText={errors["name"]}
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
</ConfigBox>
|
|
||||||
{!isConfigure && (
|
|
||||||
<ConfigBox>
|
|
||||||
<Box>
|
|
||||||
<Typography component="h2" variant="h2">
|
|
||||||
{t("distributedUptimeCreateChecks")}
|
|
||||||
</Typography>
|
|
||||||
<Typography component="p">
|
|
||||||
{t("distributedUptimeCreateChecksDescription")}
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
<Stack gap={theme.spacing(12)}>
|
|
||||||
<Stack gap={theme.spacing(6)}>
|
|
||||||
<Radio
|
|
||||||
id="monitor-checks-http"
|
|
||||||
title="PageSpeed"
|
|
||||||
desc="Use the Lighthouse PageSpeed API to monitor your website"
|
|
||||||
size="small"
|
|
||||||
value="http"
|
|
||||||
checked={monitorData.type === "pagespeed"}
|
|
||||||
/>
|
/>
|
||||||
<ButtonGroup sx={{ ml: "32px" }}>
|
|
||||||
<Button
|
|
||||||
variant="group"
|
|
||||||
filled={https.toString()}
|
|
||||||
onClick={() => setHttps(true)}
|
|
||||||
>
|
|
||||||
{t("https")}
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
variant="group"
|
|
||||||
filled={(!https).toString()}
|
|
||||||
onClick={() => setHttps(false)}
|
|
||||||
>
|
|
||||||
{t("http")}
|
|
||||||
</Button>
|
|
||||||
</ButtonGroup>
|
|
||||||
</Stack>
|
</Stack>
|
||||||
{errors["type"] ? (
|
</ConfigBox>
|
||||||
<Box className="error-container">
|
{!isConfigure && (
|
||||||
<Typography component="p" className="input-error" color={theme.palette.error.contrastText}>
|
<ConfigBox>
|
||||||
{errors["type"]}
|
<Box>
|
||||||
|
<Typography component="h2" variant="h2">
|
||||||
|
{t("distributedUptimeCreateChecks")}
|
||||||
|
</Typography>
|
||||||
|
<Typography component="p">
|
||||||
|
{t("distributedUptimeCreateChecksDescription")}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
) : null}
|
<Stack gap={theme.spacing(12)}>
|
||||||
|
<Stack gap={theme.spacing(6)}>
|
||||||
|
<Radio
|
||||||
|
id="monitor-checks-http"
|
||||||
|
title="PageSpeed"
|
||||||
|
desc="Use the Lighthouse PageSpeed API to monitor your website"
|
||||||
|
size="small"
|
||||||
|
value="http"
|
||||||
|
checked={monitor.type === "pagespeed"}
|
||||||
|
/>
|
||||||
|
<ButtonGroup sx={{ ml: "32px" }}>
|
||||||
|
<Button
|
||||||
|
variant="group"
|
||||||
|
filled={https.toString()}
|
||||||
|
onClick={() => setHttps(true)}
|
||||||
|
>
|
||||||
|
{t("https")}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="group" // Why does this work?
|
||||||
|
filled={(!https).toString()} // There's nothing in the docs about this either
|
||||||
|
onClick={() => setHttps(false)}
|
||||||
|
>
|
||||||
|
{t("http")}
|
||||||
|
</Button>
|
||||||
|
</ButtonGroup>
|
||||||
|
</Stack>
|
||||||
|
{errors["type"] ? (
|
||||||
|
<Box className="error-container">
|
||||||
|
<Typography
|
||||||
|
component="p"
|
||||||
|
className="input-error"
|
||||||
|
color={theme.palette.error.contrastText}
|
||||||
|
>
|
||||||
|
{errors["type"]}
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
) : ""}
|
||||||
|
</Stack>
|
||||||
|
</ConfigBox>
|
||||||
|
)}
|
||||||
|
<ConfigBox>
|
||||||
|
<Box>
|
||||||
|
<Typography component="h2" variant="h2">
|
||||||
|
{t("notificationConfig.title")}
|
||||||
|
</Typography>
|
||||||
|
<Typography component="p">{t("notificationConfig.description")}</Typography>
|
||||||
|
</Box>
|
||||||
|
<NotificationsConfig
|
||||||
|
notifications={notifications}
|
||||||
|
setMonitor={setMonitor}
|
||||||
|
setNotifications={isConfigure ? monitor.notifications : undefined}
|
||||||
|
/>
|
||||||
|
</ConfigBox>
|
||||||
|
<ConfigBox>
|
||||||
|
<Box>
|
||||||
|
<Typography
|
||||||
|
component="h2"
|
||||||
|
variant="h2"
|
||||||
|
>
|
||||||
|
{t("distributedUptimeCreateAdvancedSettings")}
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
<Stack gap={theme.spacing(isConfigure ? 20 : 12)}>
|
||||||
|
<Select
|
||||||
|
id="monitor-interval"
|
||||||
|
name="interval"
|
||||||
|
label={t("checkFrequency")}
|
||||||
|
value={monitor?.interval / MS_PER_MINUTE || 3}
|
||||||
|
onChange={handleChange}
|
||||||
|
items={FREQUENCIES}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
</ConfigBox>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
justifyContent="flex-end"
|
||||||
|
mt={isConfigure ? "auto" : undefined}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
type="submit"
|
||||||
|
variant="contained"
|
||||||
|
color="accent"
|
||||||
|
disabled={!Object.values(errors).every((value) => value === undefined)}
|
||||||
|
loading={isLoading || isDeleting || isUpdating || isPausing || isCreating}
|
||||||
|
sx={isConfigure ? { px: theme.spacing(12) } : undefined}
|
||||||
|
>
|
||||||
|
{isConfigure ? t("settingsSave") : t("createMonitor")}
|
||||||
|
</Button>
|
||||||
</Stack>
|
</Stack>
|
||||||
</ConfigBox>
|
|
||||||
)}
|
|
||||||
<ConfigBox>
|
|
||||||
<Box>
|
|
||||||
<Typography component="h2" variant="h2">
|
|
||||||
{t("notificationConfig.title")}
|
|
||||||
</Typography>
|
|
||||||
<Typography component="p">{t("notificationConfig.description")}</Typography>
|
|
||||||
</Box>
|
|
||||||
<NotificationsConfig
|
|
||||||
notifications={notifications}
|
|
||||||
setMonitor={setMonitorData}
|
|
||||||
setNotifications={isConfigure ? monitorData.notifications : undefined}
|
|
||||||
/>
|
|
||||||
</ConfigBox>
|
|
||||||
<ConfigBox>
|
|
||||||
<Box>
|
|
||||||
<Typography component="h2" variant="h2">
|
|
||||||
{t("distributedUptimeCreateAdvancedSettings")}
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
<Stack gap={isConfigure ? theme.spacing(20) : theme.spacing(12)}>
|
|
||||||
<Select
|
|
||||||
name="interval"
|
|
||||||
label={t("checkFrequency")}
|
|
||||||
value={isConfigure ? monitorData.interval / MS_PER_MINUTE || 3 : monitorData.interval || 3}
|
|
||||||
onChange={handleChange}
|
|
||||||
items={frequencies}
|
|
||||||
/>
|
|
||||||
</Stack>
|
</Stack>
|
||||||
</ConfigBox>
|
</>
|
||||||
<Stack direction="row" justifyContent="flex-end" mt={isConfigure ? "auto" : undefined}>
|
)}
|
||||||
<Button
|
|
||||||
type="submit"
|
|
||||||
variant="contained"
|
|
||||||
color="accent"
|
|
||||||
disabled={!Object.values(errors).every((value) => value === undefined)}
|
|
||||||
loading={isLoading || isDeleting || isUpdating || isPausing || isCreating}
|
|
||||||
sx={isConfigure ? { px: theme.spacing(12) } : undefined}
|
|
||||||
>
|
|
||||||
{isConfigure ? t("settingsSave") : t("createMonitor")}
|
|
||||||
</Button>
|
|
||||||
</Stack>
|
|
||||||
</Stack>
|
|
||||||
{isConfigure && (
|
{isConfigure && (
|
||||||
<Dialog
|
<Dialog
|
||||||
open={isOpen}
|
open={isOpen}
|
||||||
|
|||||||
@@ -18,10 +18,8 @@ import UptimeConfigure from "../Pages/Uptime/Configure";
|
|||||||
|
|
||||||
// PageSpeed
|
// PageSpeed
|
||||||
import PageSpeed from "../Pages/PageSpeed/Monitors";
|
import PageSpeed from "../Pages/PageSpeed/Monitors";
|
||||||
import PageSpeedSetup from "../Pages/PageSpeed/Setup";
|
|
||||||
import PageSpeedCreate from "../Pages/PageSpeed/Create";
|
|
||||||
import PageSpeedDetails from "../Pages/PageSpeed/Details";
|
import PageSpeedDetails from "../Pages/PageSpeed/Details";
|
||||||
import PageSpeedConfigure from "../Pages/PageSpeed/Configure";
|
import PageSpeedSetup from "../Pages/PageSpeed/Setup";
|
||||||
|
|
||||||
// Infrastructure
|
// Infrastructure
|
||||||
import Infrastructure from "../Pages/Infrastructure/Monitors";
|
import Infrastructure from "../Pages/Infrastructure/Monitors";
|
||||||
@@ -108,7 +106,7 @@ const Routes = () => {
|
|||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="pagespeed/configure/:monitorId"
|
path="pagespeed/configure/:monitorId"
|
||||||
element={<PageSpeedSetup monitor={true} />}
|
element={<PageSpeedSetup configure={true} />}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="infrastructure"
|
path="infrastructure"
|
||||||
|
|||||||
Reference in new issue
Block a user