Skip to content

Commit 4ddfc9e

Browse files
committed
[Components] google_appsheet #15159
Actions - Add Row - Update Row - Delete Row
1 parent ca816a1 commit 4ddfc9e

File tree

9 files changed

+129
-155
lines changed

9 files changed

+129
-155
lines changed

components/google_appsheet/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
1-
import appsheet from "../../appsheet.app.mjs";
2-
import { axios } from "@pipedream/platform";
1+
import common from "../common/base.mjs";
32

43
export default {
5-
key: "appsheet-add-row",
4+
...common,
5+
key: "google_appsheet-add-row",
66
name: "Add Row",
7-
description: "Adds a new row to a specific table in an AppSheet app. [See the documentation]()",
8-
version: "0.0.{{ts}}",
7+
description: "Adds a new row to a specific table in an AppSheet app. [See the documentation](https://support.google.com/appsheet/answer/10104797?hl=en&ref_topic=10105767&sjid=1665780.0.1444403316-SA#)",
8+
version: "0.0.1",
99
type: "action",
10-
props: {
11-
appsheet,
12-
rowData: {
13-
type: "object",
14-
label: "Row Data",
15-
description: "JSON object representing the new row data",
10+
methods: {
11+
getAction() {
12+
return "Add";
13+
},
14+
getSummary() {
15+
return "Added a new row successfully";
1616
},
17-
},
18-
async run({ $ }) {
19-
const response = await this.appsheet.addRow(this.rowData);
20-
$.export("$summary", "Added a new row successfully");
21-
return response;
2217
},
2318
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { parseObject } from "../../common/utils.mjs";
2+
import appsheet from "../../google_appsheet.app.mjs";
3+
4+
export default {
5+
props: {
6+
appsheet,
7+
tableName: {
8+
propDefinition: [
9+
appsheet,
10+
"tableName",
11+
],
12+
},
13+
row: {
14+
propDefinition: [
15+
appsheet,
16+
"row",
17+
],
18+
},
19+
},
20+
async run({ $ }) {
21+
const response = await this.appsheet.post({
22+
$,
23+
tableName: this.tableName,
24+
data: {
25+
Action: this.getAction(),
26+
Rows: [
27+
parseObject(this.row),
28+
],
29+
},
30+
});
31+
$.export("$summary", this.getSummary(response));
32+
return response;
33+
},
34+
};
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
import google_appsheet from "../../google_appsheet.app.mjs";
2-
import { axios } from "@pipedream/platform";
1+
import common from "../common/base.mjs";
32

43
export default {
4+
...common,
55
key: "google_appsheet-delete-row",
66
name: "Delete Row",
7-
description: "Deletes a specific row from a table in an AppSheet app. [See the documentation]()",
8-
version: "0.0.{{ts}}",
7+
description: "Deletes a specific row from a table in an AppSheet app. [See the documentation](https://support.google.com/appsheet/answer/10105399?hl=en&ref_topic=10105767&sjid=1665780.0.1444403316-SA)",
8+
version: "0.0.1",
99
type: "action",
1010
props: {
11-
google_appsheet: {
12-
type: "app",
13-
app: "google_appsheet",
14-
},
15-
rowId: {
16-
type: "string",
17-
label: "Row ID",
18-
description: "The ID of the row to delete",
11+
...common.props,
12+
alert: {
13+
type: "alert",
14+
alertType: "info",
15+
content: "The `Row` value may contain field values of the key field values of the record to be deleted.",
1916
},
2017
},
21-
async run({ $ }) {
22-
const response = await this.google_appsheet.deleteRow(this.rowId);
23-
$.export("$summary", `Deleted row with ID ${this.rowId}`);
24-
return response;
18+
methods: {
19+
getAction() {
20+
return "Delete";
21+
},
22+
getSummary(response) {
23+
return `${response.Rows.length} successfully delete!`;
24+
},
2525
},
2626
};
Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
import google_appsheet from "../../google_appsheet.app.mjs";
1+
import common from "../common/base.mjs";
22

33
export default {
4+
...common,
45
key: "google_appsheet-update-row",
56
name: "Update Row",
6-
description: "Updates an existing row in a specific table in an AppSheet app. [See the documentation]()",
7-
version: "0.0.{{ts}}",
7+
description: "Updates an existing row in a specific table in an AppSheet app. [See the documentation](https://support.google.com/appsheet/answer/10105002?hl=en&ref_topic=10105767&sjid=1665780.0.1444403316-SA)",
8+
version: "0.0.1",
89
type: "action",
910
props: {
10-
google_appsheet,
11-
rowId: {
12-
type: "string",
13-
label: "Row ID",
14-
description: "The ID of the row to update",
15-
},
16-
fieldsToUpdate: {
17-
type: "object",
18-
label: "Fields to Update",
19-
description: "Key-value pairs of fields to update",
11+
...common.props,
12+
alert: {
13+
type: "alert",
14+
alertType: "info",
15+
content: `The \`Row\` value must include the key field values of the record to be updated.
16+
\nThe \`Row\` value may contain one or more field values of other fields to be updated in the record.
17+
\nIf a field's name is omitted, that field's value is not changed. If the field can be assigned a string value and the field value you specify is "" then the field's value will be cleared.`,
2018
},
2119
},
22-
async run({ $ }) {
23-
const response = await this.google_appsheet.updateRow(this.rowId, this.fieldsToUpdate);
24-
$.export("$summary", `Updated row with ID ${this.rowId}`);
25-
return response;
20+
methods: {
21+
getAction() {
22+
return "Edit";
23+
},
24+
getSummary(response) {
25+
return `${response.Rows.length} successfully updated!`;
26+
},
2627
},
2728
};

components/google_appsheet/app/google_appsheet.app.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) return undefined;
3+
4+
if (Array.isArray(obj)) {
5+
return obj.map((item) => {
6+
if (typeof item === "string") {
7+
try {
8+
return JSON.parse(item);
9+
} catch (e) {
10+
return item;
11+
}
12+
}
13+
return item;
14+
});
15+
}
16+
if (typeof obj === "string") {
17+
try {
18+
return JSON.parse(obj);
19+
} catch (e) {
20+
return obj;
21+
}
22+
}
23+
return obj;
24+
};

components/google_appsheet/google_appsheet.app.mjs

Lines changed: 21 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -2,105 +2,41 @@ import { axios } from "@pipedream/platform";
22

33
export default {
44
type: "app",
5-
app: "appsheet",
6-
version: "0.0.{{ts}}",
5+
app: "google_appsheet",
76
propDefinitions: {
8-
appsheetRegion: {
9-
type: "string",
10-
label: "AppSheet Region",
11-
description: "Domain used to invoke the API based on data residency regions",
12-
options: [
13-
{
14-
label: "Global (www.appsheet.com)",
15-
value: "www.appsheet.com",
16-
},
17-
{
18-
label: "EU (eu.appsheet.com)",
19-
value: "eu.appsheet.com",
20-
},
21-
],
22-
},
23-
appId: {
24-
type: "string",
25-
label: "App ID",
26-
description: "ID of the AppSheet app",
27-
},
287
tableName: {
298
type: "string",
309
label: "Table Name",
31-
description: "Name of the table",
10+
description: "Name of the table. **Select Data > Tables** and expand the table details to view the table name.",
3211
},
33-
applicationAccessKey: {
34-
type: "string",
35-
label: "Application Access Key",
36-
description: "Access key for the AppSheet API",
37-
secret: true,
12+
row: {
13+
type: "object",
14+
label: "Row",
15+
description: "JSON object representing the new row data",
3816
},
3917
},
4018
methods: {
41-
_baseUrl() {
42-
return `https://${this.appsheetRegion}/api/v2/apps/${this.appId}/tables/${encodeURIComponent(this.tableName)}/Action`;
43-
},
44-
async _makeRequest(opts = {}) {
45-
const {
46-
$, method = "POST", data, headers = {}, ...otherOpts
47-
} = opts;
48-
return axios($, {
49-
method,
50-
url: `${this._baseUrl()}?applicationAccessKey=${this.applicationAccessKey}`,
51-
data,
52-
headers: {
53-
...headers,
54-
"Content-Type": "application/json",
55-
},
56-
...otherOpts,
57-
});
19+
_baseUrl(tableName) {
20+
return `https://api.appsheet.com/api/v2/apps/${this.$auth.app_id}/tables/${encodeURIComponent(tableName)}/Action`;
5821
},
59-
async addRow(rowData) {
60-
const requestBody = {
61-
Action: "Add",
62-
Properties: {
63-
Locale: "en-US",
64-
},
65-
Rows: [
66-
rowData,
67-
],
22+
_headers() {
23+
return {
24+
"ApplicationAccessKey": `${this.$auth.api_key}`,
6825
};
69-
return this._makeRequest({
70-
data: requestBody,
71-
});
7226
},
73-
async updateRow(rowId, fieldsToUpdate) {
74-
const requestBody = {
75-
Action: "Edit",
76-
Properties: {
77-
Locale: "en-US",
78-
},
79-
Rows: [
80-
{
81-
RowId: rowId,
82-
...fieldsToUpdate,
83-
},
84-
],
85-
};
86-
return this._makeRequest({
87-
data: requestBody,
27+
_makeRequest({
28+
$ = this, tableName, ...opts
29+
}) {
30+
return axios($, {
31+
url: this._baseUrl(tableName),
32+
headers: this._headers(),
33+
...opts,
8834
});
8935
},
90-
async deleteRow(rowId) {
91-
const requestBody = {
92-
Action: "Delete",
93-
Properties: {
94-
Locale: "en-US",
95-
},
96-
Rows: [
97-
{
98-
RowId: rowId,
99-
},
100-
],
101-
};
36+
post(opts = {}) {
10237
return this._makeRequest({
103-
data: requestBody,
38+
method: "POST",
39+
...opts,
10440
});
10541
},
10642
},
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"name": "@pipedream/google_appsheet",
3-
"version": "0.0.3",
3+
"version": "0.1.0",
44
"description": "Pipedream Google Appsheet Components",
5-
"main": "dist/app/google_appsheet.app.mjs",
5+
"main": "google_appsheet.app.mjs",
66
"keywords": [
77
"pipedream",
88
"google_appsheet"
99
],
10-
"files": [
11-
"dist"
12-
],
1310
"homepage": "https://pipedream.com/apps/google_appsheet",
1411
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1512
"publishConfig": {
1613
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1717
}
1818
}

0 commit comments

Comments
 (0)