From 9ce5fc5fd89044bf99929488e7b06709efb439c1 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 5 Sep 2024 11:34:37 +0200 Subject: [PATCH] B OpenNebula/one#6707: Boolean default values on user inputs (#3215) Signed-off-by: dcarracedo (cherry picked from commit 4a1abef990d9c970e8c07fe9b15202060d1b96d7) --- .../Steps/Extra/customAttributes/schema.js | 21 ++++++++++++++----- .../Steps/UserInputs/schema.js | 11 ++++++++-- src/fireedge/src/client/utils/schema.js | 2 +- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/fireedge/src/client/components/Forms/ServiceTemplate/CreateForm/Steps/Extra/customAttributes/schema.js b/src/fireedge/src/client/components/Forms/ServiceTemplate/CreateForm/Steps/Extra/customAttributes/schema.js index ae8c88ed04..86c28b676f 100644 --- a/src/fireedge/src/client/components/Forms/ServiceTemplate/CreateForm/Steps/Extra/customAttributes/schema.js +++ b/src/fireedge/src/client/components/Forms/ServiceTemplate/CreateForm/Steps/Extra/customAttributes/schema.js @@ -115,15 +115,25 @@ const DEFAULT_VALUE_TEXT = { name: 'defaultvalue', label: T.DefaultValue, dependOf: CA_TYPE.name, - - htmlType: (type) => type === CA_TYPES.password && INPUT_TYPES.HIDDEN, - + htmlType: (type) => + (type === CA_TYPES.password || type === CA_TYPES.boolean) && + INPUT_TYPES.HIDDEN, type: getTypeProp, - fieldProps: getFieldProps, - validation: string(), + grid: { sm: 2.5, md: 2.5 }, +} +const DEFAULT_VALUE_BOOLEAN = { + name: 'defaultvalue', + label: T.DefaultValue, + dependOf: CA_TYPE.name, + type: INPUT_TYPES.AUTOCOMPLETE, + htmlType: (type) => ![CA_TYPES.boolean].includes(type) && INPUT_TYPES.HIDDEN, + optionsOnly: true, + values: () => arrayToOptions(['NO', 'YES']), + fieldProps: getFieldProps, + validation: string(), grid: { sm: 2.5, md: 2.5 }, } @@ -184,6 +194,7 @@ export const CUSTOM_ATTRIBUTES_FIELDS = [ NAME, DESCRIPTION, DEFAULT_VALUE_TEXT, + DEFAULT_VALUE_BOOLEAN, MANDATORY, DEFAULT_VALUE_RANGE_MIN, DEFAULT_VALUE_RANGE_MAX, diff --git a/src/fireedge/src/client/components/Forms/ServiceTemplate/InstantiateForm/Steps/UserInputs/schema.js b/src/fireedge/src/client/components/Forms/ServiceTemplate/InstantiateForm/Steps/UserInputs/schema.js index b551b417bd..04a4a1e5cc 100644 --- a/src/fireedge/src/client/components/Forms/ServiceTemplate/InstantiateForm/Steps/UserInputs/schema.js +++ b/src/fireedge/src/client/components/Forms/ServiceTemplate/InstantiateForm/Steps/UserInputs/schema.js @@ -15,6 +15,7 @@ * ------------------------------------------------------------------------- */ import { string, boolean, number } from 'yup' import { INPUT_TYPES } from 'client/constants' +import { stringToBoolean } from 'client/models/Helper' const getTypeProp = (type) => { switch (type) { @@ -71,8 +72,14 @@ const getValidation = (type, mandatory, defaultValue = undefined) => { .default(() => defaultValue) case 'boolean': return isMandatory - ? boolean().yesOrNo().required() - : boolean().yesOrNo().notRequired() + ? boolean() + .yesOrNo() + .required() + .default(() => stringToBoolean(defaultValue)) + : boolean() + .yesOrNo() + .notRequired() + .default(() => stringToBoolean(defaultValue)) default: return isMandatory ? string() diff --git a/src/fireedge/src/client/utils/schema.js b/src/fireedge/src/client/utils/schema.js index 7ebaa4ac00..34b69baa31 100644 --- a/src/fireedge/src/client/utils/schema.js +++ b/src/fireedge/src/client/utils/schema.js @@ -326,7 +326,7 @@ export const schemaUserInput = ({ } case USER_INPUT_TYPES.boolean: return { - type: INPUT_TYPES.CHECKBOX, + type: INPUT_TYPES.SWITCH, validation: boolean() .concat(requiredSchema(mandatory, boolean())) .default(() => stringToBoolean(defaultValue))