Skip to content

Commit

Permalink
adds incremental columns beyond 'Z' (ToolJet#2440)
Browse files Browse the repository at this point in the history
  • Loading branch information
arpitnath authored Mar 7, 2022
1 parent dfd9e7a commit 7775ef5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 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,
spreadsheetRange,
queryOptions.sheet,
queryOptions.body,
queryOptionFilter,
Expand Down
11 changes: 11 additions & 0 deletions 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"
},
"spreadsheet_range": {
"label": "Range",
"key": "spreadsheet_range",
"type": "codehinter",
"lineNumbers": false,
"placeholder": "A1:Z500",
"description": "Enter range",
"width": "320px",
"height": "36px",
"className": "codehinter-plugins"
},
"sheet": {
"label": "Sheet name",
"key": "sheet",
Expand Down
27 changes: 21 additions & 6 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,
spreadsheetRange: string='A1:Z500',
sheet: string='',
requestBody: any,
filterData: any,
Expand All @@ -45,7 +46,7 @@ export async function batchUpdateToSheet(
return new Error('filterOperator is required');
}

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

const updateBody = (requestBody, filterCondition, filterOperator, data) => {
const rowsIndexes = getRowsIndex(filterCondition, filterOperator, data) as any[];
Expand Down Expand Up @@ -183,8 +184,8 @@ export async function deleteData(
return await deleteDataFromSheet(spreadSheetId, sheet, rowIndex, authHeader);
}

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

Expand All @@ -198,9 +199,14 @@ const getInputKeys = (inputBody, data) => {
keys.map((key) =>
data.filter((val, index) => {
if (val[0] === key) {
const kIndex = `${String.fromCharCode(65 + index)}`;
arr.push({ col: val[0], colIndex: kIndex });
}
let keyIndex = '';
if(index >= 26) {
keyIndex = numberToLetters(index);
} else {
keyIndex = `${String.fromCharCode(65 + index)}`;
}
arr.push({ col: val[0], colIndex: keyIndex });
}
})
);
return arr;
Expand Down Expand Up @@ -236,3 +242,12 @@ const getRowsIndex = (inputFilter, filterOperator, response) => {

return rowIndex;
};

function numberToLetters(num) {
let letters = ''
while (num >= 0) {
letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'[num % 26] + letters
num = Math.floor(num / 26) - 1
}
return letters
}

0 comments on commit 7775ef5

Please sign in to comment.