Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Navaneeth-pk committed Feb 16, 2022
2 parents 64cfcc6 + 1b7fb46 commit 0f71973
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions plugins/packages/googlesheets/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export default class GooglesheetsQueryService implements QueryService {
case "update":
result = await batchUpdateToSheet(
spreadsheetId,
queryOptions.sheet,
queryOptions.body,
queryOptionFilter,
queryOptions.where_operation,
Expand Down
13 changes: 12 additions & 1 deletion plugins/packages/googlesheets/lib/operations.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@
"className": "codehinter-plugins",
"placeholder": "Enter spreadsheet_id"
},
"sheet": {
"label": "Sheet name",
"key": "sheet",
"type": "codehinter",
"lineNumbers": false,
"description": "Enter sheet name",
"width": "320px",
"height": "36px",
"className": "codehinter-plugins",
"placeholder": "Leave blank to use first sheet"
},
"where_field": {
"label": "Where",
"key": "where_field",
Expand Down Expand Up @@ -197,7 +208,7 @@
"description": "Enter value",
"height": "36px",
"className": "codehinter-plugins col-4",
"placeholder": "Enter spreadsheet_id"
"placeholder": "Enter value"
},
"body": {
"label": "Body",
Expand Down
10 changes: 6 additions & 4 deletions plugins/packages/googlesheets/lib/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ async function makeRequestToLookUpCellValues(spreadSheetId: string, range: strin

export async function batchUpdateToSheet(
spreadSheetId: string,
sheet: string='',
requestBody: any,
filterData: any,
filterOperator: string,
Expand All @@ -44,7 +45,7 @@ export async function batchUpdateToSheet(
return new Error('filterOperator is required');
}

const lookUpData = await lookUpSheetData(spreadSheetId, authHeader);
const lookUpData = await lookUpSheetData(spreadSheetId, sheet, authHeader);

const updateBody = (requestBody, filterCondition, filterOperator, data) => {
const rowsIndexes = getRowsIndex(filterCondition, filterOperator, data) as any[];
Expand Down Expand Up @@ -72,7 +73,7 @@ export async function batchUpdateToSheet(
const _data = body.map((data) => {
return {
majorDimension: 'ROWS',
range: data.cellIndex,
range: `${sheet}!${data.cellIndex}`,
values: [[data.cellValue]],
};
});
Expand Down Expand Up @@ -182,8 +183,9 @@ export async function deleteData(
return await deleteDataFromSheet(spreadSheetId, sheet, rowIndex, authHeader);
}

async function lookUpSheetData(spreadSheetId: string, authHeader: any) {
const responseLookUpCellValues = await makeRequestToLookUpCellValues(spreadSheetId, 'A1:Z500', authHeader);
async function lookUpSheetData(spreadSheetId: string, sheet:string, authHeader: any) {
const range = `${sheet}!A1:Z500`;
const responseLookUpCellValues = await makeRequestToLookUpCellValues(spreadSheetId, range, authHeader);
const data = await responseLookUpCellValues['values'];

return data;
Expand Down

0 comments on commit 0f71973

Please sign in to comment.