Skip to content

Commit

Permalink
B #6707: Boolean default values on user inputs (#3215)
Browse files Browse the repository at this point in the history
Signed-off-by: dcarracedo <[email protected]>
  • Loading branch information
dcarracedo authored Sep 5, 2024
1 parent ccc8ccf commit 4a1abef
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
}

Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/fireedge/src/client/utils/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 4a1abef

Please sign in to comment.