diff --git a/packages/web/src/components/ChooseAppAndEventSubstep/index.tsx b/packages/web/src/components/ChooseAppAndEventSubstep/index.tsx index 534e2f19..ae90cf77 100644 --- a/packages/web/src/components/ChooseAppAndEventSubstep/index.tsx +++ b/packages/web/src/components/ChooseAppAndEventSubstep/index.tsx @@ -80,7 +80,7 @@ function ChooseAppAndEventSubstep( const app = apps?.find((currentApp: IApp) => currentApp.key === step.appKey); const appOptions = React.useMemo( - () => apps?.map((app) => optionGenerator(app)), + () => apps?.map((app) => optionGenerator(app)) || [], [apps] ); const actionsOrTriggers: Array = @@ -167,7 +167,7 @@ function ChooseAppAndEventSubstep( ( @@ -176,7 +176,7 @@ function ChooseAppAndEventSubstep( label={formatMessage('flowEditor.chooseApp')} /> )} - value={getOption(appOptions, step.appKey)} + value={getOption(appOptions, step.appKey) || null} onChange={onAppChange} data-test="choose-app-autocomplete" /> @@ -191,7 +191,9 @@ function ChooseAppAndEventSubstep( ( @@ -235,7 +237,7 @@ function ChooseAppAndEventSubstep( )} )} - value={getOption(actionOrTriggerOptions, step.key)} + value={getOption(actionOrTriggerOptions, step.key) || null} onChange={onEventChange} data-test="choose-event-autocomplete" /> diff --git a/packages/web/src/components/ControlledCustomAutocomplete/index.tsx b/packages/web/src/components/ControlledCustomAutocomplete/index.tsx index 42a352f9..22cca39c 100644 --- a/packages/web/src/components/ControlledCustomAutocomplete/index.tsx +++ b/packages/web/src/components/ControlledCustomAutocomplete/index.tsx @@ -255,7 +255,7 @@ function ControlledCustomAutocomplete( /> - {isSingleChoice && serialize(editor.children) && ( + {isSingleChoice && serialize(editor.children) !== '' && ( )} - {(additionalFieldsLoading && !additionalFields?.length) &&
- -
} + {additionalFieldsLoading && !additionalFields?.length && ( +
+ +
+ )} {additionalFields?.map((field) => ( - {(additionalFieldsLoading && !additionalFields?.length) &&
- -
} + {additionalFieldsLoading && !additionalFields?.length && ( +
+ +
+ )} {additionalFields?.map((field) => ( - {(additionalFieldsLoading && !additionalFields?.length) &&
- -
} + {additionalFieldsLoading && !additionalFields?.length && ( +
+ +
+ )} {additionalFields?.map((field) => ( { - if (!value) - return [ - { - type: 'paragraph', - children: [{ text: '' }], - }, - ]; - - const selectedNativeOption = options.find((option) => value === option.value); + const selectedNativeOption = options?.find( + (option) => value === option.value + ); if (selectedNativeOption) { return [ @@ -116,43 +110,54 @@ export const deserialize = ( ]; } - return value.split('\n').map((line) => { - const nodes = line.split(variableRegExp); - - if (nodes.length > 1) { - return { + if (value === null || value === undefined || value === '') + return [ + { type: 'paragraph', - children: nodes.map((node) => { - if (node.match(variableRegExp)) { - const variableDetails = getVariableDetails( - node, - stepsWithVariables - ); + children: [{ text: '' }], + }, + ]; + + return value + .toString() + .split('\n') + .map((line) => { + const nodes = line.split(variableRegExp); + + if (nodes.length > 1) { + return { + type: 'paragraph', + children: nodes.map((node) => { + if (node.match(variableRegExp)) { + const variableDetails = getVariableDetails( + node, + stepsWithVariables + ); + + return { + type: 'variable', + name: variableDetails.label, + sampleValue: variableDetails.sampleValue, + value: node, + children: [{ text: '' }], + }; + } return { - type: 'variable', - name: variableDetails.label, - sampleValue: variableDetails.sampleValue, - value: node, - children: [{ text: '' }], + text: node, }; - } + }), + }; + } - return { - text: node, - }; - }), + return { + type: 'paragraph', + children: [{ text: line }], }; - } - - return { - type: 'paragraph', - children: [{ text: line }], - }; - }); + }); }; -export const serialize = (value: Descendant[]): string => { +export const serialize = (value: Descendant[]): string | number | null => { const serializedNodes = value.map((node) => serializeNode(node)); const hasSingleNode = value.length === 1; @@ -169,8 +174,12 @@ export const serialize = (value: Descendant[]): string => { return serializedValue; }; -const serializeNode = (node: CustomElement | Descendant): string => { - if (isCustomText(node)) return node.value; +const serializeNode = ( + node: CustomElement | Descendant +): string | number | null => { + if (isCustomText(node)) { + return node.value; + } if (Text.isText(node)) { return node.text; diff --git a/packages/web/src/hooks/useDynamicFields.ts b/packages/web/src/hooks/useDynamicFields.ts index b6b8f855..fbbf1697 100644 --- a/packages/web/src/hooks/useDynamicFields.ts +++ b/packages/web/src/hooks/useDynamicFields.ts @@ -27,7 +27,7 @@ function computeArguments( const sanitizedFieldPath = value.replace(/{|}/g, ''); const computedValue = getValues(sanitizedFieldPath); - if (computedValue === undefined) + if (computedValue === undefined || computedValue === '') throw new Error(`The ${sanitizedFieldPath} field is required.`); set(result, name, computedValue);