From 7bbd984fcfb8413bc472d219dbeabcd00af715eb Mon Sep 17 00:00:00 2001 From: Shemy Gan Date: Mon, 11 Nov 2024 11:16:06 -0500 Subject: [PATCH] - WIP add memory and disk usage --- .../CreateMonitor/index.jsx | 18 ++++++++++-------- Client/src/Validation/error.js | 10 +++++++++- Client/src/Validation/validation.js | 12 ++++++++++-- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/Client/src/Pages/InfrastructureMonitors/CreateMonitor/index.jsx b/Client/src/Pages/InfrastructureMonitors/CreateMonitor/index.jsx index 199cb3b1f..515b3cbfb 100644 --- a/Client/src/Pages/InfrastructureMonitors/CreateMonitor/index.jsx +++ b/Client/src/Pages/InfrastructureMonitors/CreateMonitor/index.jsx @@ -116,16 +116,18 @@ const CreateInfrastructureMonitor = () => { }); }; - const handleBlur = (event) => { + const handleBlur = (event, appenedID) => { + event.preventDefault(); const { value, id } = event.target; + if (id?.startsWith("notify-email-")) return; const { error } = infrastractureMonitorValidation.validate( - { [id]: value }, + { [id ?? appenedID]: value }, { abortEarly: false, } ); setErrors((prev) => { - return buildErrors(prev, id, error); + return buildErrors(prev, id ?? appenedID, error); }); }; @@ -202,7 +204,7 @@ const CreateInfrastructureMonitor = () => { if (hasValidationErrors(form, infrastractureMonitorValidation, setErrors)) { return; } else { - const checkEndpointAction = await dispatch( + const checkEndpointAction = dispatch( checkInfrastructureEndpointResolution({ authToken, monitorURL: form.url }) ); if (checkEndpointAction.meta.requestStatus === "rejected") { @@ -212,7 +214,7 @@ const CreateInfrastructureMonitor = () => { setErrors({ url: "The entered URL is not reachable." }); return; } - const action = await dispatch( + const action = dispatch( createInfrastructureMonitor({ authToken, monitor: generatePayload(form) }) ); if (action.meta.requestStatus === "fulfilled") { @@ -372,7 +374,7 @@ const CreateInfrastructureMonitor = () => { onBlur={handleBlur} alertUnit="%" /> - {/* { onChange={handleChange} onBlur={handleBlur} alertUnit="%" - /> */} + /> {/* { label="Check frequency" value={infrastructureMonitor.interval || 15} onChange={(e) => handleChange(e, "interval")} - onBlur={handleBlur} + onBlur={(e) => handleBlur(e, "interval")} items={frequencies} /> {/* { "dbConnectionString", "refreshTokenTTL", "jwtTTL", + "notify-email-list", ].includes(err.path[0]) ) { newErrors[err.path[0]] = err.message ?? "Validation error"; } + // Handle conditionally usage number required cases if (!form.cpu || (form.cpu && form.usage_cpu)) { delete newErrors["usage_cpu"]; - } + } + if (!form.memory || (form.memory && form.usage_memory)) { + delete newErrors["usage_memory"]; + } + if (!form.disk || (form.disk && form.usage_disk)) { + delete newErrors["usage_disk"]; + } }); if (Object.keys(newErrors).length > 0) { setErrors(newErrors); diff --git a/Client/src/Validation/validation.js b/Client/src/Validation/validation.js index fb0a436c1..83e585bd9 100644 --- a/Client/src/Validation/validation.js +++ b/Client/src/Validation/validation.js @@ -187,8 +187,16 @@ const infrastractureMonitorValidation = joi.object({ "any.required": "CPU threshold is required.", }), cpu:joi.boolean(), - // usage_memory: joi.number(), - // usage_disk: joi.number(), + memory:joi.boolean(), + disk:joi.boolean(), + usage_memory: joi.number().messages({ + "number.base": "Memory threshold must be a number.", + "any.required": "Memory threshold is required.", + }), + usage_disk: joi.number().messages({ + "number.base": "Disk threshold must be a number.", + "any.required": "Disk threshold is required.", + }), // usage_temperature: joi.number().messages({ // "number.base": "Temperature must be a number.", // }),