feat: Add assignment component with drag and drop to Set node (#8283)

Co-authored-by: Giulio Andreini <andreini@netseven.it>
This commit is contained in:
Elias Meire
2024-02-06 18:34:34 +01:00
committed by GitHub
parent c04f92f7fd
commit 2799de491b
53 changed files with 3296 additions and 1060 deletions

View File

@@ -1,4 +1,6 @@
import type {
AssignmentCollectionValue,
FieldType,
IDataObject,
IExecuteFunctions,
INode,
@@ -23,6 +25,11 @@ const properties: INodeProperties[] = [
placeholder: 'Add Field',
type: 'fixedCollection',
description: 'Edit existing fields or add new ones to modify the output data',
displayOptions: {
show: {
'@version': [3, 3.1, 3.2],
},
},
typeOptions: {
multipleValues: true,
sortable: true,
@@ -156,6 +163,17 @@ const properties: INodeProperties[] = [
},
],
},
{
displayName: 'Fields to Set',
name: 'assignments',
type: 'assignmentCollection',
displayOptions: {
hide: {
'@version': [3, 3.1, 3.2],
},
},
default: {},
},
];
const displayOptions = {
@@ -175,35 +193,60 @@ export async function execute(
node: INode,
) {
try {
const fields = this.getNodeParameter('fields.values', i, []) as SetField[];
if (node.typeVersion < 3.3) {
const fields = this.getNodeParameter('fields.values', i, []) as SetField[];
const newData: IDataObject = {};
const newData: IDataObject = {};
for (const entry of fields) {
if (
entry.type === 'objectValue' &&
rawFieldsData[entry.name] !== undefined &&
entry.objectValue !== undefined &&
entry.objectValue !== null
) {
entry.objectValue = parseJsonParameter(
resolveRawData.call(this, rawFieldsData[entry.name] as string, i),
for (const entry of fields) {
if (
entry.type === 'objectValue' &&
rawFieldsData[entry.name] !== undefined &&
entry.objectValue !== undefined &&
entry.objectValue !== null
) {
entry.objectValue = parseJsonParameter(
resolveRawData.call(this, rawFieldsData[entry.name] as string, i),
node,
i,
entry.name,
);
}
const { name, value } = validateEntry(
entry.name,
entry.type.replace('Value', '') as FieldType,
entry[entry.type],
node,
i,
entry.name,
options.ignoreConversionErrors,
node.typeVersion,
);
newData[name] = value;
}
const { name, value } = validateEntry(
entry,
node,
i,
options.ignoreConversionErrors,
node.typeVersion,
);
newData[name] = value;
return composeReturnItem.call(this, i, item, newData, options);
}
const assignmentCollection = this.getNodeParameter(
'assignments',
i,
) as AssignmentCollectionValue;
const newData = Object.fromEntries(
(assignmentCollection?.assignments ?? []).map((assignment) => {
const { name, value } = validateEntry(
assignment.name,
assignment.type as FieldType,
assignment.value,
node,
i,
options.ignoreConversionErrors,
node.typeVersion,
);
return [name, value];
}),
);
return composeReturnItem.call(this, i, item, newData, options);
} catch (error) {
if (this.continueOnFail()) {