diff --git a/packages/nodes-base/nodes/Coda/Coda.node.ts b/packages/nodes-base/nodes/Coda/Coda.node.ts index d0274d1fb8..c731b92de8 100644 --- a/packages/nodes-base/nodes/Coda/Coda.node.ts +++ b/packages/nodes-base/nodes/Coda/Coda.node.ts @@ -105,6 +105,30 @@ export class Coda implements INodeType { } return returnData; }, + // Get all the available columns to display them to user so that he can + // select them easily + async getColumns(this: ILoadOptionsFunctions): Promise { + const returnData: INodePropertyOptions[] = []; + let columns; + + const docId = this.getCurrentNodeParameter('docId'); + const tableId = this.getCurrentNodeParameter('tableId'); + + try { + columns = await codaApiRequestAllItems.call(this, 'items', 'GET', `/docs/${docId}/tables/${tableId}/columns`, {}); + } catch (err) { + throw new Error(`Coda Error: ${err}`); + } + for (const column of columns) { + const columnName = column.name; + const columnId = column.id; + returnData.push({ + name: columnName, + value: columnId, + }); + } + return returnData; + }, }, }; @@ -217,6 +241,9 @@ export class Coda implements INodeType { if (options.visibleOnly) { qs.visibleOnly = options.visibleOnly as boolean; } + if (options.query) { + qs.query = options.query as string; + } try { if (returnAll === true) { responseData = await codaApiRequestAllItems.call(this, 'items', 'GET', endpoint, {}, qs); @@ -266,8 +293,21 @@ export class Coda implements INodeType { // Return the incoming data return [items]; } - } + // https://coda.io/developers/apis/v1beta1#operation/pushButton + if (operation === 'pushButton') { + for (let i = 0; i < items.length; i++) { + const docId = this.getNodeParameter('docId', i) as string; + const tableId = this.getNodeParameter('tableId', i) as string; + const rowId = this.getNodeParameter('rowId', i) as string; + const columnId = this.getNodeParameter('columnId', i) as string; + const endpoint = `/docs/${docId}/tables/${tableId}/rows/${rowId}/buttons/${columnId}`; + responseData = await codaApiRequest.call(this, 'POST', endpoint, {}); + returnData.push(responseData) + } + return [this.helpers.returnJsonArray(returnData)]; + } + } return []; } } diff --git a/packages/nodes-base/nodes/Coda/TableDescription.ts b/packages/nodes-base/nodes/Coda/TableDescription.ts index 647d92e1cb..04377870f2 100644 --- a/packages/nodes-base/nodes/Coda/TableDescription.ts +++ b/packages/nodes-base/nodes/Coda/TableDescription.ts @@ -33,6 +33,11 @@ export const tableOperations = [ value: 'deleteRow', description: 'Delete one or multiple rows', }, + { + name: 'Push Button', + value: 'pushButton', + description: 'Pushes a button', + }, ], default: 'createRow', description: 'The operation to perform.', @@ -42,7 +47,7 @@ export const tableOperations = [ export const tableFields = [ /* -------------------------------------------------------------------------- */ -/* table:createRow */ +/* table:createRow */ /* -------------------------------------------------------------------------- */ { displayName: 'Doc', @@ -125,7 +130,7 @@ export const tableFields = [ }, /* -------------------------------------------------------------------------- */ -/* table:get */ +/* table:get */ /* -------------------------------------------------------------------------- */ { displayName: 'Doc', @@ -249,7 +254,7 @@ export const tableFields = [ ] }, /* -------------------------------------------------------------------------- */ -/* table:getAll */ +/* table:getAll */ /* -------------------------------------------------------------------------- */ { displayName: 'Doc', @@ -354,6 +359,18 @@ export const tableFields = [ }, }, options: [ + { + displayName: 'Query', + name: 'query', + type: 'string', + typeOptions: { + alwaysOpenEditWindow: true, + }, + default: '', + description: `Query used to filter returned rows, specified as :.
+ If you'd like to use a column name instead of an ID, you must quote it (e.g., "My Column":123).
+ Also note that value is a JSON value; if you'd like to use a string, you must surround it in quotes (e.g., "groceries").`, + }, { displayName: 'Use Column Names', name: 'useColumnNames', @@ -484,5 +501,97 @@ export const tableFields = [ }, description: 'Row IDs to delete.', }, +/* -------------------------------------------------------------------------- */ +/* table:pushButton */ +/* -------------------------------------------------------------------------- */ + { + displayName: 'Doc', + name: 'docId', + type: 'options', + required: true, + typeOptions: { + loadOptionsMethod: 'getDocs', + }, + default: '', + displayOptions: { + show: { + resource: [ + 'table', + ], + operation: [ + 'pushButton', + ] + }, + }, + description: 'ID of the doc.', + }, + { + displayName: 'Table', + name: 'tableId', + type: 'options', + typeOptions: { + loadOptionsDependsOn: [ + 'docId', + ], + loadOptionsMethod: 'getTables', + }, + required: true, + default: '', + displayOptions: { + show: { + resource: [ + 'table', + ], + operation: [ + 'pushButton', + ] + }, + }, + description: 'The table to get the row from.', + }, + { + displayName: 'Row ID', + name: 'rowId', + type: 'string', + required: true, + default: '', + displayOptions: { + show: { + resource: [ + 'table', + ], + operation: [ + 'pushButton', + ] + }, + }, + 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: 'Column', + name: 'columnId', + type: 'options', + required: true, + typeOptions: { + loadOptionsMethod: 'getColumns', + loadOptionsDependsOn: [ + 'docId', + 'tableId', + ], + }, + default: '', + displayOptions: { + show: { + resource: [ + 'table', + ], + operation: [ + 'pushButton', + ] + }, + }, + }, ] as INodeProperties[];