Added push a button operation

This commit is contained in:
Ricardo Espinoza 2020-01-30 17:02:09 -05:00
parent 56c8d4688f
commit b3a394a38f
2 changed files with 153 additions and 4 deletions

View file

@ -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<INodePropertyOptions[]> {
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 [];
}
}

View file

@ -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.',
@ -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 <column_id_or_name>:<value>. <br/>
If you'd like to use a column name instead of an ID, you must quote it (e.g., "My Column":123).<br/>
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[];