From ee968b212a4b0c4da13cef3859a2d8526e95b998 Mon Sep 17 00:00:00 2001 From: Dean Date: Mon, 9 Sep 2024 16:10:39 +0100 Subject: [PATCH 1/4] Fix to accommodate filtering updates for GoogleSheets --- packages/server/src/integrations/googlesheets.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/server/src/integrations/googlesheets.ts b/packages/server/src/integrations/googlesheets.ts index f8f5209890..ea62281d4b 100644 --- a/packages/server/src/integrations/googlesheets.ts +++ b/packages/server/src/integrations/googlesheets.ts @@ -566,24 +566,20 @@ class GoogleSheetsIntegration implements DatasourcePlus { query.filters.equal[`_${GOOGLE_SHEETS_PRIMARY_KEY}`] = id } } - let filtered = dataFilters.runQuery( - rows, - query.filters || {}, - (row: GoogleSpreadsheetRow, headerKey: string) => { - return row.get(headerKey) - } - ) + if (hasFilters && query.paginate) { - filtered = filtered.slice(offset, offset + limit) + rows = rows.slice(offset, offset + limit) } const headerValues = sheet.headerValues let response = [] - for (let row of filtered) { + for (let row of rows) { response.push( - this.buildRowObject(headerValues, row.toObject(), row._rowNumber) + this.buildRowObject(headerValues, row.toObject(), row.rowNumber) ) } + response = dataFilters.runQuery(response, query.filters || {}) + if (query.sort) { if (Object.keys(query.sort).length !== 1) { console.warn("Googlesheets does not support multiple sorting", { From 6e10c528d89a8204d8ff8fe8e4dfe8958aca37bc Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 9 Sep 2024 16:25:34 +0100 Subject: [PATCH 2/4] Getting rid of findInDoc as its not used anymore. --- packages/shared-core/src/filters.ts | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/packages/shared-core/src/filters.ts b/packages/shared-core/src/filters.ts index 70fb24b373..bcd2e0e338 100644 --- a/packages/shared-core/src/filters.ts +++ b/packages/shared-core/src/filters.ts @@ -471,15 +471,8 @@ export const search = ( * Performs a client-side search on an array of data * @param docs the data * @param query the JSON query - * @param findInDoc optional fn when trying to extract a value - * from custom doc type e.g. Google Sheets - * */ -export const runQuery = ( - docs: Record[], - query: SearchFilters, - findInDoc: Function = deepGet -) => { +export const runQuery = (docs: Record[], query: SearchFilters) => { if (!docs || !Array.isArray(docs)) { return [] } @@ -503,11 +496,8 @@ export const runQuery = ( test: (docValue: any, testValue: any) => boolean ) => (doc: Record) => { - for (const [key, testValue] of Object.entries(query[type] || {})) { - const valueToCheck = isLogicalSearchOperator(type) - ? doc - : findInDoc(doc, removeKeyNumbering(key)) - const result = test(valueToCheck, testValue) + for (const testValue of Object.values(query[type] || {})) { + const result = test(doc, testValue) if (query.allOr && result) { return true } else if (!query.allOr && !result) { From ac2416dc0b2a5b43d1fdd705e7432c52af7d5d97 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 9 Sep 2024 16:30:38 +0100 Subject: [PATCH 3/4] Lint. --- packages/shared-core/src/filters.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shared-core/src/filters.ts b/packages/shared-core/src/filters.ts index bcd2e0e338..971b59a6fb 100644 --- a/packages/shared-core/src/filters.ts +++ b/packages/shared-core/src/filters.ts @@ -22,7 +22,7 @@ import { } from "@budibase/types" import dayjs from "dayjs" import { OperatorOptions, SqlNumberTypeRangeMap } from "./constants" -import { deepGet, schema } from "./helpers" +import { schema } from "./helpers" import { isPlainObject, isEmpty } from "lodash" import { decodeNonAscii } from "./helpers/schema" From 1a27cf9d5b4931e2b15e711def1c4132fcce16cb Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 9 Sep 2024 16:40:04 +0100 Subject: [PATCH 4/4] Fix - thanks tests. --- packages/shared-core/src/filters.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/shared-core/src/filters.ts b/packages/shared-core/src/filters.ts index 971b59a6fb..31934371f6 100644 --- a/packages/shared-core/src/filters.ts +++ b/packages/shared-core/src/filters.ts @@ -22,7 +22,7 @@ import { } from "@budibase/types" import dayjs from "dayjs" import { OperatorOptions, SqlNumberTypeRangeMap } from "./constants" -import { schema } from "./helpers" +import { deepGet, schema } from "./helpers" import { isPlainObject, isEmpty } from "lodash" import { decodeNonAscii } from "./helpers/schema" @@ -496,8 +496,11 @@ export const runQuery = (docs: Record[], query: SearchFilters) => { test: (docValue: any, testValue: any) => boolean ) => (doc: Record) => { - for (const testValue of Object.values(query[type] || {})) { - const result = test(doc, testValue) + for (const [key, testValue] of Object.entries(query[type] || {})) { + const valueToCheck = isLogicalSearchOperator(type) + ? doc + : deepGet(doc, removeKeyNumbering(key)) + const result = test(valueToCheck, testValue) if (query.allOr && result) { return true } else if (!query.allOr && !result) {