Skip to content

Commit 4d8dd79

Browse files
authored
New Components - google_appsheet (#15509)
* google_appsheet init * [Components] google_appsheet #15159 Actions - Add Row - Update Row - Delete Row * pnpm update * some adjusts
1 parent 1eb4668 commit 4d8dd79

File tree

11 files changed

+252
-22
lines changed

11 files changed

+252
-22
lines changed

components/google_appsheet/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import common from "../common/base.mjs";
2+
3+
export default {
4+
...common,
5+
key: "google_appsheet-add-row",
6+
name: "Add Row",
7+
description: "Adds a new row to a specific table in the 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",
9+
type: "action",
10+
methods: {
11+
...common.methods,
12+
getAction() {
13+
return "Add";
14+
},
15+
getSummary() {
16+
return "Added a new row successfully";
17+
},
18+
},
19+
};
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
methods: {
21+
getData() {
22+
return {};
23+
},
24+
},
25+
async run({ $ }) {
26+
const dataRow = parseObject(this.row);
27+
const rows = dataRow
28+
? [
29+
dataRow,
30+
]
31+
: [];
32+
33+
const response = await this.appsheet.post({
34+
$,
35+
tableName: this.tableName,
36+
data: {
37+
Action: this.getAction(),
38+
Rows: rows,
39+
...this.getData(),
40+
},
41+
});
42+
console.log("response: ", response);
43+
44+
$.export("$summary", this.getSummary(response));
45+
return response;
46+
},
47+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import common from "../common/base.mjs";
2+
3+
export default {
4+
...common,
5+
key: "google_appsheet-delete-row",
6+
name: "Delete Row",
7+
description: "Deletes a specific row from a table in the 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",
9+
type: "action",
10+
props: {
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.",
16+
},
17+
row: {
18+
propDefinition: [
19+
common.props.appsheet,
20+
"row",
21+
],
22+
description: "The `Row` value may contain field values of the key field values of the record to be deleted.",
23+
optional: true,
24+
},
25+
},
26+
methods: {
27+
...common.methods,
28+
getAction() {
29+
return "Delete";
30+
},
31+
getSummary(response) {
32+
return `${response.Rows.length} successfully delete!`;
33+
},
34+
},
35+
};
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import common from "../common/base.mjs";
2+
3+
export default {
4+
...common,
5+
key: "google_appsheet-get-rows",
6+
name: "Get Rows",
7+
description: "Read existing records in a table in the 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",
9+
type: "action",
10+
props: {
11+
...common.props,
12+
selector: {
13+
type: "string",
14+
label: "Selector",
15+
description: "You can specify an expression to select and format the rows returned. **Example: Filter(TableName, [Column] = \"Value\")** [See the documentation](https://support.google.com/appsheet/answer/10105770?hl=en&ref_topic=10105767&sjid=3242006823758562345-NC)",
16+
optional: true,
17+
},
18+
row: {
19+
propDefinition: [
20+
common.props.appsheet,
21+
"row",
22+
],
23+
description: "You can also filter the results using the `Row` value. The `Row` value may contain field values of the key field values of the record to be retrieved. **Example:** `{ \"First Name\": \"John\" }`",
24+
optional: true,
25+
},
26+
},
27+
methods: {
28+
...common.methods,
29+
getAction() {
30+
return "Find";
31+
},
32+
getData() {
33+
return this.selector
34+
? {
35+
Properties: {
36+
Selector: this.selector,
37+
},
38+
}
39+
: {};
40+
},
41+
getSummary(response) {
42+
return `Successfully retrieved ${ response.length || 0} rows`;
43+
},
44+
},
45+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import common from "../common/base.mjs";
2+
3+
export default {
4+
...common,
5+
key: "google_appsheet-update-row",
6+
name: "Update Row",
7+
description: "Updates an existing row in a specific table in the 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",
9+
type: "action",
10+
props: {
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.`,
18+
},
19+
},
20+
methods: {
21+
...common.methods,
22+
getAction() {
23+
return "Edit";
24+
},
25+
getSummary(response) {
26+
return `${response.Rows.length} successfully updated!`;
27+
},
28+
},
29+
};

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+
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { axios } from "@pipedream/platform";
2+
3+
export default {
4+
type: "app",
5+
app: "google_appsheet",
6+
propDefinitions: {
7+
tableName: {
8+
type: "string",
9+
label: "Table Name",
10+
description: "Name of the table. **Select Data > Tables** and expand the table details to view the table name.",
11+
},
12+
row: {
13+
type: "object",
14+
label: "Row",
15+
description: "JSON object representing the row data",
16+
},
17+
},
18+
methods: {
19+
_baseUrl(tableName) {
20+
return `https://api.appsheet.com/api/v2/apps/${this.$auth.app_id}/tables/${encodeURIComponent(tableName)}/Action`;
21+
},
22+
_headers() {
23+
return {
24+
"ApplicationAccessKey": `${this.$auth.api_key}`,
25+
};
26+
},
27+
_makeRequest({
28+
$ = this, tableName, ...opts
29+
}) {
30+
return axios($, {
31+
url: this._baseUrl(tableName),
32+
headers: this._headers(),
33+
...opts,
34+
});
35+
},
36+
post(opts = {}) {
37+
return this._makeRequest({
38+
method: "POST",
39+
...opts,
40+
});
41+
},
42+
},
43+
};
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)