From ef26a4bfe5690d0f9531e09a0104dba01ec5a748 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Sun, 12 Apr 2020 12:28:36 +0200 Subject: [PATCH] :zap: Small improvement to Cockpit-Node --- .../nodes/Cockpit/CollectionDescription.ts | 29 ++++++++++--------- .../nodes/Cockpit/CollectionFunctions.ts | 11 ++++++- .../nodes/Cockpit/FormDescription.ts | 10 +++---- .../nodes/Cockpit/SingletonDescription.ts | 2 +- 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/packages/nodes-base/nodes/Cockpit/CollectionDescription.ts b/packages/nodes-base/nodes/Cockpit/CollectionDescription.ts index 24873a3c87..92420c2570 100644 --- a/packages/nodes-base/nodes/Cockpit/CollectionDescription.ts +++ b/packages/nodes-base/nodes/Cockpit/CollectionDescription.ts @@ -14,17 +14,17 @@ export const collectionOperations = [ }, options: [ { - name: 'Create an entry', + name: 'Create an Entry', value: 'create', description: 'Create a collection entry', }, { - name: 'Get all entries', + name: 'Get all Entries', value: 'getAll', description: 'Get all collection entries', }, { - name: 'Update an entry', + name: 'Update an Entry', value: 'update', description: 'Update a collection entries', }, @@ -116,22 +116,24 @@ export const collectionFields = [ { displayName: 'Fields', name: 'fields', - type: 'json', + type: 'string', default: '', typeOptions: { alwaysOpenEditWindow: true, }, - description: 'Fields to get.', + placeholder: '_id,name', + description: 'Comma separated list of fields to get.', }, { - displayName: 'Filter', + displayName: 'Filter Query', name: 'filter', type: 'json', default: '', typeOptions: { alwaysOpenEditWindow: true, }, - description: 'Filter result by fields.', + placeholder: '{"name": "Jim"}', + description: 'Filter query in Mongolite format.', }, { displayName: 'Language', @@ -163,11 +165,12 @@ export const collectionFields = [ description: 'Skip number of entries.', }, { - displayName: 'Sort', + displayName: 'Sort Query', name: 'sort', type: 'json', default: '', - description: 'Sort result by fields.', + placeholder: '{"price": -1}', + description: 'Sort query in Mongolite format.', }, ], }, @@ -213,7 +216,7 @@ export const collectionFields = [ description: 'If new entry fields should be set via the value-key pair UI or JSON.', }, { - displayName: 'Data fields', + displayName: 'Entry Data', name: 'dataFieldsJson', type: 'json', default: '', @@ -234,10 +237,10 @@ export const collectionFields = [ ] }, }, - description: 'Data to send as JSON.', + description: 'Entry data to send as JSON.', }, { - displayName: 'Data fields', + displayName: 'Entry Data', name: 'dataFieldsUi', type: 'fixedCollection', typeOptions: { @@ -280,6 +283,6 @@ export const collectionFields = [ ], }, ], - description: 'Data field to send.', + description: 'Entry data to send.', }, ] as INodeProperties[]; diff --git a/packages/nodes-base/nodes/Cockpit/CollectionFunctions.ts b/packages/nodes-base/nodes/Cockpit/CollectionFunctions.ts index 344b483407..d508629840 100644 --- a/packages/nodes-base/nodes/Cockpit/CollectionFunctions.ts +++ b/packages/nodes-base/nodes/Cockpit/CollectionFunctions.ts @@ -27,7 +27,16 @@ export async function getAllCollectionEntries(this: IExecuteFunctions | IExecute const body: ICollection = {}; if (options.fields) { - body.fields = JSON.parse(options.fields.toString()); + const fields = (options.fields as string).split(',').map(field => field.trim() ); + + const bodyFields = { + _id: false, + } as IDataObject; + for (const field of fields) { + bodyFields[field] = true; + } + + body.fields = bodyFields; } if (options.filter) { diff --git a/packages/nodes-base/nodes/Cockpit/FormDescription.ts b/packages/nodes-base/nodes/Cockpit/FormDescription.ts index 78f77ba548..66a5c052ec 100644 --- a/packages/nodes-base/nodes/Cockpit/FormDescription.ts +++ b/packages/nodes-base/nodes/Cockpit/FormDescription.ts @@ -14,7 +14,7 @@ export const formOperations = [ }, options: [ { - name: 'Submit a form', + name: 'Submit a Form', value: 'submit', description: 'Store submission of a form', }, @@ -61,7 +61,7 @@ export const formFields = [ description: 'If form fields should be set via the value-key pair UI or JSON.', }, { - displayName: 'Form fields', + displayName: 'Form Data', name: 'dataFieldsJson', type: 'json', default: '', @@ -81,10 +81,10 @@ export const formFields = [ ] }, }, - description: 'Form to send as JSON.', + description: 'Form data to send as JSON.', }, { - displayName: 'Data fields', + displayName: 'Form Data', name: 'dataFieldsUi', type: 'fixedCollection', typeOptions: { @@ -126,6 +126,6 @@ export const formFields = [ ], }, ], - description: 'Form field to send.', + description: 'Form data to send.', }, ] as INodeProperties[]; diff --git a/packages/nodes-base/nodes/Cockpit/SingletonDescription.ts b/packages/nodes-base/nodes/Cockpit/SingletonDescription.ts index e9774b4f5f..98df8a03d9 100644 --- a/packages/nodes-base/nodes/Cockpit/SingletonDescription.ts +++ b/packages/nodes-base/nodes/Cockpit/SingletonDescription.ts @@ -16,7 +16,7 @@ export const singletonOperations = [ { name: 'Get', value: 'get', - description: 'Gets a singleton', + description: 'Gets a Singleton', }, ], default: 'get',