mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-20 11:22:15 +00:00
feat(editor): Add mapping support for data paths (#5191)
* feat: add data path flag * chore: update types * feat: use path for data * feat: add support for multiple values * fix: handle if not prev node * fix: update node * fix: handle multi part path * feat: add support for multiple vals for field * feat: add support for table transforms * feat: use dot notation * feat: fix bug where brackets removed * fix: handle dots, fix unit tests * test: update snapshot * test: fix tests * test: add test for edge case
This commit is contained in:
31
packages/editor-ui/src/utils/mappingUtils.ts
Normal file
31
packages/editor-ui/src/utils/mappingUtils.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
export function generatePath(root: string, path: Array<string | number>): string {
|
||||
return path.reduce((accu: string, part: string | number) => {
|
||||
if (typeof part === 'number') {
|
||||
return `${accu}[${part}]`;
|
||||
}
|
||||
|
||||
if (part.includes(' ') || part.includes('.')) {
|
||||
return `${accu}["${part}"]`;
|
||||
}
|
||||
|
||||
return `${accu}.${part}`;
|
||||
}, root);
|
||||
}
|
||||
|
||||
export function getMappedExpression({
|
||||
nodeName,
|
||||
distanceFromActive,
|
||||
path,
|
||||
}: {
|
||||
nodeName: string;
|
||||
distanceFromActive: number;
|
||||
path: Array<string | number> | string;
|
||||
}) {
|
||||
const root = distanceFromActive === 1 ? '$json' : generatePath('$node', [nodeName, 'json']);
|
||||
|
||||
if (typeof path === 'string') {
|
||||
return `{{ ${root}${path} }}`;
|
||||
}
|
||||
|
||||
return `{{ ${generatePath(root, path)} }}`;
|
||||
}
|
||||
Reference in New Issue
Block a user