From 71cde317a7aa37a6d673f7566668f4bba3997233 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Mon, 25 Nov 2024 11:20:52 +0800 Subject: [PATCH] Add temperature threshold to create infrastructure monitor page --- .../Pages/Infrastructure/CreateMonitor/index.jsx | 13 ++++++++----- Client/src/Validation/error.js | 9 +++++++-- Client/src/Validation/validation.js | 7 ++++--- Server/validation/joi.js | 1 + 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Client/src/Pages/Infrastructure/CreateMonitor/index.jsx b/Client/src/Pages/Infrastructure/CreateMonitor/index.jsx index bbcb7b05d..1ebbab21e 100644 --- a/Client/src/Pages/Infrastructure/CreateMonitor/index.jsx +++ b/Client/src/Pages/Infrastructure/CreateMonitor/index.jsx @@ -32,12 +32,14 @@ const CreateInfrastructureMonitor = () => { usage_memory: "", disk: false, usage_disk: "", + temperature: false, + usage_temperature: "", secret: "", }); const MS_PER_MINUTE = 60000; const THRESHOLD_FIELD_PREFIX = "usage_"; - const HARDWARE_MONITOR_TYPES = ["cpu", "memory", "disk"]; + const HARDWARE_MONITOR_TYPES = ["cpu", "memory", "disk", "temperature"]; const { user, authToken } = useSelector((state) => state.auth); const monitorState = useSelector((state) => state.infrastructureMonitor); const dispatch = useDispatch(); @@ -74,18 +76,18 @@ const CreateInfrastructureMonitor = () => { }); }; - const handleBlur = (event, appenedID) => { + const handleBlur = (event, appendID) => { event.preventDefault(); const { value, id } = event.target; if (id?.startsWith("notify-email-")) return; const { error } = infrastructureMonitorValidation.validate( - { [id ?? appenedID]: value }, + { [id ?? appendID]: value }, { abortEarly: false, } ); setErrors((prev) => { - return buildErrors(prev, id ?? appenedID, error); + return buildErrors(prev, id ?? appendID, error); }); }; @@ -297,7 +299,8 @@ const CreateInfrastructureMonitor = () => { Customize alerts - Send a notification to user(s) when thresholds exceed a specified percentage. + Send a notification to user(s) when thresholds exceed a specified + percentage. diff --git a/Client/src/Validation/error.js b/Client/src/Validation/error.js index a941e2509..0d1359ad5 100644 --- a/Client/src/Validation/error.js +++ b/Client/src/Validation/error.js @@ -37,8 +37,13 @@ const hasValidationErrors = (form, validation, setErrors) => { if (!form.disk || form.usage_disk) { newErrors["usage_disk"] = null; } + if (!form.temperature || form.usage_temperature) { + newErrors["usage_temperature"] = null; + } }); - if (Object.values(newErrors).some(v=> v)) { + + console.log("newErrors", newErrors); + if (Object.values(newErrors).some((v) => v)) { setErrors(newErrors); return true; } else { @@ -48,4 +53,4 @@ const hasValidationErrors = (form, validation, setErrors) => { } return false; }; -export { buildErrors, hasValidationErrors }; \ No newline at end of file +export { buildErrors, hasValidationErrors }; diff --git a/Client/src/Validation/validation.js b/Client/src/Validation/validation.js index 7dfbeb246..332ea6aea 100644 --- a/Client/src/Validation/validation.js +++ b/Client/src/Validation/validation.js @@ -190,15 +190,16 @@ const infrastructureMonitorValidation = joi.object({ cpu: joi.boolean(), memory: joi.boolean(), disk: joi.boolean(), + temperature: joi.boolean(), usage_memory: joi.number().messages({ "number.base": THRESHOLD_COMMON_BASE_MSG, }), usage_disk: joi.number().messages({ "number.base": THRESHOLD_COMMON_BASE_MSG, }), - // usage_temperature: joi.number().messages({ - // "number.base": "Temperature must be a 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.", // }), diff --git a/Server/validation/joi.js b/Server/validation/joi.js index bc3967657..3b51e6e97 100644 --- a/Server/validation/joi.js +++ b/Server/validation/joi.js @@ -201,6 +201,7 @@ const createMonitorBodyValidation = joi.object({ usage_cpu: joi.number(), usage_memory: joi.number(), usage_disk: joi.number(), + usage_temperature: joi.number(), }), notifications: joi.array().items(joi.object()), secret: joi.string(),