Skip to content

Commit 26654f0

Browse files
Coda new actions (#2013)
* template for actions * add create doc action * add copy doc action * remove timezone parameter * change props to prop definitions * add list docs action * refactor prop names and properties * add pagination in list docs * move optional and default props to coda source * add source doc id list options * refactor new remove empty key values method * add list tables action * add list columns * add create rows * add find row * add update row * add upsert rows * refactor to initial action versions * style action keys as in docs * refactor props * refactor descriptions * remove authKeys * review js docs * refactor create doc method * descriptions review and rewriting * create _makeRequest method * always paginate when listing docs * change to pipedream axios * fix some prop descriptions * refactor columnId prop * unneeded _removeEmptyKeyValues method * add summary export for actions * better id/value options viewing * create default rows prop * add coda error handling messages * fix labels and descriptions in actions * remove doc id async options prop input * pass $ to axios * change options label to just name * update row action with additional props as column values * find row query using column id * find row optional column id and query * add async options pagination * change limit prop to max in list docs actions * add pagination to actions * add page counter to context * fix return list directly in actions
1 parent 2f11414 commit 26654f0

File tree

10 files changed

+962
-4
lines changed

10 files changed

+962
-4
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import coda from "../../coda.app.mjs";
2+
3+
export default {
4+
key: "coda-copy-doc",
5+
name: "Copy Doc",
6+
description: "Creates a copy of the specified doc. [See docs](https://coda.io/developers/apis/v1#operation/createDoc)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
coda,
11+
docId: {
12+
propDefinition: [
13+
coda,
14+
"docId",
15+
],
16+
label: "Source Doc ID",
17+
description: "The doc from which to create a copy",
18+
},
19+
title: {
20+
propDefinition: [
21+
coda,
22+
"title",
23+
],
24+
description: "Title of the newly copied doc. Defaults to `\"Copy of <originalTitle>\"`",
25+
},
26+
folderId: {
27+
propDefinition: [
28+
coda,
29+
"folderId",
30+
],
31+
description: "The folder within which to copy this doc",
32+
},
33+
},
34+
async run({ $ }) {
35+
let data = {
36+
title: this.title,
37+
folderId: this.folderId,
38+
sourceDoc: this.docId,
39+
};
40+
41+
let response = await this.coda.createDoc($, data);
42+
$.export("$summary", `Copied to new doc "${response.name}" in folderId: "${response.folderId}" and workspaceId: "${response.workspaceId}"`);
43+
return response;
44+
},
45+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import coda from "../../coda.app.mjs";
2+
3+
export default {
4+
key: "coda-create-doc",
5+
name: "Create Doc",
6+
description: "Creates a new doc. [See docs](https://coda.io/developers/apis/v1#operation/createDoc)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
coda,
11+
title: {
12+
propDefinition: [
13+
coda,
14+
"title",
15+
],
16+
},
17+
folderId: {
18+
propDefinition: [
19+
coda,
20+
"folderId",
21+
],
22+
description: "The folder within which to create this doc",
23+
},
24+
},
25+
async run({ $ }) {
26+
let data = {
27+
title: this.title,
28+
folderId: this.folderId,
29+
};
30+
31+
let response = await this.coda.createDoc($, data);
32+
$.export("$summary", `Created doc "${response.name}" in folderId: "${response.folderId}" and workspaceId: "${response.workspaceId}"`);
33+
return response;
34+
},
35+
};
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import coda from "../../coda.app.mjs";
2+
3+
export default {
4+
key: "coda-create-rows",
5+
name: "Create Rows",
6+
description: "Insert a row in a selected table. [See docs](https://coda.io/developers/apis/v1#operation/upsertRows)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
coda,
11+
docId: {
12+
propDefinition: [
13+
coda,
14+
"docId",
15+
],
16+
},
17+
tableId: {
18+
propDefinition: [
19+
coda,
20+
"tableId",
21+
(c) => ({
22+
docId: c.docId,
23+
}),
24+
],
25+
reloadProps: true,
26+
},
27+
disableParsing: {
28+
propDefinition: [
29+
coda,
30+
"disableParsing",
31+
],
32+
},
33+
},
34+
async additionalProps() {
35+
const props = {};
36+
const { items } = await this.coda.listColumns(this, this.docId, this.tableId);
37+
for (const item of items) {
38+
props[`col_${item.id}`] = {
39+
type: "string",
40+
label: `Column: ${item.name}`,
41+
description: "Leave blank to ignore this column",
42+
optional: true,
43+
};
44+
}
45+
return props;
46+
},
47+
async run({ $ }) {
48+
const params = {
49+
disableParsing: this.disableParsing,
50+
};
51+
52+
const data = {
53+
rows: [
54+
{
55+
cells: this.coda.createRowCells(this),
56+
},
57+
],
58+
};
59+
60+
const response = await this.coda.createRows(
61+
$,
62+
this.docId,
63+
this.tableId,
64+
data,
65+
params,
66+
);
67+
68+
$.export("$summary", "Created row successfully");
69+
return response;
70+
},
71+
};
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import coda from "../../coda.app.mjs";
2+
3+
export default {
4+
key: "coda-find-row",
5+
name: "Find Row",
6+
description: "Searches for a row in the selected table using a column match search. [See docs](https://coda.io/developers/apis/v1#operation/listRows)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
coda,
11+
docId: {
12+
propDefinition: [
13+
coda,
14+
"docId",
15+
],
16+
},
17+
tableId: {
18+
propDefinition: [
19+
coda,
20+
"tableId",
21+
(c) => ({
22+
docId: c.docId,
23+
}),
24+
],
25+
},
26+
columnId: {
27+
propDefinition: [
28+
coda,
29+
"columnId",
30+
(c) => ({
31+
docId: c.docId,
32+
tableId: c.tableId,
33+
}),
34+
],
35+
description: "ID of the column. This field is required if querying",
36+
optional: true,
37+
},
38+
query: {
39+
propDefinition: [
40+
coda,
41+
"query",
42+
],
43+
description: "Query used to filter returned rows",
44+
optional: true,
45+
},
46+
sortBy: {
47+
propDefinition: [
48+
coda,
49+
"sortBy",
50+
],
51+
description: "Specifies the sort order of the rows returned. If left unspecified, rows are returned by creation time ascending",
52+
options: [
53+
"createdAt",
54+
"natural",
55+
"updatedAt",
56+
],
57+
},
58+
visibleOnly: {
59+
propDefinition: [
60+
coda,
61+
"visibleOnly",
62+
],
63+
},
64+
useColumnNames: {
65+
type: "boolean",
66+
label: "Use Column Names",
67+
description: "Use column names instead of column IDs in the returned output",
68+
optional: true,
69+
},
70+
valueFormat: {
71+
type: "string",
72+
label: "Value Format",
73+
description: "The format that individual cell values are returned as",
74+
optional: true,
75+
options: [
76+
"simple",
77+
"simpleWithArrays",
78+
"rich",
79+
],
80+
},
81+
max: {
82+
propDefinition: [
83+
coda,
84+
"max",
85+
],
86+
},
87+
},
88+
async run({ $ }) {
89+
let params = {
90+
sortBy: this.sortBy,
91+
visibleOnly: this.visibleOnly,
92+
useColumnNames: this.useColumnNames,
93+
valueFormat: this.valueFormat,
94+
};
95+
96+
if (this.columnId && this.query) {
97+
params.query = `${this.columnId}:"${this.query}"`;
98+
}
99+
100+
let items = [];
101+
let response;
102+
do {
103+
response = await this.coda.findRow(
104+
$,
105+
this.docId,
106+
this.tableId,
107+
params,
108+
);
109+
items.push(...response.items);
110+
params.pageToken = response.nextPageToken;
111+
} while (params.pageToken && items.length < this.max);
112+
113+
if (items.length > this.max) items.length = this.max;
114+
115+
if (items.length > 0) {
116+
$.export("$summary", `Found ${items.length} rows`);
117+
} else {
118+
$.export("$summary", `No rows found with the search query: ${this.query}`);
119+
}
120+
return {
121+
items,
122+
};
123+
},
124+
};
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import coda from "../../coda.app.mjs";
2+
3+
export default {
4+
key: "coda-list-columns",
5+
name: "List Columns",
6+
description: "Lists columns in a table. [See docs](https://coda.io/developers/apis/v1#operation/listColumns)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
coda,
11+
docId: {
12+
propDefinition: [
13+
coda,
14+
"docId",
15+
],
16+
},
17+
tableId: {
18+
propDefinition: [
19+
coda,
20+
"tableId",
21+
(c) => ({
22+
docId: c.docId,
23+
}),
24+
],
25+
},
26+
visibleOnly: {
27+
propDefinition: [
28+
coda,
29+
"visibleOnly",
30+
],
31+
},
32+
max: {
33+
propDefinition: [
34+
coda,
35+
"max",
36+
],
37+
},
38+
},
39+
async run({ $ }) {
40+
let params = {
41+
visibleOnly: this.visibleOnly,
42+
};
43+
44+
let items = [];
45+
let response;
46+
do {
47+
response = await this.coda.listColumns(
48+
$,
49+
this.docId,
50+
this.tableId,
51+
params,
52+
);
53+
items.push(...response.items);
54+
params.pageToken = response.nextPageToken;
55+
} while (params.pageToken && items.length < this.max);
56+
57+
if (items.length > this.max) items.length = this.max;
58+
59+
$.export("$summary", `Retrieved ${items.length} column(s)`);
60+
61+
return items;
62+
},
63+
};

0 commit comments

Comments
 (0)