From e07ea137087381d2ba09c07990395ecbfd4b8b21 Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Mon, 16 Dec 2019 11:40:44 -0500 Subject: [PATCH] :bug: fixes --- .../credentials/CodaApi.credentials.ts | 6 - packages/nodes-base/nodes/Coda/Coda.node.ts | 35 +- .../nodes-base/nodes/Coda/RowDescription.ts | 584 ++++++++++-------- 3 files changed, 351 insertions(+), 274 deletions(-) diff --git a/packages/nodes-base/credentials/CodaApi.credentials.ts b/packages/nodes-base/credentials/CodaApi.credentials.ts index c7e8befe4..226dd6ee6 100644 --- a/packages/nodes-base/credentials/CodaApi.credentials.ts +++ b/packages/nodes-base/credentials/CodaApi.credentials.ts @@ -7,12 +7,6 @@ export class CodaApi implements ICredentialType { name = 'codaApi'; displayName = 'Coda API'; properties = [ - { - displayName: 'Doc ID', - name: 'docId', - type: 'string' as NodePropertyTypes, - default: '', - }, { displayName: 'Access Token', name: 'accessToken', diff --git a/packages/nodes-base/nodes/Coda/Coda.node.ts b/packages/nodes-base/nodes/Coda/Coda.node.ts index 38110a228..4a54bf41c 100644 --- a/packages/nodes-base/nodes/Coda/Coda.node.ts +++ b/packages/nodes-base/nodes/Coda/Coda.node.ts @@ -63,24 +63,23 @@ export class Coda implements INodeType { methods = { loadOptions: { - // Get all the available tables to display them to user so that he can + // Get all the available docs to display them to user so that he can // select them easily - async getTables(this: ILoadOptionsFunctions): Promise { + async getDocs(this: ILoadOptionsFunctions): Promise { const returnData: INodePropertyOptions[] = []; - const credentials = this.getCredentials('codaApi'); const qs = {}; - let tables; + let docs; try { - tables = await codaApiRequestAllItems.call(this,'items', 'GET', `/docs/${credentials!.docId}/tables`, {}, qs); + docs = await codaApiRequestAllItems.call(this,'items', 'GET', `/docs`, {}, qs); } catch (err) { throw new Error(`Coda Error: ${err}`); } - for (const table of tables) { - const tableName = table.name; - const tableId = table.id; + for (const doc of docs) { + const docName = doc.name; + const docId = doc.id; returnData.push({ - name: tableName, - value: tableId, + name: docName, + value: docId, }); } return returnData; @@ -91,9 +90,6 @@ export class Coda implements INodeType { async execute(this: IExecuteFunctions): Promise { const returnData: IDataObject[] = []; const items = this.getInputData(); - const credentials = this.getCredentials('codaApi'); - const docId = credentials!.docId; - const length = items.length as unknown as number; let responseData; const qs: IDataObject = {}; const resource = this.getNodeParameter('resource', 0) as string; @@ -101,6 +97,7 @@ export class Coda implements INodeType { if (resource === 'row') { //https://coda.io/developers/apis/v1beta1#operation/upsertRows if (operation === 'create') { + const docId = this.getNodeParameter('docId', 0) as string; const tableId = this.getNodeParameter('tableId', 0) as string; const additionalFields = this.getNodeParameter('additionalFields', 0) as IDataObject; const endpoint = `/docs/${docId}/tables/${tableId}/rows`; @@ -119,6 +116,7 @@ export class Coda implements INodeType { } //https://coda.io/developers/apis/v1beta1#operation/getRow if (operation === 'get') { + const docId = this.getNodeParameter('docId', 0) as string; const tableId = this.getNodeParameter('tableId', 0) as string; const rowId = this.getNodeParameter('rowId', 0) as string; const filters = this.getNodeParameter('filters', 0) as IDataObject; @@ -137,6 +135,7 @@ export class Coda implements INodeType { } //https://coda.io/developers/apis/v1beta1#operation/listRows if (operation === 'getAll') { + const docId = this.getNodeParameter('docId', 0) as string; const returnAll = this.getNodeParameter('returnAll', 0) as boolean; const tableId = this.getNodeParameter('tableId', 0) as string; const filters = this.getNodeParameter('filters', 0) as IDataObject; @@ -167,13 +166,19 @@ export class Coda implements INodeType { } //https://coda.io/developers/apis/v1beta1#operation/deleteRows if (operation === 'delete') { + const docId = this.getNodeParameter('docId', 0) as string; const tableId = this.getNodeParameter('tableId', 0) as string; - const rowId = this.getNodeParameter('rowId', 0) as string; const body = {}; + let rowIds = ''; const endpoint = `/docs/${docId}/tables/${tableId}/rows`; + for (let i = 0; i < items.length; i++) { + const rowId = this.getNodeParameter('rowId', i) as string; + rowIds += rowId; + } + // @ts-ignore + body['rowIds'] = rowIds.split(',') as string[]; try { // @ts-ignore - body['rowIds'] = rowId.split(',') as string[]; responseData = await codaApiRequest.call(this, 'DELETE', endpoint, body, qs); } catch (err) { throw new Error(`Coda Error: ${err.message}`); diff --git a/packages/nodes-base/nodes/Coda/RowDescription.ts b/packages/nodes-base/nodes/Coda/RowDescription.ts index d9520266d..70529412e 100644 --- a/packages/nodes-base/nodes/Coda/RowDescription.ts +++ b/packages/nodes-base/nodes/Coda/RowDescription.ts @@ -45,12 +45,12 @@ export const rowFields = [ /* row:create */ /* -------------------------------------------------------------------------- */ { - displayName: 'Table', - name: 'tableId', + displayName: 'Doc', + name: 'docId', type: 'options', required: true, typeOptions: { - loadOptionsMethod: 'getTables', + loadOptionsMethod: 'getDocs', }, default: [], displayOptions: { @@ -63,7 +63,27 @@ export const rowFields = [ ] }, }, - description: 'Tables on document', + description: 'ID of the doc.', + }, + { + displayName: 'Table ID', + name: 'tableId', + type: 'string', + required: true, + default: [], + displayOptions: { + show: { + resource: [ + 'row', + ], + operation: [ + 'create' + ] + }, + }, + description: `ID or name of the table. Names are discouraged because
+ they're easily prone to being changed by users.
+ If you're using a name, be sure to URI-encode it.`, }, { displayName: 'Additional Fields', @@ -103,278 +123,336 @@ export const rowFields = [ /* -------------------------------------------------------------------------- */ /* row:get */ /* -------------------------------------------------------------------------- */ -{ - displayName: 'Table', - name: 'tableId', - type: 'options', - required: true, - typeOptions: { - loadOptionsMethod: 'getTables', + { + displayName: 'Doc', + name: 'docId', + type: 'options', + required: true, + typeOptions: { + loadOptionsMethod: 'getDocs', + }, + default: [], + displayOptions: { + show: { + resource: [ + 'row', + ], + operation: [ + 'get' + ] + }, + }, + description: 'ID of the doc.', }, - default: [], - displayOptions: { - show: { - resource: [ - 'row', - ], - operation: [ - 'get' - ] + { + displayName: 'Table ID', + name: 'tableId', + type: 'string', + required: true, + default: [], + displayOptions: { + show: { + resource: [ + 'row', + ], + operation: [ + 'get' + ] + }, }, + description: `ID or name of the table. Names are discouraged because
+ they're easily prone to being changed by users.
+ If you're using a name, be sure to URI-encode it.`, }, - description: 'Tables on document', -}, -{ - displayName: 'Row ID', - name: 'rowId', - type: 'string', - required: true, - default: '', - displayOptions: { - show: { - resource: [ - 'row', - ], - operation: [ - 'get' - ] + { + displayName: 'Row ID', + name: 'rowId', + type: 'string', + required: true, + default: '', + displayOptions: { + show: { + resource: [ + 'row', + ], + operation: [ + 'get' + ] + }, }, + description: `ID or name of the row. Names are discouraged because they're easily prone to being changed by users. + If you're using a name, be sure to URI-encode it. + If there are multiple rows with the same value in the identifying column, an arbitrary one will be selected`, }, - description: `ID or name of the row. Names are discouraged because they're easily prone to being changed by users. - If you're using a name, be sure to URI-encode it. - If there are multiple rows with the same value in the identifying column, an arbitrary one will be selected`, -}, -{ - displayName: 'Filters', - name: 'filters', - type: 'collection', - placeholder: 'Add Filter', - default: {}, - displayOptions: { - show: { - resource: [ - 'row', - ], - operation: [ - 'get', - ], + { + displayName: 'Filters', + name: 'filters', + type: 'collection', + placeholder: 'Add Filter', + default: {}, + displayOptions: { + show: { + resource: [ + 'row', + ], + operation: [ + 'get', + ], + }, }, + options: [ + { + displayName: 'Use Column Names', + name: 'useColumnNames', + type: 'boolean', + default: false, + description: `Use column names instead of column IDs in the returned output.
+ This is generally discouraged as it is fragile. If columns are renamed,
+ code using original names may throw errors.`, + }, + { + displayName: 'ValueFormat', + name: 'valueFormat', + type: 'options', + default: [], + options: [ + { + name: 'Simple', + value: 'simple', + }, + { + name: 'Simple With Arrays', + value: 'simpleWithArrays', + }, + { + name: 'Rich', + value: 'rich', + }, + ], + description: `The format that cell values are returned as.`, + }, + ] }, - options: [ - { - displayName: 'Use Column Names', - name: 'useColumnNames', - type: 'boolean', - default: false, - description: `Use column names instead of column IDs in the returned output.
- This is generally discouraged as it is fragile. If columns are renamed,
- code using original names may throw errors.`, - }, - { - displayName: 'ValueFormat', - name: 'valueFormat', - type: 'options', - default: [], - options: [ - { - name: 'Simple', - value: 'simple', - }, - { - name: 'Simple With Arrays', - value: 'simpleWithArrays', - }, - { - name: 'Rich', - value: 'rich', - }, - ], - description: `The format that cell values are returned as.`, - }, - ] -}, - /* -------------------------------------------------------------------------- */ /* get:all */ /* -------------------------------------------------------------------------- */ -{ - displayName: 'Table', - name: 'tableId', - type: 'options', - required: true, - typeOptions: { - loadOptionsMethod: 'getTables', + { + displayName: 'Doc', + name: 'docId', + type: 'options', + required: true, + typeOptions: { + loadOptionsMethod: 'getDocs', + }, + default: [], + displayOptions: { + show: { + resource: [ + 'row', + ], + operation: [ + 'getAll' + ] + }, + }, + description: 'ID of the doc.', }, - default: [], - displayOptions: { - show: { - resource: [ - 'row', - ], - operation: [ - 'getAll' - ] + { + displayName: 'Table ID', + name: 'tableId', + type: 'string', + required: true, + default: [], + displayOptions: { + show: { + resource: [ + 'row', + ], + operation: [ + 'getAll' + ] + }, }, + description: `ID or name of the table. Names are discouraged because
+ they're easily prone to being changed by users.
+ If you're using a name, be sure to URI-encode it.`, }, - description: 'Tables on document', -}, -{ - displayName: 'Return All', - name: 'returnAll', - type: 'boolean', - displayOptions: { - show: { - resource: [ - 'row', - ], - operation: [ - 'getAll' - ] + { + displayName: 'Return All', + name: 'returnAll', + type: 'boolean', + displayOptions: { + show: { + resource: [ + 'row', + ], + operation: [ + 'getAll' + ] + }, }, + default: false, + description: 'If all results should be returned or only up to a given limit.', }, - default: false, - description: 'If all results should be returned or only up to a given limit.', -}, -{ - displayName: 'Limit', - name: 'limit', - type: 'number', - displayOptions: { - show: { - resource: [ - 'row', - ], - operation: [ - 'getAll' - ], - returnAll: [ - false, - ], + { + displayName: 'Limit', + name: 'limit', + type: 'number', + displayOptions: { + show: { + resource: [ + 'row', + ], + operation: [ + 'getAll' + ], + returnAll: [ + false, + ], + }, }, + typeOptions: { + minValue: 1, + maxValue: 100, + }, + default: 50, + description: 'How many results to return.', }, - typeOptions: { - minValue: 1, - maxValue: 100, + { + displayName: 'Filters', + name: 'filters', + type: 'collection', + placeholder: 'Add Filter', + default: {}, + displayOptions: { + show: { + resource: [ + 'row', + ], + operation: [ + 'getAll', + ], + }, + }, + options: [ + { + displayName: 'Use Column Names', + name: 'useColumnNames', + type: 'boolean', + default: false, + description: `Use column names instead of column IDs in the returned output.
+ This is generally discouraged as it is fragile. If columns are renamed,
+ code using original names may throw errors.`, + }, + { + displayName: 'ValueFormat', + name: 'valueFormat', + type: 'options', + default: [], + options: [ + { + name: 'Simple', + value: 'simple', + }, + { + name: 'Simple With Arrays', + value: 'simpleWithArrays', + }, + { + name: 'Rich', + value: 'rich', + }, + ], + description: `The format that cell values are returned as.`, + }, + { + displayName: 'Sort By', + name: 'sortBy', + type: 'options', + default: [], + options: [ + { + name: 'Created At', + value: 'createdAt', + }, + { + name: 'Natural', + value: 'natural', + }, + ], + description: `Specifies the sort order of the rows returned. + If left unspecified, rows are returned by creation time ascending.`, + }, + { + displayName: 'Visible Only', + name: 'visibleOnly', + type: 'boolean', + default: false, + description: `If true, returns only visible rows and columns for the table.`, + }, + ] }, - default: 50, - description: 'How many results to return.', -}, -{ - displayName: 'Filters', - name: 'filters', - type: 'collection', - placeholder: 'Add Filter', - default: {}, - displayOptions: { - show: { - resource: [ - 'row', - ], - operation: [ - 'getAll', - ], - }, - }, - options: [ - { - displayName: 'Use Column Names', - name: 'useColumnNames', - type: 'boolean', - default: false, - description: `Use column names instead of column IDs in the returned output.
- This is generally discouraged as it is fragile. If columns are renamed,
- code using original names may throw errors.`, - }, - { - displayName: 'ValueFormat', - name: 'valueFormat', - type: 'options', - default: [], - options: [ - { - name: 'Simple', - value: 'simple', - }, - { - name: 'Simple With Arrays', - value: 'simpleWithArrays', - }, - { - name: 'Rich', - value: 'rich', - }, - ], - description: `The format that cell values are returned as.`, - }, - { - displayName: 'Sort By', - name: 'sortBy', - type: 'options', - default: [], - options: [ - { - name: 'Created At', - value: 'createdAt', - }, - { - name: 'Natural', - value: 'natural', - }, - ], - description: `Specifies the sort order of the rows returned. - If left unspecified, rows are returned by creation time ascending.`, - }, - { - displayName: 'Visible Only', - name: 'visibleOnly', - type: 'boolean', - default: false, - description: `If true, returns only visible rows and columns for the table.`, - }, - ] -}, - /* -------------------------------------------------------------------------- */ /* row:delete */ /* -------------------------------------------------------------------------- */ -{ - displayName: 'Table', - name: 'tableId', - type: 'options', - required: true, - typeOptions: { - loadOptionsMethod: 'getTables', - }, - default: [], - displayOptions: { - show: { - resource: [ - 'row', - ], - operation: [ - 'delete' - ] + { + displayName: 'Doc', + name: 'docId', + type: 'options', + required: true, + typeOptions: { + loadOptionsMethod: 'getDocs', }, - }, - description: 'Tables on document', -}, -{ - displayName: 'Row ID', - name: 'rowId', - type: 'string', - required: true, - default: '', - displayOptions: { - show: { - resource: [ - 'row', - ], - operation: [ - 'delete' - ] + default: [], + displayOptions: { + show: { + resource: [ + 'row', + ], + operation: [ + 'delete' + ] + }, }, + description: 'ID of the doc.', + }, + { + displayName: 'Table ID', + name: 'tableId', + type: 'string', + required: true, + default: [], + displayOptions: { + show: { + resource: [ + 'row', + ], + operation: [ + 'delete' + ] + }, + }, + description: `ID or name of the table. Names are discouraged because
+ they're easily prone to being changed by users.
+ If you're using a name, be sure to URI-encode it.`, + }, + { + displayName: 'Row ID', + name: 'rowId', + type: 'string', + required: true, + default: '', + displayOptions: { + show: { + resource: [ + 'row', + ], + operation: [ + 'delete' + ] + }, + }, + description: `Row IDs to delete separated by ,.`, }, - description: `Row IDs to delete separated by ,.`, -}, ] as INodeProperties[];