mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
feat(editor): Support relative dependent parameters for collection NodeProperties (#18916)
This commit is contained in:
@@ -69,6 +69,7 @@ export * as ExpressionParser from './extensions/expression-parser';
|
||||
export { NativeMethods } from './native-methods';
|
||||
export * from './node-parameters/filter-parameter';
|
||||
export * from './node-parameters/parameter-type-validation';
|
||||
export * from './node-parameters/path-utils';
|
||||
export * from './evaluation-helpers';
|
||||
|
||||
export type {
|
||||
|
||||
24
packages/workflow/src/node-parameters/path-utils.ts
Normal file
24
packages/workflow/src/node-parameters/path-utils.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Resolve relative paths starting in & in the context of a given full path including parameters,
|
||||
* which will be dropped in the process.
|
||||
* If `candidateRelativePath` is not relative, it is returned unchanged.
|
||||
*
|
||||
* `parameters.a.b.c`, `&d` -> `a.b.d`
|
||||
* `parameters.a.b[0].c`, `&d` -> `a.b[0].d`
|
||||
* `parameters.a.b.c`, `d` -> `d`
|
||||
*/
|
||||
export function resolveRelativePath(
|
||||
fullPathWithParameters: string,
|
||||
candidateRelativePath: string,
|
||||
): string {
|
||||
if (candidateRelativePath.startsWith('&')) {
|
||||
const resolvedLeaf = candidateRelativePath.slice(1);
|
||||
const pathToLeaf = fullPathWithParameters.split('.').slice(1, -1).join('.');
|
||||
|
||||
if (!pathToLeaf) return resolvedLeaf;
|
||||
|
||||
return `${pathToLeaf}.${resolvedLeaf}`;
|
||||
}
|
||||
|
||||
return candidateRelativePath;
|
||||
}
|
||||
20
packages/workflow/test/node-parameters/path-utils.test.ts
Normal file
20
packages/workflow/test/node-parameters/path-utils.test.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { resolveRelativePath } from '../../src/node-parameters/path-utils';
|
||||
|
||||
describe('resolveRelativePath', () => {
|
||||
test.each([
|
||||
['parameters.level1.level2.field', '&childField', 'level1.level2.childField'],
|
||||
['parameters.level1.level2[0].field', '&childField', 'level1.level2[0].childField'],
|
||||
['parameters.level1.level2.field', 'absolute.path', 'absolute.path'],
|
||||
['parameters', '&childField', 'childField'],
|
||||
['parameters.level1.level2.field', '', ''],
|
||||
['', '&childField', 'childField'],
|
||||
['', '', ''],
|
||||
['parameters.level1.level2.field', 'relative.path', 'relative.path'],
|
||||
])(
|
||||
'should resolve relative path for fullPath: %s and candidateRelativePath: %s',
|
||||
(fullPath, candidateRelativePath, expected) => {
|
||||
const result = resolveRelativePath(fullPath, candidateRelativePath);
|
||||
expect(result).toBe(expected);
|
||||
},
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user