Merge master.
This commit is contained in:
commit
5cd1b00dad
|
@ -571,24 +571,20 @@ export class GoogleSheetsIntegration implements DatasourcePlus {
|
||||||
query.filters.equal[`_${GOOGLE_SHEETS_PRIMARY_KEY}`] = id
|
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) {
|
if (hasFilters && query.paginate) {
|
||||||
filtered = filtered.slice(offset, offset + limit)
|
rows = rows.slice(offset, offset + limit)
|
||||||
}
|
}
|
||||||
const headerValues = sheet.headerValues
|
const headerValues = sheet.headerValues
|
||||||
let response = []
|
let response = []
|
||||||
for (let row of filtered) {
|
for (let row of rows) {
|
||||||
response.push(
|
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 (query.sort) {
|
||||||
if (Object.keys(query.sort).length !== 1) {
|
if (Object.keys(query.sort).length !== 1) {
|
||||||
console.warn("Googlesheets does not support multiple sorting", {
|
console.warn("Googlesheets does not support multiple sorting", {
|
||||||
|
|
|
@ -471,14 +471,10 @@ export function search<T>(
|
||||||
* Performs a client-side search on an array of data
|
* Performs a client-side search on an array of data
|
||||||
* @param docs the data
|
* @param docs the data
|
||||||
* @param query the JSON query
|
* @param query the JSON query
|
||||||
* @param findInDoc optional fn when trying to extract a value
|
|
||||||
* from custom doc type e.g. Google Sheets
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
export function runQuery<T extends Record<string, any>>(
|
export function runQuery<T extends Record<string, any>>(
|
||||||
docs: T[],
|
docs: T[],
|
||||||
query: SearchFilters,
|
query: SearchFilters
|
||||||
findInDoc: (obj: T, key: string) => any = deepGet
|
|
||||||
): T[] {
|
): T[] {
|
||||||
if (!docs || !Array.isArray(docs)) {
|
if (!docs || !Array.isArray(docs)) {
|
||||||
return []
|
return []
|
||||||
|
@ -506,7 +502,7 @@ export function runQuery<T extends Record<string, any>>(
|
||||||
for (const [key, testValue] of Object.entries(query[type] || {})) {
|
for (const [key, testValue] of Object.entries(query[type] || {})) {
|
||||||
const valueToCheck = isLogicalSearchOperator(type)
|
const valueToCheck = isLogicalSearchOperator(type)
|
||||||
? doc
|
? doc
|
||||||
: findInDoc(doc, removeKeyNumbering(key))
|
: deepGet(doc, removeKeyNumbering(key))
|
||||||
const result = test(valueToCheck, testValue)
|
const result = test(valueToCheck, testValue)
|
||||||
if (query.allOr && result) {
|
if (query.allOr && result) {
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Reference in New Issue