fix(core): Fix issue with fixedCollection having all default values

This commit is contained in:
Jan Oberhauser 2022-05-15 19:28:42 +02:00
parent 03cdb1fea4
commit 7ced65484f
2 changed files with 331 additions and 0 deletions

View file

@ -720,6 +720,18 @@ export function getNodeParameters(
} }
} }
if (
!returnDefaults &&
nodeProperties.typeOptions?.multipleValues === false &&
propertyValues &&
Object.keys(propertyValues).length === 0
) {
// For fixedCollections, which only allow one value, it is important to still return
// the empty object which indicates that a value got added, even if it does not have
// anything set. If that is not done, the value would get lost.
return nodeValues;
}
// Iterate over all collections // Iterate over all collections
for (const itemName of Object.keys(propertyValues || {})) { for (const itemName of Object.keys(propertyValues || {})) {
if ( if (
@ -795,6 +807,25 @@ export function getNodeParameters(
} }
} }
if (
!returnDefaults &&
nodeProperties.typeOptions?.multipleValues === false &&
collectionValues &&
Object.keys(collectionValues).length === 0 &&
propertyValues &&
propertyValues?.constructor.name === 'Object' &&
Object.keys(propertyValues).length !== 0
) {
// For fixedCollections, which only allow one value, it is important to still return
// the object with an empty collection property which indicates that a value got added
// which contains all default values. If that is not done, the value would get lost.
const returnValue = {} as INodeParameters;
Object.keys(propertyValues || {}).forEach((value) => {
returnValue[value] = {};
});
return { [nodeProperties.name]: returnValue };
}
if (Object.keys(collectionValues).length !== 0 || returnDefaults) { if (Object.keys(collectionValues).length !== 0 || returnDefaults) {
// Set only if value got found // Set only if value got found
if (returnDefaults) { if (returnDefaults) {

View file

@ -3008,6 +3008,306 @@ describe('Workflow', () => {
}, },
}, },
}, },
{
description:
'complex type "collection" which contains a "fixedCollection" with "multipleValues: false" that has a collection value added but nothing to the fixedCollection',
input: {
nodePropertiesArray: [
{
displayName: 'Options',
name: 'options',
placeholder: 'Add Option',
type: 'collection',
default: {},
options: [
{
displayName: 'Sort',
name: 'sort',
type: 'fixedCollection',
typeOptions: {
multipleValues: false,
},
default: {},
placeholder: 'Add Sort',
options: [
{
displayName: 'Sort',
name: 'value',
values: [
{
displayName: 'Descending',
name: 'descending',
type: 'boolean',
default: true,
description: 'Sort by descending order',
},
{
displayName: 'Order By',
name: 'ordering',
type: 'options',
default: 'date',
options: [
{
name: 'Date',
value: 'date',
},
{
name: 'Name',
value: 'name',
},
],
},
],
},
],
},
],
},
],
nodeValues: {
options: {
sort: {},
},
},
},
output: {
noneDisplayedFalse: {
defaultsFalse: {
options: {
sort: {},
},
},
defaultsTrue: {
options: {
sort: {},
},
},
},
noneDisplayedTrue: {
defaultsFalse: {
options: {
sort: {},
},
},
defaultsTrue: {
options: {
sort: {},
},
},
},
},
},
{
description:
'complex type "collection" which contains a "fixedCollection" with "multipleValues: false" that has all values set to the default values (by having it as an empty object)',
input: {
nodePropertiesArray: [
{
displayName: 'Options',
name: 'options',
placeholder: 'Add Option',
type: 'collection',
default: {},
options: [
{
displayName: 'Sort',
name: 'sort',
type: 'fixedCollection',
typeOptions: {
multipleValues: false,
},
default: {},
placeholder: 'Add Sort',
options: [
{
displayName: 'Sort',
name: 'value',
values: [
{
displayName: 'Descending',
name: 'descending',
type: 'boolean',
default: true,
description: 'Sort by descending order',
},
{
displayName: 'Order By',
name: 'ordering',
type: 'options',
default: 'date',
options: [
{
name: 'Date',
value: 'date',
},
{
name: 'Name',
value: 'name',
},
],
},
],
},
],
},
],
},
],
nodeValues: {
options: {
sort: {
value: {},
},
},
},
},
output: {
noneDisplayedFalse: {
defaultsFalse: {
options: {
sort: {
value: {},
},
},
},
defaultsTrue: {
options: {
sort: {
value: {
descending: true,
ordering: 'date',
},
},
},
},
},
noneDisplayedTrue: {
defaultsFalse: {
options: {
sort: {
value: {},
},
},
},
defaultsTrue: {
options: {
sort: {
value: {
descending: true,
ordering: 'date',
},
},
},
},
},
},
},
{
description:
'complex type "collection" which contains a "fixedCollection" with "multipleValues: false" that has all values set to the default values (by having each value set)',
input: {
nodePropertiesArray: [
{
displayName: 'Options',
name: 'options',
placeholder: 'Add Option',
type: 'collection',
default: {},
options: [
{
displayName: 'Sort',
name: 'sort',
type: 'fixedCollection',
typeOptions: {
multipleValues: false,
},
default: {},
options: [
{
displayName: 'Sort',
name: 'value',
values: [
{
displayName: 'Descending',
name: 'descending',
type: 'boolean',
default: true,
},
{
displayName: 'Order By',
name: 'ordering',
type: 'options',
default: 'date',
options: [
{
name: 'Date',
value: 'date',
},
{
name: 'Name',
value: 'name',
},
],
},
],
},
],
},
],
},
],
nodeValues: {
options: {
sort: {
value: {
descending: true,
ordering: 'date',
},
},
},
},
},
output: {
noneDisplayedFalse: {
defaultsFalse: {
options: {
sort: {
value: {},
},
},
},
defaultsTrue: {
options: {
sort: {
value: {
descending: true,
ordering: 'date',
},
},
},
},
},
noneDisplayedTrue: {
defaultsFalse: {
options: {
sort: {
value: {},
},
},
},
defaultsTrue: {
options: {
sort: {
value: {
descending: true,
ordering: 'date',
},
},
},
},
},
},
},
]; ];
for (const testData of tests) { for (const testData of tests) {