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", { diff --git a/packages/shared-core/src/filters.ts b/packages/shared-core/src/filters.ts index 70fb24b373..31934371f6 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 [] } @@ -506,7 +499,7 @@ export const runQuery = ( for (const [key, testValue] of Object.entries(query[type] || {})) { const valueToCheck = isLogicalSearchOperator(type) ? doc - : findInDoc(doc, removeKeyNumbering(key)) + : deepGet(doc, removeKeyNumbering(key)) const result = test(valueToCheck, testValue) if (query.allOr && result) { return true