- Add basic joi validation to match what's available in BE

- Extract/ refactor the custom alert section to its own function
- WIP UI added custom alert section, retain log section and maxreties in advaced setting section
- Extend Field component to accomodate for custom alert narrower text field
This commit is contained in:
Shemy Gan committed 2024-11-06 11:13:02 -05:00
1 parent 4452cb90e6
commit 63cb4e7f1d
5 files changed
+170 -175

No files matched your search

@@ -1,6 +1,15 @@
.field { .field {
min-width: 250px; min-width: 250px;
} }
.field-infrastructure-alert {
max-width: 100px;
}
.field-infrastructure-alert .MuiInputBase-root:has(input) {
height: 34px;
}
.field h3.MuiTypography-root, .field h3.MuiTypography-root,
.field h5.MuiTypography-root, .field h5.MuiTypography-root,
.field input, .field input,
+3 -1
View File
@@ -46,6 +46,7 @@ const Field = forwardRef(
error, error,
disabled, disabled,
hidden, hidden,
className
}, },
ref ref
) => { ) => {
@@ -56,7 +57,7 @@ const Field = forwardRef(
return ( return (
<Stack <Stack
gap={theme.spacing(2)} gap={theme.spacing(2)}
className={`field field-${type}`} className={`${className ?? `field field-${type}`}`}
sx={{ sx={{
"& fieldset": { "& fieldset": {
borderColor: theme.palette.border.dark, borderColor: theme.palette.border.dark,
@@ -223,6 +224,7 @@ Field.propTypes = {
error: PropTypes.string, error: PropTypes.string,
disabled: PropTypes.bool, disabled: PropTypes.bool,
hidden: PropTypes.bool, hidden: PropTypes.bool,
className: PropTypes.string
}; };
export default Field; export default Field;
@@ -86,7 +86,7 @@ export const getInfrastructureMonitorsByTeamId = createAsyncThunk(
const res = await networkService.getMonitorsAndSummaryByTeamId({ const res = await networkService.getMonitorsAndSummaryByTeamId({
authToken: token, authToken: token,
teamId: user.teamId, teamId: user.teamId,
types: ["http", "ping"], types: ["hardware"],
}); });
return res.data; return res.data;
} catch (error) { } catch (error) {
@@ -112,6 +112,7 @@ export const updateInfrastructureMonitor = createAsyncThunk(
description: monitor.description, description: monitor.description,
interval: monitor.interval, interval: monitor.interval,
notifications: monitor.notifications, notifications: monitor.notifications,
threshold: monitor.threshold
}; };
const res = await networkService.updateMonitor({ const res = await networkService.updateMonitor({
authToken: authToken, authToken: authToken,
@@ -1,8 +1,8 @@
import { useState } from "react"; import { useState } from "react";
import { Box, Button, ButtonGroup, Stack, Typography } from "@mui/material"; import { Box, Stack, Typography } from "@mui/material";
import LoadingButton from "@mui/lab/LoadingButton"; import LoadingButton from "@mui/lab/LoadingButton";
import { useSelector, useDispatch } from "react-redux"; import { useSelector, useDispatch } from "react-redux";
import { monitorValidation } from "../../../Validation/validation"; import { infrastractureMonitorValidation } from "../../../Validation/validation";
import { import {
createInfrastructureMonitor, createInfrastructureMonitor,
checkInfrastructureEndpointResolution, checkInfrastructureEndpointResolution,
@@ -12,13 +12,63 @@ import { useTheme } from "@emotion/react";
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 { ConfigBox } from "../../Monitors/styled";
import Radio from "../../../Components/Inputs/Radio";
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";
import Breadcrumbs from "../../../Components/Breadcrumbs"; import Breadcrumbs from "../../../Components/Breadcrumbs";
const CreateInfrastructureMonitor = () => { const CreateInfrastructureMonitor = () => {
const CustomAlertStack = ({
checkboxId,
checkboxLabel,
checkboxValue,
isChecked,
onChange,
fieldId,
fieldValue,
alertUnit,
}) => {
console.log("fieldValue")
console.log(fieldValue)
return (
<Stack
direction={"row"}
sx={{
width: "50%",
justifyContent: "space-between",
}}
>
<Box>
<Checkbox
id={checkboxId}
label={checkboxLabel}
value={checkboxValue??""}
isChecked= {isChecked??false}
onChange={onChange}
/>
</Box>
<Stack
direction={"row"}
sx={{
justifyContent: "flex-end",
}}
>
<Field
type="number"
className="field-infrastructure-alert"
id={fieldId}
value={fieldValue}
></Field>
<Typography
component="p"
m={theme.spacing(3)}
>
{alertUnit}
</Typography>
</Stack>
</Stack>
);}
const MS_PER_MINUTE = 60000; const MS_PER_MINUTE = 60000;
const { user, authToken } = useSelector((state) => state.auth); const { user, authToken } = useSelector((state) => state.auth);
const monitorState = useSelector((state) => state.infrastructureMonitor); const monitorState = useSelector((state) => state.infrastructureMonitor);
@@ -30,19 +80,16 @@ const CreateInfrastructureMonitor = () => {
"monitor-url": "url", "monitor-url": "url",
"monitor-name": "name", "monitor-name": "name",
"monitor-secret": "secret", "monitor-secret": "secret",
"monitor-checks-http": "type",
"monitor-checks-ping": "type",
"notify-email-default": "notification-email", "notify-email-default": "notification-email",
}; };
const [infrastructureMonitor, setInfrastructureMonitor] = useState({ const [infrastructureMonitor, setInfrastructureMonitor] = useState({
url: "", url: "",
name: "", name: "",
type: "http",
notifications: [], notifications: [],
interval: 1, interval: 1,
threshold: {cpu: "", disk: "", memory: ""}
}); });
const [https, setHttps] = useState(true);
const [errors, setErrors] = useState({}); const [errors, setErrors] = useState({});
const handleChange = (event, name) => { const handleChange = (event, name) => {
@@ -80,7 +127,7 @@ const CreateInfrastructureMonitor = () => {
[name]: value, [name]: value,
})); }));
const { error } = monitorValidation.validate( const { error } = infrastractureMonitorValidation.validate(
{ [name]: value }, { [name]: value },
{ abortEarly: false } { abortEarly: false }
); );
@@ -98,20 +145,15 @@ const CreateInfrastructureMonitor = () => {
event.preventDefault(); event.preventDefault();
//obj to submit //obj to submit
let form = { let form = {
url: url:infrastructureMonitor.url,
//preprending protocol for url
infrastructureMonitor.type === "http"
? `http${https ? "s" : ""}://` + infrastructureMonitor.url
: infrastructureMonitor.url,
name: name:
infrastructureMonitor.name === "" infrastructureMonitor.name === ""
? infrastructureMonitor.url ? infrastructureMonitor.url
: infrastructureMonitor.name, : infrastructureMonitor.name,
type: infrastructureMonitor.type,
interval: infrastructureMonitor.interval * MS_PER_MINUTE, interval: infrastructureMonitor.interval * MS_PER_MINUTE,
}; };
const { error } = monitorValidation.validate(form, { const { error } =infrastractureMonitorValidation.validate(form, {
abortEarly: false, abortEarly: false,
}); });
@@ -287,166 +329,75 @@ const CreateInfrastructureMonitor = () => {
</Typography> </Typography>
</Box> </Box>
<Stack gap={theme.spacing(6)}> <Stack gap={theme.spacing(6)}>
<Stack <CustomAlertStack
direction={"row"} checkboxId="customize-cpu"
sx={{ checkboxLabel="CPU"
justifyContent: "space-between", checkboxValue={""}
width: "75%", fieldId={"usage_cpu"}
}} fieldValue={infrastructureMonitor.threshold['cpu']??""}
> onChange={(event) => handleChange(event)}
<Box> alertUnit="%"
<Checkbox />
id="customize-cpu" <CustomAlertStack
label={`CPU`} checkboxId="customize-memory"
value={true} checkboxLabel="Memory"
onChange={(event) => handleChange(event)} checkboxValue={""}
/> fieldId={"usage_memory"}
</Box> fieldValue={infrastructureMonitor.threshold['memory']??""}
<Stack onChange={(event) => handleChange(event)}
direction={"row"} alertUnit="%"
sx={{ />
justifyContent: "flex-end", <CustomAlertStack
}} checkboxId="customize-disk"
> checkboxLabel="Disk"
<Box> checkboxValue={""}
<Field type="text"></Field> fieldId={"usage_disk"}
</Box> fieldValue={infrastructureMonitor.threshold['disk']??""}
<Box> onChange={(event) => handleChange(event)}
<Typography alertUnit="%"
component="p" />
m={theme.spacing(3)} {/* <CustomAlertStack
> checkboxId="customize-temperature"
% checkboxLabel="Temperature"
</Typography> checkboxValue={true}
</Box> onChange={(event) => handleChange(event)}
</Stack> alertUnit="°C"
</Stack> />
<Stack <CustomAlertStack
direction={"row"} checkboxId="customize-systemload"
sx={{ checkboxLabel="System load"
width: "75%", checkboxValue={true}
justifyContent: "space-between", onChange={(event) => handleChange(event)}
}} alertUnit="%"
> />
<Box> <CustomAlertStack
<Checkbox checkboxId="customize-swap"
id="customize-memory" checkboxLabel="Swap used"
label={`Memory`} checkboxValue={""}
value={true} onChange={(event) => handleChange(event)}
onChange={(event) => handleChange(event)} alertUnit="%"
/> /> */}
</Box>
<Stack
direction={"row"}
sx={{
justifyContent: "flex-end",
}}
>
<Field type="text"></Field>
<Typography
component="p"
m={theme.spacing(3)}
>
%
</Typography>
</Stack>
</Stack>
<Stack
direction={"row"}
sx={{
width: "75%",
justifyContent: "space-between",
}}
>
<Box>
<Checkbox
id="customize-disk"
label={`Disk`}
value={user?.email}
onChange={(event) => handleChange(event)}
/>
</Box>
<Stack
direction={"row"}
sx={{
justifyContent: "flex-end",
}}
>
<Field type="text"></Field>
<Typography
component="p"
m={theme.spacing(3)}
>
%
</Typography>
</Stack>
</Stack>
<Stack
direction={"row"}
sx={{
width: "75%",
justifyContent: "space-between",
}}
>
<Box>
<Checkbox
id="customize-temparature"
label={`Temparature`}
value={user?.email}
onChange={(event) => handleChange(event)}
/>
</Box>
<Stack
direction={"row"}
sx={{
justifyContent: "flex-end",
}}
>
<Field type="text"></Field>
<Typography
component="p"
m={theme.spacing(3)}
>
°C
</Typography>
</Stack>
</Stack>
<Stack
direction={"row"}
sx={{
width: "75%",
justifyContent: "space-between",
}}
>
<Box>
<Checkbox
id="customize-systemload"
label={`System load`}
value={user?.email}
onChange={(event) => handleChange(event)}
/>
</Box>
<Stack
direction={"row"}
sx={{
justifyContent: "flex-end",
}}
>
<Field type="text"></Field>
<Typography
component="p"
m={theme.spacing(3)}
>
%
</Typography>
</Stack>
</Stack>
</Stack> </Stack>
</ConfigBox> </ConfigBox>
<ConfigBox>
<Box>
<Typography component="h2">Logging retention</Typography>
<Typography component="p">
Configure how logn logs are stored. After this period, the Uptime Manager
will start deleting oldest data.
</Typography>
</Box>
{/* <Stack gap={theme.spacing(6)}>
<CustomAlertStack
checkboxId="retain-log"
checkboxLabel="Retain data for"
checkboxValue={""}
fieldId={"retries_max"}
onChange={(event) => handleChange(event)}
alertUnit="days"
/>
</Stack> */}
</ConfigBox>
<ConfigBox> <ConfigBox>
<Box> <Box>
<Typography component="h2">Advanced settings</Typography> <Typography component="h2">Advanced settings</Typography>
@@ -459,6 +410,14 @@ const CreateInfrastructureMonitor = () => {
onChange={(event) => handleChange(event, "interval")} onChange={(event) => handleChange(event, "interval")}
items={frequencies} items={frequencies}
/> />
<Field
type={"text"}
id="monitor-retries"
label="Maximum retries before the service is marked as down"
value={infrastructureMonitor.url}
onChange={handleChange}
error={errors["url"]}
/>
</Stack> </Stack>
</ConfigBox> </ConfigBox>
<Stack <Stack
+24
View File
@@ -173,6 +173,29 @@ const advancedSettingsValidation = joi.object({
pagespeedApiKey: joi.string().allow(""), pagespeedApiKey: joi.string().allow(""),
}); });
const infrastractureMonitorValidation = joi.object({
url: joi.string().uri({ allowRelative: true }).trim().messages({
"string.empty": "This field is required.",
"string.uri": "The URL you provided is not valid.",
}),
name: joi.string().trim().max(50).allow("").messages({
"string.max": "This field should not exceed the 50 characters limit.",
}),
type: joi.string().trim().messages({ "string.empty": "This field is required." }),
usage_cpu: joi.number(),
usage_memory: joi.number(),
usage_disk: joi.number(),
// usage_temperature: joi.number().messages({
// "number.base": "Temperature must be a number.",
// }),
// usage_system: joi.number().messages({
// "number.base": "System load must be a number.",
// }),
// usage_swap: joi.number().messages({
// "number.base": "Swap used must be a number.",
// }),
});
export { export {
credentials, credentials,
imageValidation, imageValidation,
@@ -180,4 +203,5 @@ export {
settingsValidation, settingsValidation,
maintenanceWindowValidation, maintenanceWindowValidation,
advancedSettingsValidation, advancedSettingsValidation,
infrastractureMonitorValidation
}; };