Skip to content

Commit

Permalink
Parameter to accept a specific range within a Googlesheet (ToolJet#798)
Browse files Browse the repository at this point in the history
* Parameter to accept a specific range within a googlesheet

* default range: A1:Z500
  • Loading branch information
arpitnath authored Sep 21, 2021
1 parent ab17ead commit 4dc356c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
16 changes: 16 additions & 0 deletions frontend/src/Editor/QueryManager/QueryEditors/Googlesheets.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ class Googlesheets extends React.Component {
className="form-control"
/>
</div>
{['read'].includes(this.state.options.operation) && (
<div className="col-auto">
<label className="form-label">Range</label>
<input
type="text"
placeholder={'A1:Z500'}
value={this.state.options.spreadsheet_range}
onChange={(e) => {
changeOption(this, 'spreadsheet_range', e.target.value);
}}
className="form-control"
/>
</div>
) }
<div className="col-auto">
<label className="form-label">Sheet</label>
<input
Expand All @@ -104,6 +118,8 @@ class Googlesheets extends React.Component {
</div>
)}



{this.state.options.operation === 'append' && (
<div className="mb-3 mt-2">
<label className="form-label">Rows</label>
Expand Down
5 changes: 3 additions & 2 deletions server/plugins/datasources/googlesheets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export default class GooglesheetsQueryService implements QueryService {
let response = null;
const operation = queryOptions.operation;
const spreadsheetId = queryOptions['spreadsheet_id'];
const spreadsheetRange = queryOptions['spreadsheet_range'] ? queryOptions['spreadsheet_range'] : 'A1:Z500' ;
const accessToken = sourceOptions['access_token'];

try {
Expand All @@ -84,8 +85,8 @@ export default class GooglesheetsQueryService implements QueryService {
result = JSON.parse(response.body);
break;

case 'read':
result = await readData(spreadsheetId, queryOptions['sheet'], this.authHeader(accessToken));
case 'read':
result = await readData(spreadsheetId, spreadsheetRange, queryOptions['sheet'], this.authHeader(accessToken));
break;

case 'append':
Expand Down
3 changes: 2 additions & 1 deletion server/plugins/datasources/googlesheets/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,11 @@ async function deleteDataFromSheet(

export async function readData(
spreadSheetId: string,
spreadsheetRange:string,
sheet: string,
authHeader: any,
): Promise<any[]> {
return await readDataFromSheet(spreadSheetId, sheet, 'A1:Z500', authHeader);
return await readDataFromSheet(spreadSheetId, sheet, spreadsheetRange, authHeader);
}

export async function appendData(
Expand Down

0 comments on commit 4dc356c

Please sign in to comment.