Skip to content

Commit 75f525c

Browse files
authored
Removed withLabel field from worksheetId async props (#12637)
Added try/catch block for a more clear error msg hasHeaders prop as optional Improved hasHeaders prop description
1 parent 41c2075 commit 75f525c

File tree

13 files changed

+126
-59
lines changed

13 files changed

+126
-59
lines changed

components/google_sheets/actions/add-multiple-rows/add-multiple-rows.mjs

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
import googleSheets from "../../google_sheets.app.mjs";
1+
import common from "../common/worksheet.mjs";
22
import { ConfigurationError } from "@pipedream/platform";
33
import {
44
parseArray, getWorksheetHeaders,
55
} from "../../common/utils.mjs";
66

7+
const { googleSheets } = common.props;
8+
79
export default {
10+
...common,
811
key: "google_sheets-add-multiple-rows",
912
name: "Add Multiple Rows",
1013
description: "Add multiple rows of data to a Google Sheet. [See the documentation](https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/append)",
11-
version: "0.2.6",
14+
version: "0.2.7",
1215
type: "action",
1316
props: {
1417
googleSheets,
@@ -37,7 +40,6 @@ export default {
3740
],
3841
type: "string",
3942
label: "Worksheet Id",
40-
withLabel: true,
4143
reloadProps: true,
4244
},
4345
headersDisplay: {
@@ -70,7 +72,8 @@ export default {
7072
if (!this.sheetId || !this.worksheetId) {
7173
return props;
7274
}
73-
const rowHeaders = await getWorksheetHeaders(this, this.sheetId, this.worksheetId.label);
75+
const worksheet = await this.getWorksheetById(this.sheetId, this.worksheetId);
76+
const rowHeaders = await getWorksheetHeaders(this, this.sheetId, worksheet?.properties?.title);
7477
if (rowHeaders.length) {
7578
return {
7679
headersDisplay: {
@@ -100,9 +103,10 @@ export default {
100103
throw new ConfigurationError("Rows data is not an array of arrays. Please enter an array of arrays in the `Rows` parameter above. If you're trying to send a single rows to Google Sheets, search for the action to add a single row to Sheets or try modifying the code for this step.");
101104
}
102105

106+
const worksheet = await this.getWorksheetById(this.sheetId, this.worksheetId);
103107
const addRowsResponse = await this.googleSheets.addRowsToSheet({
104108
spreadsheetId: this.sheetId,
105-
range: this.worksheetId.label,
109+
range: worksheet?.properties?.title,
106110
rows,
107111
});
108112

components/google_sheets/actions/add-single-row/add-single-row.mjs

+28-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
import googleSheets from "../../google_sheets.app.mjs";
1+
import common from "../common/worksheet.mjs";
22
import { ConfigurationError } from "@pipedream/platform";
33
import { parseArray } from "../../common/utils.mjs";
44

5+
const { googleSheets } = common.props;
6+
57
export default {
8+
...common,
69
key: "google_sheets-add-single-row",
710
name: "Add Single Row",
811
description: "Add a single row of data to Google Sheets. [See the documentation](https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/append)",
9-
version: "2.1.7",
12+
version: "2.1.8",
1013
type: "action",
1114
props: {
1215
googleSheets,
@@ -24,7 +27,6 @@ export default {
2427
driveId: googleSheets.methods.getDriveId(c.drive),
2528
}),
2629
],
27-
withLabel: true,
2830
},
2931
worksheetId: {
3032
propDefinition: [
@@ -36,21 +38,26 @@ export default {
3638
],
3739
type: "string",
3840
label: "Worksheet Id",
39-
withLabel: true,
4041
},
4142
hasHeaders: {
4243
type: "boolean",
4344
label: "Does the first row of the sheet have headers?",
44-
description: "If the first row of your document has headers, we'll retrieve them to make it easy to enter the value for each column.",
45+
description: "If the first row of your document has headers, we'll retrieve them to make it easy to enter the value for each column. Please note, that if you are referencing a worksheet using a custom expression referencing data from another step, e.g. `{{steps.my_step.$return_value}}` this prop cannot be used. If you want to retrieve the headers use the `Select an option` instead in both **Spreadsheet** and **Worksheet Id** props.",
4546
reloadProps: true,
47+
optional: true,
4648
},
4749
},
4850
async additionalProps() {
49-
const sheetId = this.sheetId?.value || this.sheetId;
50-
const worksheetName = this.worksheetId?.label;
51+
const {
52+
sheetId,
53+
worksheetId,
54+
} = this;
55+
5156
const props = {};
5257
if (this.hasHeaders) {
53-
const { values } = await this.googleSheets.getSpreadsheetValues(sheetId, `${worksheetName}!1:1`);
58+
const worksheet = await this.getWorksheetById(sheetId, worksheetId);
59+
60+
const { values } = await this.googleSheets.getSpreadsheetValues(sheetId, `${worksheet?.properties?.title}!1:1`);
5461
if (!values[0]?.length) {
5562
throw new ConfigurationError("Could not find a header row. Please either add headers and click \"Refresh fields\" or adjust the action configuration to continue.");
5663
}
@@ -76,8 +83,17 @@ export default {
7683
return props;
7784
},
7885
async run({ $ }) {
79-
const sheetId = this.sheetId?.value || this.sheetId;
80-
const worksheetName = this.worksheetId.label;
86+
const {
87+
sheetId,
88+
worksheetId,
89+
} = this;
90+
91+
const { name: sheetName } = await this.googleSheets.getFile(sheetId, {
92+
fields: "name",
93+
});
94+
95+
const worksheet = await this.getWorksheetById(sheetId, worksheetId);
96+
8197
let cells;
8298
if (this.hasHeaders) {
8399
const rows = JSON.parse(this.allColumns);
@@ -109,13 +125,13 @@ export default {
109125

110126
const data = await this.googleSheets.addRowsToSheet({
111127
spreadsheetId: sheetId,
112-
range: worksheetName,
128+
range: worksheet?.properties?.title,
113129
rows: [
114130
arr,
115131
],
116132
});
117133

118-
let summary = `Added 1 row to [${this.sheetId?.label || sheetId} (${data.updatedRange})](https://docs.google.com/spreadsheets/d/${sheetId}).`;
134+
let summary = `Added 1 row to [${sheetName || sheetId} (${data.updatedRange})](https://docs.google.com/spreadsheets/d/${sheetId}).`;
119135
if (convertedIndexes.length > 0) {
120136
summary += " We detected something other than a string/number/boolean in at least one of the fields and automatically converted it to a string.";
121137
}

components/google_sheets/actions/clear-cell/clear-cell.mjs

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
import googleSheets from "../../google_sheets.app.mjs";
1+
import common from "../common/worksheet.mjs";
2+
3+
const { googleSheets } = common.props;
24

35
export default {
6+
...common,
47
key: "google_sheets-clear-cell",
58
name: "Clear Cell",
69
description: "Delete the content of a specific cell in a spreadsheet. [See the documentation](https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/clear)",
7-
version: "0.1.7",
10+
version: "0.1.8",
811
type: "action",
912
props: {
1013
googleSheets,
@@ -34,7 +37,6 @@ export default {
3437
],
3538
type: "string",
3639
label: "Worksheet Id",
37-
withLabel: true,
3840
},
3941
cell: {
4042
type: "string",
@@ -43,9 +45,10 @@ export default {
4345
},
4446
},
4547
async run() {
48+
const worksheet = await this.getWorksheetById(this.sheetId, this.worksheetId);
4649
const request = {
4750
spreadsheetId: this.sheetId,
48-
range: `${this.worksheetId.label}!${this.cell}`,
51+
range: `${worksheet?.properties?.title}!${this.cell}`,
4952
};
5053
return await this.googleSheets.clearSheetValues(request);
5154
},

components/google_sheets/actions/clear-rows/clear-rows.mjs

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
import googleSheets from "../../google_sheets.app.mjs";
1+
import common from "../common/worksheet.mjs";
2+
3+
const { googleSheets } = common.props;
24

35
export default {
6+
...common,
47
key: "google_sheets-clear-rows",
58
name: "Clear Rows",
69
description: "Delete the content of a row or rows in a spreadsheet. Deleted rows will appear as blank rows. [See the documentation](https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/clear)",
7-
version: "0.1.5",
10+
version: "0.1.6",
811
type: "action",
912
props: {
1013
googleSheets,
@@ -34,7 +37,6 @@ export default {
3437
],
3538
type: "string",
3639
label: "Worksheet Id",
37-
withLabel: true,
3840
},
3941
startIndex: {
4042
type: "integer",
@@ -49,9 +51,10 @@ export default {
4951
},
5052
},
5153
async run() {
54+
const worksheet = await this.getWorksheetById(this.sheetId, this.worksheetId);
5255
const request = {
5356
spreadsheetId: this.sheetId,
54-
range: `${this.worksheetId.label}!${this.startIndex}:${this.endIndex || this.startIndex}`,
57+
range: `${worksheet?.properties?.title}!${this.startIndex}:${this.endIndex || this.startIndex}`,
5558
};
5659
return await this.googleSheets.clearSheetValues(request);
5760
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import googleSheets from "../../google_sheets.app.mjs";
2+
3+
export default {
4+
props: {
5+
googleSheets,
6+
},
7+
methods: {
8+
async getWorksheetById(sheetId, worksheetId) {
9+
try {
10+
const { sheets } = await this.googleSheets.getSpreadsheet(sheetId);
11+
return sheets
12+
.find(({ properties: { sheetId } }) => String(sheetId) === String(worksheetId));
13+
} catch (error) {
14+
const errorMsg = `Error fetching worksheet with ID \`${worksheetId}\` - ${error.message}`;
15+
console.log(error);
16+
throw new Error(errorMsg);
17+
}
18+
},
19+
},
20+
};

components/google_sheets/actions/find-row/find-row.mjs

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
import googleSheets from "../../google_sheets.app.mjs";
1+
import common from "../common/worksheet.mjs";
2+
3+
const { googleSheets } = common.props;
24

35
export default {
6+
...common,
47
key: "google_sheets-find-row",
58
name: "Find Row",
69
description: "Find one or more rows by a column and value. [See the documentation](https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/get)",
7-
version: "0.2.5",
10+
version: "0.2.6",
811
type: "action",
912
props: {
1013
googleSheets,
@@ -33,7 +36,6 @@ export default {
3336
],
3437
type: "string",
3538
label: "Worksheet Id",
36-
withLabel: true,
3739
},
3840
column: {
3941
propDefinition: [
@@ -54,11 +56,12 @@ export default {
5456
},
5557
},
5658
async run() {
59+
const worksheet = await this.getWorksheetById(this.sheetId, this.worksheetId);
5760
const sheets = this.googleSheets.sheets();
5861

5962
const colValues = (await sheets.spreadsheets.values.get({
6063
spreadsheetId: this.sheetId,
61-
range: `${this.worksheetId.label}!${this.column}:${this.column}`,
64+
range: `${worksheet?.properties?.title}!${this.column}:${this.column}`,
6265
})).data.values;
6366

6467
const rows = [];
@@ -81,7 +84,7 @@ export default {
8184
const { data: { values } } =
8285
await sheets.spreadsheets.values.get({
8386
spreadsheetId: this.sheetId,
84-
range: `${this.worksheetId.label}`,
87+
range: `${worksheet?.properties?.title}`,
8588
});
8689
return values.reduce((acc, row, index) => {
8790
if (indexes.includes(index)) {

components/google_sheets/actions/get-cell/get-cell.mjs

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
import googleSheets from "../../google_sheets.app.mjs";
1+
import common from "../common/worksheet.mjs";
2+
3+
const { googleSheets } = common.props;
24

35
export default {
6+
...common,
47
key: "google_sheets-get-cell",
58
name: "Get Cell",
69
description: "Fetch the contents of a specific cell in a spreadsheet. [See the documentation](https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/get)",
7-
version: "0.1.5",
10+
version: "0.1.6",
811
type: "action",
912
props: {
1013
googleSheets,
@@ -33,7 +36,6 @@ export default {
3336
],
3437
type: "string",
3538
label: "Worksheet Id",
36-
withLabel: true,
3739
},
3840
cell: {
3941
propDefinition: [
@@ -43,11 +45,12 @@ export default {
4345
},
4446
},
4547
async run() {
48+
const worksheet = await this.getWorksheetById(this.sheetId, this.worksheetId);
4649
const sheets = this.googleSheets.sheets();
4750

4851
const values = (await sheets.spreadsheets.values.get({
4952
spreadsheetId: this.sheetId,
50-
range: `${this.worksheetId.label}!${this.cell}:${this.cell}`,
53+
range: `${worksheet?.properties?.title}!${this.cell}:${this.cell}`,
5154
})).data.values;
5255
if (values?.length) {
5356
return values[0][0];

components/google_sheets/actions/get-values-in-range/get-values-in-range.mjs

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
import googleSheets from "../../google_sheets.app.mjs";
1+
import common from "../common/worksheet.mjs";
2+
3+
const { googleSheets } = common.props;
24

35
export default {
6+
...common,
47
key: "google_sheets-get-values-in-range",
58
name: "Get Values in Range",
69
description: "Get all values or values from a range of cells using A1 notation. [See the documentation](https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/get)",
7-
version: "0.1.5",
10+
version: "0.1.6",
811
type: "action",
912
props: {
1013
googleSheets,
@@ -33,7 +36,6 @@ export default {
3336
],
3437
type: "string",
3538
label: "Worksheet Id",
36-
withLabel: true,
3739
},
3840
range: {
3941
propDefinition: [
@@ -44,13 +46,14 @@ export default {
4446
},
4547
},
4648
async run() {
49+
const worksheet = await this.getWorksheetById(this.sheetId, this.worksheetId);
4750
const sheets = this.googleSheets.sheets();
4851

4952
return (await sheets.spreadsheets.values.get({
5053
spreadsheetId: this.sheetId,
5154
range: this.range
52-
? `${this.worksheetId.label}!${this.range}`
53-
: `${this.worksheetId.label}`,
55+
? `${worksheet?.properties?.title}!${this.range}`
56+
: `${worksheet?.properties?.title}`,
5457
})).data.values;
5558
},
5659
};

components/google_sheets/actions/update-cell/update-cell.mjs

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
import googleSheets from "../../google_sheets.app.mjs";
1+
import common from "../common/worksheet.mjs";
2+
3+
const { googleSheets } = common.props;
24

35
export default {
6+
...common,
47
key: "google_sheets-update-cell",
58
name: "Update Cell",
69
description: "Update a cell in a spreadsheet. [See the documentation](https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/update)",
7-
version: "0.1.5",
10+
version: "0.1.6",
811
type: "action",
912
props: {
1013
googleSheets,
@@ -35,7 +38,6 @@ export default {
3538
],
3639
type: "string",
3740
label: "Worksheet Id",
38-
withLabel: true,
3941
},
4042
cell: {
4143
propDefinition: [
@@ -54,9 +56,10 @@ export default {
5456
},
5557
},
5658
async run() {
59+
const worksheet = await this.getWorksheetById(this.sheetId, this.worksheetId);
5760
const request = {
5861
spreadsheetId: this.sheetId,
59-
range: `${this.worksheetId.label}!${this.cell}:${this.cell}`,
62+
range: `${worksheet?.properties?.title}!${this.cell}:${this.cell}`,
6063
valueInputOption: "USER_ENTERED",
6164
resource: {
6265
values: [

0 commit comments

Comments
 (0)