Merge pull request #11920 from Budibase/BUDI-7249/google-sheet-rowindex-is-off
Fixing query row index on google sheets
This commit is contained in:
commit
51e5ef5402
|
@ -322,14 +322,14 @@ class GoogleSheetsIntegration implements DatasourcePlus {
|
||||||
case Operation.UPDATE:
|
case Operation.UPDATE:
|
||||||
return this.update({
|
return this.update({
|
||||||
// exclude the header row and zero index
|
// exclude the header row and zero index
|
||||||
rowIndex: json.extra?.idFilter?.equal?.rowNumber - 2,
|
rowIndex: json.extra?.idFilter?.equal?.rowNumber,
|
||||||
sheet,
|
sheet,
|
||||||
row: json.body,
|
row: json.body,
|
||||||
})
|
})
|
||||||
case Operation.DELETE:
|
case Operation.DELETE:
|
||||||
return this.delete({
|
return this.delete({
|
||||||
// exclude the header row and zero index
|
// exclude the header row and zero index
|
||||||
rowIndex: json.extra?.idFilter?.equal?.rowNumber - 2,
|
rowIndex: json.extra?.idFilter?.equal?.rowNumber,
|
||||||
sheet,
|
sheet,
|
||||||
})
|
})
|
||||||
case Operation.CREATE_TABLE:
|
case Operation.CREATE_TABLE:
|
||||||
|
@ -540,12 +540,21 @@ class GoogleSheetsIntegration implements DatasourcePlus {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async getRowByIndex(sheetTitle: string, rowIndex: number) {
|
||||||
|
const sheet = this.client.sheetsByTitle[sheetTitle]
|
||||||
|
const rows = await sheet.getRows()
|
||||||
|
// We substract 2, as the SDK is skipping the header automatically and Google Spreadsheets is base 1
|
||||||
|
const row = rows[rowIndex - 2]
|
||||||
|
return { sheet, row }
|
||||||
|
}
|
||||||
|
|
||||||
async update(query: { sheet: string; rowIndex: number; row: any }) {
|
async update(query: { sheet: string; rowIndex: number; row: any }) {
|
||||||
try {
|
try {
|
||||||
await this.connect()
|
await this.connect()
|
||||||
const sheet = this.client.sheetsByTitle[query.sheet]
|
const { sheet, row } = await this.getRowByIndex(
|
||||||
const rows = await sheet.getRows()
|
query.sheet,
|
||||||
const row = rows[query.rowIndex]
|
query.rowIndex
|
||||||
|
)
|
||||||
if (row) {
|
if (row) {
|
||||||
const updateValues =
|
const updateValues =
|
||||||
typeof query.row === "string" ? JSON.parse(query.row) : query.row
|
typeof query.row === "string" ? JSON.parse(query.row) : query.row
|
||||||
|
@ -571,9 +580,7 @@ class GoogleSheetsIntegration implements DatasourcePlus {
|
||||||
|
|
||||||
async delete(query: { sheet: string; rowIndex: number }) {
|
async delete(query: { sheet: string; rowIndex: number }) {
|
||||||
await this.connect()
|
await this.connect()
|
||||||
const sheet = this.client.sheetsByTitle[query.sheet]
|
const { row } = await this.getRowByIndex(query.sheet, query.rowIndex)
|
||||||
const rows = await sheet.getRows()
|
|
||||||
const row = rows[query.rowIndex]
|
|
||||||
if (row) {
|
if (row) {
|
||||||
await row.delete()
|
await row.delete()
|
||||||
return [
|
return [
|
||||||
|
|
Loading…
Reference in New Issue