diff --git a/packages/nodes-base/nodes/Cockpit/CollectionDescription.ts b/packages/nodes-base/nodes/Cockpit/CollectionDescription.ts index e448ce670e..24873a3c87 100644 --- a/packages/nodes-base/nodes/Cockpit/CollectionDescription.ts +++ b/packages/nodes-base/nodes/Cockpit/CollectionDescription.ts @@ -54,29 +54,6 @@ export const collectionFields = [ description: 'Name of the collection to operate on.' }, - // Collection:entry:create - { - displayName: 'Data', - name: 'data', - type: 'json', - required: true, - default: '', - typeOptions: { - alwaysOpenEditWindow: true, - }, - displayOptions: { - show: { - resource: [ - 'collection', - ], - operation: [ - 'create', - ] - }, - }, - description: 'The data to create.', - }, - // Collection:entry:getAll { displayName: 'Return All', @@ -214,25 +191,95 @@ export const collectionFields = [ }, description: 'The entry ID.', }, + + // Collection:entry:create + // Collection:entry:update { - displayName: 'Data', - name: 'data', - type: 'json', - required: true, - default: '', - typeOptions: { - alwaysOpenEditWindow: true, - }, + displayName: 'JSON Data fields', + name: 'jsonDataFields', + type: 'boolean', + default: false, displayOptions: { show: { resource: [ 'collection', ], operation: [ + 'create', 'update', ] }, }, - description: 'The data to update.', + description: 'If new entry fields should be set via the value-key pair UI or JSON.', + }, + { + displayName: 'Data fields', + name: 'dataFieldsJson', + type: 'json', + default: '', + typeOptions: { + alwaysOpenEditWindow: true, + }, + displayOptions: { + show: { + jsonDataFields: [ + true, + ], + resource: [ + 'collection', + ], + operation: [ + 'create', + 'update', + ] + }, + }, + description: 'Data to send as JSON.', + }, + { + displayName: 'Data fields', + name: 'dataFieldsUi', + type: 'fixedCollection', + typeOptions: { + multipleValues: true, + }, + default: {}, + displayOptions: { + show: { + jsonDataFields: [ + false, + ], + resource: [ + 'collection', + ], + operation: [ + 'create', + 'update', + ] + }, + }, + options: [ + { + displayName: 'Field', + name: 'field', + values: [ + { + displayName: 'Name', + name: 'name', + type: 'string', + default: '', + description: 'Name of the field.', + }, + { + displayName: 'Value', + name: 'value', + type: 'string', + default: '', + description: 'Value of the field.', + }, + ], + }, + ], + description: 'Data field to send.', }, ] as INodeProperties[]; diff --git a/packages/nodes-base/nodes/Cockpit/CollectionFunctions.ts b/packages/nodes-base/nodes/Cockpit/CollectionFunctions.ts index 4a2c640f84..344b483407 100644 --- a/packages/nodes-base/nodes/Cockpit/CollectionFunctions.ts +++ b/packages/nodes-base/nodes/Cockpit/CollectionFunctions.ts @@ -9,7 +9,7 @@ import { cockpitApiRequest } from './GenericFunctions'; export async function createCollectionEntry(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, resourceName: string, data: IDataObject, id?: string): Promise { // tslint:disable-line:no-any const body: ICollection = { - data: JSON.parse(data.toString()) + data, }; if (id) {