mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-26 05:04:05 -08:00
⚡ Make it possible to not use dot-notation with Set-Node
This commit is contained in:
parent
c1853a6ff5
commit
0ec6010a00
|
@ -1,5 +1,6 @@
|
||||||
import { IExecuteFunctions } from 'n8n-core';
|
import { IExecuteFunctions } from 'n8n-core';
|
||||||
import {
|
import {
|
||||||
|
IDataObject,
|
||||||
INodeExecutionData,
|
INodeExecutionData,
|
||||||
INodeParameters,
|
INodeParameters,
|
||||||
INodeType,
|
INodeType,
|
||||||
|
@ -103,6 +104,26 @@ export class Set implements INodeType {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
displayName: 'Options',
|
||||||
|
name: 'options',
|
||||||
|
type: 'collection',
|
||||||
|
placeholder: 'Add Option',
|
||||||
|
default: {},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
displayName: 'Dot Notation',
|
||||||
|
name: 'dotNotation',
|
||||||
|
type: 'boolean',
|
||||||
|
default: true,
|
||||||
|
description: `By default does dot-notation get used in property names..<br />
|
||||||
|
This means that "a.b" will set the property "b" underneath "a" so { "a": { "b": value} }.<br />
|
||||||
|
If that is not intended this can be deactivated, it will then set { "a.b": value } instead.
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -122,6 +143,7 @@ export class Set implements INodeType {
|
||||||
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
||||||
keepOnlySet = this.getNodeParameter('keepOnlySet', itemIndex, []) as boolean;
|
keepOnlySet = this.getNodeParameter('keepOnlySet', itemIndex, []) as boolean;
|
||||||
item = items[itemIndex];
|
item = items[itemIndex];
|
||||||
|
const options = this.getNodeParameter('options', itemIndex, {}) as IDataObject;
|
||||||
|
|
||||||
const newItem: INodeExecutionData = {
|
const newItem: INodeExecutionData = {
|
||||||
json: {},
|
json: {},
|
||||||
|
@ -141,17 +163,29 @@ export class Set implements INodeType {
|
||||||
|
|
||||||
// Add boolean values
|
// Add boolean values
|
||||||
(this.getNodeParameter('values.boolean', itemIndex, []) as INodeParameters[]).forEach((setItem) => {
|
(this.getNodeParameter('values.boolean', itemIndex, []) as INodeParameters[]).forEach((setItem) => {
|
||||||
|
if (options.dotNotation === false) {
|
||||||
|
newItem.json[setItem.name as string] = !!setItem.value;
|
||||||
|
} else {
|
||||||
set(newItem.json, setItem.name as string, !!setItem.value);
|
set(newItem.json, setItem.name as string, !!setItem.value);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add number values
|
// Add number values
|
||||||
(this.getNodeParameter('values.number', itemIndex, []) as INodeParameters[]).forEach((setItem) => {
|
(this.getNodeParameter('values.number', itemIndex, []) as INodeParameters[]).forEach((setItem) => {
|
||||||
|
if (options.dotNotation === false) {
|
||||||
|
newItem.json[setItem.name as string] = setItem.value;
|
||||||
|
} else {
|
||||||
set(newItem.json, setItem.name as string, setItem.value);
|
set(newItem.json, setItem.name as string, setItem.value);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add string values
|
// Add string values
|
||||||
(this.getNodeParameter('values.string', itemIndex, []) as INodeParameters[]).forEach((setItem) => {
|
(this.getNodeParameter('values.string', itemIndex, []) as INodeParameters[]).forEach((setItem) => {
|
||||||
|
if (options.dotNotation === false) {
|
||||||
|
newItem.json[setItem.name as string] = setItem.value;
|
||||||
|
} else {
|
||||||
set(newItem.json, setItem.name as string, setItem.value);
|
set(newItem.json, setItem.name as string, setItem.value);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
returnData.push(newItem);
|
returnData.push(newItem);
|
||||||
|
|
Loading…
Reference in a new issue