Ran npm start format
This commit is contained in:
1 parent
da7d9c02c8
commit
e04ac77ddd
4 files changed
+107
-107
No files matched your search
@@ -1,95 +1,95 @@
|
|||||||
import Box from "@mui/material/Box";
|
import Box from "@mui/material/Box";
|
||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
import ConfigBox from "../../Components/ConfigBox";
|
import ConfigBox from "../../Components/ConfigBox";
|
||||||
import TextInput from "../../Components/Inputs/TextInput";
|
import TextInput from "../../Components/Inputs/TextInput";
|
||||||
|
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { PropTypes } from "prop-types";
|
import { PropTypes } from "prop-types";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
const SettingsGlobalThresholds = ({
|
const SettingsGlobalThresholds = ({
|
||||||
isAdmin,
|
isAdmin,
|
||||||
HEADING_SX,
|
HEADING_SX,
|
||||||
settingsData,
|
settingsData,
|
||||||
setSettingsData,
|
setSettingsData,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation(); // For language translation
|
const { t } = useTranslation(); // For language translation
|
||||||
const theme = useTheme(); // MUI theme access
|
const theme = useTheme(); // MUI theme access
|
||||||
|
|
||||||
// Handles input change and updates parent state
|
// Handles input change and updates parent state
|
||||||
const handleChange = (e, min, max) => {
|
const handleChange = (e, min, max) => {
|
||||||
const { name, value } = e.target;
|
const { name, value } = e.target;
|
||||||
|
|
||||||
const numValue = parseFloat(value);
|
const numValue = parseFloat(value);
|
||||||
const isValidNumber =
|
const isValidNumber =
|
||||||
value === "" ||
|
value === "" ||
|
||||||
(!isNaN(numValue) && isFinite(numValue) && numValue >= min && numValue <= max);
|
(!isNaN(numValue) && isFinite(numValue) && numValue >= min && numValue <= max);
|
||||||
|
|
||||||
if (isValidNumber) {
|
if (isValidNumber) {
|
||||||
setSettingsData((prev) => ({
|
setSettingsData((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
settings: {
|
settings: {
|
||||||
...prev.settings,
|
...prev.settings,
|
||||||
globalThresholds: {
|
globalThresholds: {
|
||||||
...prev.settings?.globalThresholds,
|
...prev.settings?.globalThresholds,
|
||||||
[name]: value,
|
[name]: value,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Only render this section for admins
|
// Only render this section for admins
|
||||||
if (!isAdmin) return null;
|
if (!isAdmin) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ConfigBox>
|
<ConfigBox>
|
||||||
{/* Header and description */}
|
{/* Header and description */}
|
||||||
<Box>
|
<Box>
|
||||||
<Typography
|
<Typography
|
||||||
component="h1"
|
component="h1"
|
||||||
variant="h2"
|
variant="h2"
|
||||||
>
|
>
|
||||||
{t("settingsPage.globalThresholds.title", "Global Thresholds")}
|
{t("settingsPage.globalThresholds.title", "Global Thresholds")}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography sx={HEADING_SX}>
|
<Typography sx={HEADING_SX}>
|
||||||
{t(
|
{t(
|
||||||
"settingsPage.globalThresholds.description",
|
"settingsPage.globalThresholds.description",
|
||||||
"Configure global CPU, Memory, Disk, and Temperature thresholds."
|
"Configure global CPU, Memory, Disk, and Temperature thresholds."
|
||||||
)}
|
)}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
{/* Threshold inputs */}
|
{/* Threshold inputs */}
|
||||||
<Stack gap={theme.spacing(20)}>
|
<Stack gap={theme.spacing(20)}>
|
||||||
{[
|
{[
|
||||||
["CPU Threshold (%)", "cpu", 1, 100],
|
["CPU Threshold (%)", "cpu", 1, 100],
|
||||||
["Memory Threshold (%)", "memory", 1, 100],
|
["Memory Threshold (%)", "memory", 1, 100],
|
||||||
["Disk Threshold (%)", "disk", 1, 100],
|
["Disk Threshold (%)", "disk", 1, 100],
|
||||||
["Temperature Threshold (°C)", "temperature", 1, 150],
|
["Temperature Threshold (°C)", "temperature", 1, 150],
|
||||||
].map(([label, name, min, max]) => (
|
].map(([label, name, min, max]) => (
|
||||||
<TextInput
|
<TextInput
|
||||||
key={name}
|
key={name}
|
||||||
name={name}
|
name={name}
|
||||||
label={label}
|
label={label}
|
||||||
placeholder={`${min} - ${max}`}
|
placeholder={`${min} - ${max}`}
|
||||||
type="number"
|
type="number"
|
||||||
value={settingsData?.settings?.globalThresholds?.[name] || ""}
|
value={settingsData?.settings?.globalThresholds?.[name] || ""}
|
||||||
onChange={(e) => handleChange(e, min, max)}
|
onChange={(e) => handleChange(e, min, max)}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</Stack>
|
</Stack>
|
||||||
</ConfigBox>
|
</ConfigBox>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Prop types
|
// Prop types
|
||||||
SettingsGlobalThresholds.propTypes = {
|
SettingsGlobalThresholds.propTypes = {
|
||||||
isAdmin: PropTypes.bool,
|
isAdmin: PropTypes.bool,
|
||||||
HEADING_SX: PropTypes.object,
|
HEADING_SX: PropTypes.object,
|
||||||
settingsData: PropTypes.object,
|
settingsData: PropTypes.object,
|
||||||
setSettingsData: PropTypes.func,
|
setSettingsData: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default SettingsGlobalThresholds;
|
export default SettingsGlobalThresholds;
|
||||||
@@ -49,7 +49,7 @@ const Settings = () => {
|
|||||||
setIsApiKeySet,
|
setIsApiKeySet,
|
||||||
setIsEmailPasswordSet,
|
setIsEmailPasswordSet,
|
||||||
});
|
});
|
||||||
|
|
||||||
const [addDemoMonitors, isAddingDemoMonitors] = useAddDemoMonitors();
|
const [addDemoMonitors, isAddingDemoMonitors] = useAddDemoMonitors();
|
||||||
|
|
||||||
const [isSaving, saveError, saveSettings] = useSaveSettings({
|
const [isSaving, saveError, saveSettings] = useSaveSettings({
|
||||||
@@ -62,7 +62,6 @@ const Settings = () => {
|
|||||||
const [deleteAllMonitors, isDeletingMonitors] = useDeleteAllMonitors();
|
const [deleteAllMonitors, isDeletingMonitors] = useDeleteAllMonitors();
|
||||||
const [deleteMonitorStats, isDeletingMonitorStats] = useDeleteMonitorStats();
|
const [deleteMonitorStats, isDeletingMonitorStats] = useDeleteMonitorStats();
|
||||||
|
|
||||||
|
|
||||||
// Setup
|
// Setup
|
||||||
const isAdmin = useIsAdmin();
|
const isAdmin = useIsAdmin();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
@@ -152,7 +151,7 @@ const Settings = () => {
|
|||||||
error.details.forEach((err) => {
|
error.details.forEach((err) => {
|
||||||
newErrors[err.path[0]] = err.message;
|
newErrors[err.path[0]] = err.message;
|
||||||
});
|
});
|
||||||
|
|
||||||
setErrors(newErrors);
|
setErrors(newErrors);
|
||||||
}
|
}
|
||||||
saveSettings(settingsData?.settings);
|
saveSettings(settingsData?.settings);
|
||||||
|
|||||||
@@ -302,15 +302,16 @@ const settingsValidation = joi.object({
|
|||||||
systemEmailIgnoreTLS: joi.boolean(),
|
systemEmailIgnoreTLS: joi.boolean(),
|
||||||
systemEmailRequireTLS: joi.boolean(),
|
systemEmailRequireTLS: joi.boolean(),
|
||||||
systemEmailRejectUnauthorized: joi.boolean(),
|
systemEmailRejectUnauthorized: joi.boolean(),
|
||||||
globalThresholds: joi.object({
|
globalThresholds: joi
|
||||||
cpu: joi.number().min(1).max(100).allow("").optional(),
|
.object({
|
||||||
memory: joi.number().min(1).max(100).allow("").optional(),
|
cpu: joi.number().min(1).max(100).allow("").optional(),
|
||||||
disk: joi.number().min(1).max(100).allow("").optional(),
|
memory: joi.number().min(1).max(100).allow("").optional(),
|
||||||
temperature: joi.number().min(1).max(150).allow("").optional(),
|
disk: joi.number().min(1).max(100).allow("").optional(),
|
||||||
}).optional(),
|
temperature: joi.number().min(1).max(150).allow("").optional(),
|
||||||
|
})
|
||||||
|
.optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const dayjsValidator = (value, helpers) => {
|
const dayjsValidator = (value, helpers) => {
|
||||||
if (!dayjs(value).isValid()) {
|
if (!dayjs(value).isValid()) {
|
||||||
return helpers.error("any.invalid");
|
return helpers.error("any.invalid");
|
||||||
|
|||||||
@@ -838,8 +838,8 @@
|
|||||||
},
|
},
|
||||||
"title": "Settings",
|
"title": "Settings",
|
||||||
"globalThresholds": {
|
"globalThresholds": {
|
||||||
"title": "Global Thresholds",
|
"title": "Global Thresholds",
|
||||||
"description": "Configure global CPU, Memory, Disk, and Temperature thresholds. If a value is provided, it will automatically be enabled for monitoring."
|
"description": "Configure global CPU, Memory, Disk, and Temperature thresholds. If a value is provided, it will automatically be enabled for monitoring."
|
||||||
},
|
},
|
||||||
"uiSettings": {
|
"uiSettings": {
|
||||||
"description": "Switch between light and dark mode, or change user interface language.",
|
"description": "Switch between light and dark mode, or change user interface language.",
|
||||||
|
|||||||
Reference in new issue
Block a user