fix(core): Properly resolve expressions in declarative node design

This commit is contained in:
Jan Oberhauser 2022-06-08 18:16:55 +02:00
parent 481ccc7647
commit 1999f4b066
2 changed files with 71 additions and 2 deletions

View file

@ -564,7 +564,10 @@ export class RoutingNode {
additionalKeys?: IWorkflowDataProxyAdditionalKeys, additionalKeys?: IWorkflowDataProxyAdditionalKeys,
returnObjectAsString = false, returnObjectAsString = false,
): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | string { ): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | string {
if (typeof parameterValue === 'string' && parameterValue.charAt(0) === '=') { if (
typeof parameterValue === 'object' ||
(typeof parameterValue === 'string' && parameterValue.charAt(0) === '=')
) {
return this.workflow.expression.getParameterValue( return this.workflow.expression.getParameterValue(
parameterValue, parameterValue,
this.runExecutionData ?? null, this.runExecutionData ?? null,
@ -820,8 +823,18 @@ export class RoutingNode {
value = [value]; value = [value];
} }
// Resolve expressions
value = this.getParameterValue(
value as INodeParameters[],
itemIndex,
runIndex,
executeSingleFunctions.getExecuteData(),
{ ...additionalKeys },
false,
) as INodeParameters[];
const loopBasePath = `${basePath}${propertyOptions.name}`; const loopBasePath = `${basePath}${propertyOptions.name}`;
for (let i = 0; i < (value as INodeParameters[]).length; i++) { for (let i = 0; i < value.length; i++) {
for (const option of propertyOptions.values) { for (const option of propertyOptions.values) {
const tempOptions = this.getRequestOptionsFromParameters( const tempOptions = this.getRequestOptionsFromParameters(
executeSingleFunctions, executeSingleFunctions,

View file

@ -961,6 +961,7 @@ describe('RoutingNode', () => {
input: { input: {
node: { node: {
parameters: { parameters: {
value1: '={{"test"}}',
multipleFields: { multipleFields: {
value1: 'v1', value1: 'v1',
value2: 'v2', value2: 'v2',
@ -998,11 +999,25 @@ describe('RoutingNode', () => {
}, },
], ],
}, },
customPropertiesMultiExp: {
property0: [
{
name: '={{$parameter["value1"]}}N',
value: '={{$parameter["value1"]}}V',
},
],
},
}, },
}, },
}, },
nodeType: { nodeType: {
properties: [ properties: [
{
displayName: 'Value 1',
name: 'value1',
type: 'string',
default: '',
},
{ {
displayName: 'Multiple Fields', displayName: 'Multiple Fields',
name: 'multipleFields', name: 'multipleFields',
@ -1285,6 +1300,46 @@ describe('RoutingNode', () => {
}, },
], ],
}, },
// Test fixed collection: multipleValues=true with expression which references an expression
{
displayName: 'Custom Properties (multi)',
name: 'customPropertiesMultiExp',
placeholder: 'Add Custom Property',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
default: {},
options: [
{
name: 'property0',
displayName: 'Property0',
values: [
// To set: { name0: 'value0', name1: 'value1' }
{
displayName: 'Property Name',
name: 'name',
type: 'string',
default: '',
description: 'Name of the property to set.',
},
{
displayName: 'Property Value',
name: 'value',
type: 'string',
default: '',
routing: {
send: {
property: '={{$parent.name}}',
type: 'body',
},
},
description: 'Value of the property to set.',
},
],
},
],
},
], ],
}, },
], ],
@ -1324,6 +1379,7 @@ describe('RoutingNode', () => {
value: 'cM1Value2', value: 'cM1Value2',
}, },
], ],
testN: 'testV',
}, },
method: 'POST', method: 'POST',
headers: { headers: {