Skip to content

Commit 18316f9

Browse files
committed
[Components] zoho_sheet #14584
Sources - New Row (Instant) - New Or Updated Row (Instant) - New Workbook (Instant) Actions - Create Row - Search Delete Row - Update Row
1 parent b476fcf commit 18316f9

File tree

15 files changed

+415
-323
lines changed

15 files changed

+415
-323
lines changed

components/zoho_sheet/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { parseObject } from "../../common/utils.mjs";
12
import zohoSheet from "../../zoho_sheet.app.mjs";
2-
import { axios } from "@pipedream/platform";
33

44
export default {
55
key: "zoho_sheet-create-row",
@@ -9,12 +9,27 @@ export default {
99
type: "action",
1010
props: {
1111
zohoSheet,
12+
workbookId: {
13+
propDefinition: [
14+
zohoSheet,
15+
"workbookId",
16+
],
17+
},
1218
worksheet: {
1319
propDefinition: [
1420
zohoSheet,
1521
"worksheet",
22+
({ workbookId }) => ({
23+
workbookId,
24+
}),
1625
],
1726
},
27+
headerRow: {
28+
type: "integer",
29+
label: "Header Row",
30+
description: "Default value is 1. This can be mentioned if the table header is not in the first row of the worksheet.",
31+
optional: true,
32+
},
1833
data: {
1934
propDefinition: [
2035
zohoSheet,
@@ -24,11 +39,16 @@ export default {
2439
},
2540
async run({ $ }) {
2641
const response = await this.zohoSheet.createRow({
27-
worksheet: this.worksheet,
28-
data: this.data,
42+
$,
43+
workbookId: this.workbookId,
44+
data: {
45+
worksheet_id: this.worksheet,
46+
header_row: this.headerRow || 1,
47+
json_data: JSON.stringify(parseObject(this.data)),
48+
},
2949
});
3050

31-
$.export("$summary", `Successfully created a row in the worksheet: ${this.worksheet}`);
51+
$.export("$summary", `Successfully created a row in the worksheet: ${response.sheet_name}`);
3252
return response;
3353
},
3454
};

components/zoho_sheet/actions/search-delete-row/search-delete-row.mjs

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,85 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import { parseObject } from "../../common/utils.mjs";
13
import zohoSheet from "../../zoho_sheet.app.mjs";
2-
import { axios } from "@pipedream/platform";
34

45
export default {
56
key: "zoho_sheet-search-delete-row",
67
name: "Search and Delete Row",
78
description: "Searches for a row based on provided criteria and deletes it. [See the documentation](https://www.zoho.com/sheet/help/api/v2/)",
8-
version: "0.0.{{ts}}",
9+
version: "0.0.1",
910
type: "action",
1011
props: {
1112
zohoSheet,
13+
workbookId: {
14+
propDefinition: [
15+
zohoSheet,
16+
"workbookId",
17+
],
18+
},
1219
worksheet: {
1320
propDefinition: [
1421
zohoSheet,
1522
"worksheet",
23+
({ workbookId }) => ({
24+
workbookId,
25+
}),
1626
],
1727
},
28+
headerRow: {
29+
propDefinition: [
30+
zohoSheet,
31+
"headerRow",
32+
],
33+
optional: true,
34+
},
1835
criteria: {
1936
propDefinition: [
2037
zohoSheet,
2138
"criteria",
2239
],
40+
optional: true,
41+
},
42+
rowArray: {
43+
type: "integer[]",
44+
label: "Row Array",
45+
description: "Array of row indexs, which needs to be deleted.",
46+
optional: true,
47+
},
48+
firstMatchOnly: {
49+
propDefinition: [
50+
zohoSheet,
51+
"firstMatchOnly",
52+
],
53+
},
54+
isCaseSensitive: {
55+
propDefinition: [
56+
zohoSheet,
57+
"isCaseSensitive",
58+
],
59+
},
60+
deleteRows: {
61+
type: "boolean",
62+
label: "Delete Rows",
63+
description: "If true it will delete the rows completely, otherwise the records are only erased by default.",
64+
default: false,
2365
},
2466
},
2567
async run({ $ }) {
68+
if (!this.criteria && !this.rowArray) {
69+
throw new ConfigurationError("You must provide at least **Criteria** or **Row Array** to process this request.");
70+
}
2671
const response = await this.zohoSheet.deleteRow({
27-
worksheet: this.worksheet,
28-
criteria: this.criteria,
72+
$,
73+
workbookId: this.workbookId,
74+
data: {
75+
worksheet_id: this.worksheet,
76+
header_row: this.headerRow,
77+
criteria: this.criteria,
78+
row_array: JSON.stringify(parseObject(this.rowArray)),
79+
first_match_only: this.firstMatchOnly,
80+
is_case_sensitive: this.isCaseSensitive,
81+
delete_rows: this.deleteRows,
82+
},
2983
});
3084

3185
$.export("$summary", `Row matching criteria deleted successfully from worksheet ${this.worksheet}`);
Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { parseObject } from "../../common/utils.mjs";
12
import zohoSheet from "../../zoho_sheet.app.mjs";
2-
import { axios } from "@pipedream/platform";
33

44
export default {
55
key: "zoho_sheet-update-row",
@@ -9,33 +9,73 @@ export default {
99
type: "action",
1010
props: {
1111
zohoSheet,
12+
workbookId: {
13+
propDefinition: [
14+
zohoSheet,
15+
"workbookId",
16+
],
17+
},
1218
worksheet: {
1319
propDefinition: [
1420
zohoSheet,
1521
"worksheet",
22+
({ workbookId }) => ({
23+
workbookId,
24+
}),
25+
],
26+
},
27+
headerRow: {
28+
propDefinition: [
29+
zohoSheet,
30+
"headerRow",
31+
],
32+
optional: true,
33+
},
34+
criteria: {
35+
propDefinition: [
36+
zohoSheet,
37+
"criteria",
38+
],
39+
description: "If criteria is not set all available rows will get updated. Mention the criteria as described above.",
40+
optional: true,
41+
},
42+
firstMatchOnly: {
43+
propDefinition: [
44+
zohoSheet,
45+
"firstMatchOnly",
1646
],
47+
description: "If true and if there are multiple records on the specified criteria, records will be updated for first match alone. Otherwise, all the matched records will be updated.",
1748
},
18-
rowIndex: {
49+
isCaseSensitive: {
1950
propDefinition: [
2051
zohoSheet,
21-
"rowIndex",
52+
"isCaseSensitive",
2253
],
2354
},
2455
data: {
2556
propDefinition: [
2657
zohoSheet,
2758
"data",
2859
],
60+
type: "object",
61+
description: "The JSON data that needs to be updated. Example:{\"Month\":\"May\",\"Amount\":50}",
2962
},
3063
},
3164
async run({ $ }) {
3265
const response = await this.zohoSheet.updateRow({
33-
worksheet: this.worksheet,
34-
rowIndex: this.rowIndex,
35-
data: this.data,
66+
$,
67+
workbookId: this.workbookId,
68+
data: {
69+
worksheet_id: this.worksheet,
70+
header_row: this.headerRow,
71+
criteria: this.criteria,
72+
first_match_only: this.firstMatchOnly,
73+
is_case_sensitive: this.isCaseSensitive,
74+
data: JSON.stringify(parseObject(this.data)),
75+
},
3676
});
3777

38-
$.export("$summary", `Successfully updated row ${this.rowIndex} in worksheet ${this.worksheet}`);
78+
$.export("$summary", `Successfully updated ${response.no_of_affected_rows} row(s) in worksheet ${this.worksheet}`);
3979
return response;
4080
},
4181
};

components/zoho_sheet/app/zoho_sheet.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/zoho_sheet/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"name": "@pipedream/zoho_sheet",
3-
"version": "0.0.3",
3+
"version": "0.1.0",
44
"description": "Pipedream Zoho Sheet Components",
5-
"main": "dist/app/zoho_sheet.app.mjs",
5+
"main": "zoho_sheet.app.mjs",
66
"keywords": [
77
"pipedream",
88
"zoho_sheet"
99
],
10-
"files": [
11-
"dist"
12-
],
1310
"homepage": "https://pipedream.com/apps/zoho_sheet",
1411
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1512
"publishConfig": {
1613
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1717
}
1818
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import zohoSheet from "../../zoho_sheet.app.mjs";
2+
3+
export default {
4+
props: {
5+
zohoSheet,
6+
http: {
7+
type: "$.interface.http",
8+
customResponse: true,
9+
},
10+
db: "$.service.db",
11+
serviceName: {
12+
type: "string",
13+
label: "Service Name",
14+
description: "The name of the webhook.",
15+
},
16+
},
17+
methods: {
18+
getExtraData() {
19+
return {};
20+
},
21+
},
22+
hooks: {
23+
async activate() {
24+
await this.zohoSheet.createWebhook({
25+
data: {
26+
service_name: this.serviceName.replace(/\s/g, ""),
27+
target_url: this.http.endpoint,
28+
event: this.getEvent(),
29+
...this.getExtraData(),
30+
},
31+
});
32+
},
33+
async deactivate() {
34+
await this.zohoSheet.deleteWebhook({
35+
data: {
36+
target_url: this.http.endpoint,
37+
...this.getExtraData(),
38+
},
39+
});
40+
},
41+
},
42+
async run({ body }) {
43+
const ts = Date.parse(new Date());
44+
this.$emit(body, {
45+
id: `${ts}`,
46+
summary: this.getSummary(body),
47+
ts: ts,
48+
});
49+
},
50+
};

0 commit comments

Comments
 (0)