From a9aece6123eaa20ce2173c62c7f7904379a9f0dd Mon Sep 17 00:00:00 2001 From: Shemy Gan Date: Thu, 14 Nov 2024 11:01:36 -0500 Subject: [PATCH] - set error as null instead of delete it - customize checkbox to pass in element as label - adjust checkbox posion to appear align top with string within the element label based on review feedback - remove the checkbox margin setting instead of comment out --- .../src/Components/Inputs/Checkbox/index.jsx | 5 +- .../CreateMonitor/index.jsx | 55 +++++++++++-------- Client/src/Validation/error.js | 6 +- 3 files changed, 37 insertions(+), 29 deletions(-) diff --git a/Client/src/Components/Inputs/Checkbox/index.jsx b/Client/src/Components/Inputs/Checkbox/index.jsx index 28643ce3a..20de4731b 100644 --- a/Client/src/Components/Inputs/Checkbox/index.jsx +++ b/Client/src/Components/Inputs/Checkbox/index.jsx @@ -39,6 +39,7 @@ const Checkbox = ({ }) => { const sizes = { small: "14px", medium: "16px", large: "18px" }; const theme = useTheme(); + const checkBoxPosition = typeof label === "string" ? {} : { pb: "65px" }; return ( { cpu: false, usage_cpu: "", memory: false, - usage_memory: "", + usage_memory: "", disk: false, - usage_disk: "", + usage_disk: "", secret: "", }); const MS_PER_MINUTE = 60000; - const THRESHOLD_FIELD_PREFIX = "usage_" - const HARDWARE_MONITOR_TYPES = ["cpu","memory","disk"] + const THRESHOLD_FIELD_PREFIX = "usage_"; + const HARDWARE_MONITOR_TYPES = ["cpu", "memory", "disk"]; const { user, authToken } = useSelector((state) => state.auth); const monitorState = useSelector((state) => state.infrastructureMonitor); const dispatch = useDispatch(); @@ -50,8 +50,9 @@ const CreateInfrastructureMonitor = () => { const [errors, setErrors] = useState({}); - const alertErrKeyLen = Object.keys(errors) - .filter(k => k.startsWith(THRESHOLD_FIELD_PREFIX)).length + const alertErrKeyLen = Object.keys(errors).filter((k) => + k.startsWith(THRESHOLD_FIELD_PREFIX) + ).length; const handleCustomAlertCheckChange = (event) => { const { value, id } = event.target; @@ -62,14 +63,14 @@ const CreateInfrastructureMonitor = () => { return { ...prev, ...newState, - [THRESHOLD_FIELD_PREFIX+ id]: newState[id] - ? prev[THRESHOLD_FIELD_PREFIX+ id] + [THRESHOLD_FIELD_PREFIX + id]: newState[id] + ? prev[THRESHOLD_FIELD_PREFIX + id] : "", }; }); // Remove the error if unchecked setErrors((prev) => { - return buildErrors(prev, [THRESHOLD_FIELD_PREFIX+ id]); + return buildErrors(prev, [THRESHOLD_FIELD_PREFIX + id]); }); }; @@ -134,7 +135,7 @@ const CreateInfrastructureMonitor = () => { if (form[k]) thresholds[k] = form[k]; delete form[k]; delete form[k.substring(THRESHOLD_FIELD_PREFIX.length)]; - }); + }); form = { ...form, @@ -193,6 +194,25 @@ const CreateInfrastructureMonitor = () => { { _id: 600, name: "10 minutes" }, ]; + const NOTIFY_MULTIPLE_EMAIL_LABEL = ( + + + Also notify via email to multiple addresses (coming soon) + + logger.warn("disabled")} + onBlur={handleBlur} + /> + + You can separate multiple emails with a comma + + + ); + return ( { /> logger.warn("disabled")} onBlur={handleBlur} isDisabled={true} /> - - logger.warn("disabled")} - onBlur={handleBlur} - /> - - You can separate multiple emails with a comma - - diff --git a/Client/src/Validation/error.js b/Client/src/Validation/error.js index e1278310b..d017cfd2d 100644 --- a/Client/src/Validation/error.js +++ b/Client/src/Validation/error.js @@ -29,13 +29,13 @@ const hasValidationErrors = (form, validation, setErrors) => { } // Handle conditionally usage number required cases if (!form.cpu || (form.cpu && form.usage_cpu)) { - delete newErrors["usage_cpu"]; + newErrors["usage_cpu"] = null; } if (!form.memory || (form.memory && form.usage_memory)) { - delete newErrors["usage_memory"]; + newErrors["usage_memory"] = null; } if (!form.disk || (form.disk && form.usage_disk)) { - delete newErrors["usage_disk"]; + newErrors["usage_disk"] = null; } }); if (Object.keys(newErrors).length > 0) {