- update safe checking for string util

- remove required for threshold in joi
-  refine if logic and update no error checking with values due to the change to set null instead of delete error entry
- move customthreshold component to under create infrastructure folder
- correct interval setting and threshold default value and fix typo
This commit is contained in:
Shemy Gan committed 2024-11-15 14:49:27 -05:00
1 parent c3859c7507
commit 2f8638cf04
5 files changed
+29 -24

No files matched your search

+4 -4
View File
@@ -28,17 +28,17 @@ const hasValidationErrors = (form, validation, setErrors) => {
newErrors[err.path[0]] = err.message ?? "Validation error";
}
// Handle conditionally usage number required cases
if (!form.cpu || (form.cpu && form.usage_cpu)) {
if (!form.cpu || form.usage_cpu) {
newErrors["usage_cpu"] = null;
}
if (!form.memory || (form.memory && form.usage_memory)) {
if (!form.memory || form.usage_memory) {
newErrors["usage_memory"] = null;
}
if (!form.disk || (form.disk && form.usage_disk)) {
if (!form.disk || form.usage_disk) {
newErrors["usage_disk"] = null;
}
});
if (Object.keys(newErrors).length > 0) {
if (Object.values(newErrors).some(v=> v)) {
setErrors(newErrors);
return true;
} else {
+2 -6
View File
@@ -1,7 +1,6 @@
import joi from "joi";
import dayjs from "dayjs";
const THRESHOLD_COMMON_MSG = "Threshold is required.";
const THRESHOLD_COMMON_BASE_MSG = "Threshold must be a number.";
const nameSchema = joi
@@ -176,7 +175,7 @@ const advancedSettingsValidation = joi.object({
pagespeedApiKey: joi.string().allow(""),
});
const infrastractureMonitorValidation = joi.object({
const infrastructureMonitorValidation = 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.",
@@ -187,18 +186,15 @@ const infrastractureMonitorValidation = joi.object({
secret: joi.string().trim().messages({ "string.empty": "This field is required." }),
usage_cpu: joi.number().messages({
"number.base": THRESHOLD_COMMON_BASE_MSG,
"any.required": THRESHOLD_COMMON_MSG,
}),
cpu: joi.boolean(),
memory: joi.boolean(),
disk: joi.boolean(),
usage_memory: joi.number().messages({
"number.base": THRESHOLD_COMMON_BASE_MSG,
"any.required": THRESHOLD_COMMON_MSG,
}),
usage_disk: joi.number().messages({
"number.base": THRESHOLD_COMMON_BASE_MSG,
"any.required": THRESHOLD_COMMON_MSG,
}),
// usage_temperature: joi.number().messages({
// "number.base": "Temperature must be a number.",
@@ -222,5 +218,5 @@ export {
settingsValidation,
maintenanceWindowValidation,
advancedSettingsValidation,
infrastractureMonitorValidation,
infrastructureMonitorValidation,
};