fix: consider null as value in step parameters (#1282)

This commit is contained in:
kattoczko
2023-09-29 16:33:45 +02:00
committed by GitHub
parent 108bd04cf8
commit c77e12edbb
5 changed files with 79 additions and 61 deletions

View File

@@ -80,7 +80,7 @@ function ChooseAppAndEventSubstep(
const app = apps?.find((currentApp: IApp) => currentApp.key === step.appKey); const app = apps?.find((currentApp: IApp) => currentApp.key === step.appKey);
const appOptions = React.useMemo( const appOptions = React.useMemo(
() => apps?.map((app) => optionGenerator(app)), () => apps?.map((app) => optionGenerator(app)) || [],
[apps] [apps]
); );
const actionsOrTriggers: Array<ITrigger | IAction> = const actionsOrTriggers: Array<ITrigger | IAction> =
@@ -167,7 +167,7 @@ function ChooseAppAndEventSubstep(
<Autocomplete <Autocomplete
fullWidth fullWidth
disablePortal disablePortal
disableClearable disableClearable={getOption(appOptions, step.appKey) !== undefined}
disabled={editorContext.readOnly} disabled={editorContext.readOnly}
options={appOptions} options={appOptions}
renderInput={(params) => ( renderInput={(params) => (
@@ -176,7 +176,7 @@ function ChooseAppAndEventSubstep(
label={formatMessage('flowEditor.chooseApp')} label={formatMessage('flowEditor.chooseApp')}
/> />
)} )}
value={getOption(appOptions, step.appKey)} value={getOption(appOptions, step.appKey) || null}
onChange={onAppChange} onChange={onAppChange}
data-test="choose-app-autocomplete" data-test="choose-app-autocomplete"
/> />
@@ -191,7 +191,9 @@ function ChooseAppAndEventSubstep(
<Autocomplete <Autocomplete
fullWidth fullWidth
disablePortal disablePortal
disableClearable disableClearable={
getOption(actionOrTriggerOptions, step.key) !== undefined
}
disabled={editorContext.readOnly} disabled={editorContext.readOnly}
options={actionOrTriggerOptions} options={actionOrTriggerOptions}
renderInput={(params) => ( renderInput={(params) => (
@@ -235,7 +237,7 @@ function ChooseAppAndEventSubstep(
)} )}
</li> </li>
)} )}
value={getOption(actionOrTriggerOptions, step.key)} value={getOption(actionOrTriggerOptions, step.key) || null}
onChange={onEventChange} onChange={onEventChange}
data-test="choose-event-autocomplete" data-test="choose-event-autocomplete"
/> />

View File

@@ -255,7 +255,7 @@ function ControlledCustomAutocomplete(
/> />
<ActionButtonsWrapper direction="row" mr={1.5}> <ActionButtonsWrapper direction="row" mr={1.5}>
{isSingleChoice && serialize(editor.children) && ( {isSingleChoice && serialize(editor.children) !== '' && (
<IconButton <IconButton
disabled={disabled} disabled={disabled}
edge="end" edge="end"

View File

@@ -55,10 +55,9 @@ export default function InputCreator(
} = schema; } = schema;
const { data, loading } = useDynamicData(stepId, schema); const { data, loading } = useDynamicData(stepId, schema);
const {
data: additionalFields, const { data: additionalFields, loading: additionalFieldsLoading } =
loading: additionalFieldsLoading useDynamicFields(stepId, schema);
} = useDynamicFields(stepId, schema);
const computedName = namePrefix ? `${namePrefix}.${name}` : name; const computedName = namePrefix ? `${namePrefix}.${name}` : name;
if (type === 'dynamic') { if (type === 'dynamic') {
@@ -121,9 +120,11 @@ export default function InputCreator(
/> />
)} )}
{(additionalFieldsLoading && !additionalFields?.length) && <div> {additionalFieldsLoading && !additionalFields?.length && (
<div>
<CircularProgress sx={{ display: 'block', margin: '20px auto' }} /> <CircularProgress sx={{ display: 'block', margin: '20px auto' }} />
</div>} </div>
)}
{additionalFields?.map((field) => ( {additionalFields?.map((field) => (
<InputCreator <InputCreator
@@ -154,9 +155,13 @@ export default function InputCreator(
shouldUnregister={shouldUnregister} shouldUnregister={shouldUnregister}
/> />
{(additionalFieldsLoading && !additionalFields?.length) && <div> {additionalFieldsLoading && !additionalFields?.length && (
<CircularProgress sx={{ display: 'block', margin: '20px auto' }} /> <div>
</div>} <CircularProgress
sx={{ display: 'block', margin: '20px auto' }}
/>
</div>
)}
{additionalFields?.map((field) => ( {additionalFields?.map((field) => (
<InputCreator <InputCreator
@@ -191,9 +196,11 @@ export default function InputCreator(
shouldUnregister={shouldUnregister} shouldUnregister={shouldUnregister}
/> />
{(additionalFieldsLoading && !additionalFields?.length) && <div> {additionalFieldsLoading && !additionalFields?.length && (
<div>
<CircularProgress sx={{ display: 'block', margin: '20px auto' }} /> <CircularProgress sx={{ display: 'block', margin: '20px auto' }} />
</div>} </div>
)}
{additionalFields?.map((field) => ( {additionalFields?.map((field) => (
<InputCreator <InputCreator

View File

@@ -92,19 +92,13 @@ const variableRegExp = /({{.*?}})/;
const stepIdRegExp = /^step.([\da-zA-Z-]*)/; const stepIdRegExp = /^step.([\da-zA-Z-]*)/;
export const deserialize = ( export const deserialize = (
value: string, value: boolean | string | number,
options: readonly IFieldDropdownOption[], options: readonly IFieldDropdownOption[],
stepsWithVariables: StepsWithVariables stepsWithVariables: StepsWithVariables
): Descendant[] => { ): Descendant[] => {
if (!value) const selectedNativeOption = options?.find(
return [ (option) => value === option.value
{ );
type: 'paragraph',
children: [{ text: '' }],
},
];
const selectedNativeOption = options.find((option) => value === option.value);
if (selectedNativeOption) { if (selectedNativeOption) {
return [ return [
@@ -116,7 +110,18 @@ export const deserialize = (
]; ];
} }
return value.split('\n').map((line) => { if (value === null || value === undefined || value === '')
return [
{
type: 'paragraph',
children: [{ text: '' }],
},
];
return value
.toString()
.split('\n')
.map((line) => {
const nodes = line.split(variableRegExp); const nodes = line.split(variableRegExp);
if (nodes.length > 1) { if (nodes.length > 1) {
@@ -152,7 +157,7 @@ export const deserialize = (
}); });
}; };
export const serialize = (value: Descendant[]): string => { export const serialize = (value: Descendant[]): string | number | null => {
const serializedNodes = value.map((node) => serializeNode(node)); const serializedNodes = value.map((node) => serializeNode(node));
const hasSingleNode = value.length === 1; const hasSingleNode = value.length === 1;
@@ -169,8 +174,12 @@ export const serialize = (value: Descendant[]): string => {
return serializedValue; return serializedValue;
}; };
const serializeNode = (node: CustomElement | Descendant): string => { const serializeNode = (
if (isCustomText(node)) return node.value; node: CustomElement | Descendant
): string | number | null => {
if (isCustomText(node)) {
return node.value;
}
if (Text.isText(node)) { if (Text.isText(node)) {
return node.text; return node.text;

View File

@@ -27,7 +27,7 @@ function computeArguments(
const sanitizedFieldPath = value.replace(/{|}/g, ''); const sanitizedFieldPath = value.replace(/{|}/g, '');
const computedValue = getValues(sanitizedFieldPath); const computedValue = getValues(sanitizedFieldPath);
if (computedValue === undefined) if (computedValue === undefined || computedValue === '')
throw new Error(`The ${sanitizedFieldPath} field is required.`); throw new Error(`The ${sanitizedFieldPath} field is required.`);
set(result, name, computedValue); set(result, name, computedValue);