fix(editor): Allow switching a toggle parameter from expression to fixed (#32762)

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Ricardo Espinoza <ricardo@n8n.io>
This commit is contained in:
Nikhil Kuriakose 2026-09-09 07:12:13 +00:00 committed by GitHub
parent 0c82743a77
commit a0535781a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 4 deletions

View File

@ -399,6 +399,15 @@ describe('parseFromExpression', () => {
expect(parseFromExpression(true, undefined, 'boolean', false, [])).toBe(false);
});
it('returns defaultValue for number/boolean when expression resolves to null', () => {
// Unresolvable $fromAI() expressions resolve to null in the editor; falling back to
// the default (instead of null) is what lets the Fixed tab clear the expression.
expect(
parseFromExpression('={{ $fromAI("x", "", "boolean") }}', null, 'boolean', false, []),
).toBe(false);
expect(parseFromExpression('={{ $fromAI("x", "", "number") }}', null, 'number', 0, [])).toBe(0);
});
it('returns null for other types if value is undefined', () => {
expect(parseFromExpression({}, undefined, 'json', null, [])).toBeNull();
});

View File

@ -432,12 +432,13 @@ export function parseFromExpression(
return currentParameterValue ? currentParameterValue.replace(/^=+/, '') : null;
}
if (typeof evaluatedExpressionValue !== 'undefined') {
return evaluatedExpressionValue;
// Fall back to default when the expression can't resolve (e.g. $fromAI() -> null); `??` keeps a real `false`/`0`.
if (['number', 'boolean'].includes(parameterType)) {
return evaluatedExpressionValue ?? defaultValue;
}
if (['number', 'boolean'].includes(parameterType)) {
return defaultValue;
if (typeof evaluatedExpressionValue !== 'undefined') {
return evaluatedExpressionValue;
}
return null;