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:
Mutasem Aldmour
2023-01-30 14:42:08 +03:00
committed by GitHub
parent 5b9c650e55
commit 6092f6c41e
14 changed files with 679 additions and 66 deletions

View File

@@ -170,6 +170,7 @@ import { mapStores } from 'pinia';
import { useWorkflowsStore } from '@/stores/workflows';
import { useNDVStore } from '@/stores/ndv';
import MappingPill from './MappingPill.vue';
import { getMappedExpression } from '@/utils/mappingUtils';
const MAX_COLUMNS_LIMIT = 40;
@@ -315,11 +316,11 @@ export default mixins(externalHooks).extend({
return '';
}
if (this.distanceFromActive === 1) {
return `{{ $json["${column}"] }}`;
}
return `{{ $node["${this.node.name}"].json["${column}"] }}`;
return getMappedExpression({
nodeName: this.node.name,
distanceFromActive: this.distanceFromActive,
path: [column],
});
},
getPathNameFromTarget(el: HTMLElement) {
if (!el) {
@@ -343,21 +344,12 @@ export default mixins(externalHooks).extend({
if (!this.node) {
return '';
}
const expr = path.reduce((accu: string, key: string | number) => {
if (typeof key === 'number') {
return `${accu}[${key}]`;
}
return `${accu}["${key}"]`;
}, '');
const column = this.tableData.columns[colIndex];
if (this.distanceFromActive === 1) {
return `{{ $json["${column}"]${expr} }}`;
}
return `{{ $node["${this.node.name}"].json["${column}"]${expr} }}`;
return getMappedExpression({
nodeName: this.node.name,
distanceFromActive: this.distanceFromActive,
path: [column, ...path],
});
},
isEmpty(value: unknown): boolean {
return (