From 7f3d88265e38d20ed1edf8622069365dd4fa8441 Mon Sep 17 00:00:00 2001 From: Dean Date: Tue, 17 Sep 2024 11:18:32 +0100 Subject: [PATCH] Allow passing no query to the search API. --- packages/frontend-core/src/api/tables.js | 4 ++-- packages/frontend-core/src/fetch/UserFetch.js | 2 +- packages/frontend-core/src/fetch/ViewV2Fetch.js | 2 +- packages/shared-core/src/filters.ts | 7 ++++++- packages/shared-core/src/utils.ts | 12 ++++++------ 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/frontend-core/src/api/tables.js b/packages/frontend-core/src/api/tables.js index 34d2371e1a..dc9008e4eb 100644 --- a/packages/frontend-core/src/api/tables.js +++ b/packages/frontend-core/src/api/tables.js @@ -40,7 +40,7 @@ export const buildTableEndpoints = API => ({ sortType, paginate, }) => { - if (!tableId || !query) { + if (!tableId) { return { rows: [], } @@ -48,7 +48,7 @@ export const buildTableEndpoints = API => ({ return await API.post({ url: `/api/${tableId}/search`, body: { - query, + ...(query ? { query } : {}), bookmark, limit, sort, diff --git a/packages/frontend-core/src/fetch/UserFetch.js b/packages/frontend-core/src/fetch/UserFetch.js index 39a8d79214..902aa7edad 100644 --- a/packages/frontend-core/src/fetch/UserFetch.js +++ b/packages/frontend-core/src/fetch/UserFetch.js @@ -32,7 +32,7 @@ export default class UserFetch extends DataFetch { const { cursor, query } = get(this.store) let finalQuery // convert old format to new one - we now allow use of the lucene format - const { appId, paginated, ...rest } = query + const { appId, paginated, ...rest } = query || {} finalQuery = utils.isSupportedUserSearch(rest) ? query diff --git a/packages/frontend-core/src/fetch/ViewV2Fetch.js b/packages/frontend-core/src/fetch/ViewV2Fetch.js index 303414b2dc..46343492b4 100644 --- a/packages/frontend-core/src/fetch/ViewV2Fetch.js +++ b/packages/frontend-core/src/fetch/ViewV2Fetch.js @@ -64,7 +64,7 @@ export default class ViewV2Fetch extends DataFetch { try { const res = await this.API.viewV2.fetch({ viewId: datasource.id, - query, + ...(query ? { query } : {}), paginate, limit, bookmark: cursor, diff --git a/packages/shared-core/src/filters.ts b/packages/shared-core/src/filters.ts index e4f0282775..360d3ae512 100644 --- a/packages/shared-core/src/filters.ts +++ b/packages/shared-core/src/filters.ts @@ -574,7 +574,12 @@ export const buildQueryLegacy = ( export const buildQuery = ( filter?: SearchFilterGroup | SearchFilter[] ): SearchFilters | undefined => { - const parsedFilter: SearchFilterGroup = processSearchFilters(filter) + const parsedFilter: SearchFilterGroup | undefined = + processSearchFilters(filter) + + if (!parsedFilter) { + return + } const operatorMap: { [key in FilterGroupLogicalOperator]: LogicalOperator } = { diff --git a/packages/shared-core/src/utils.ts b/packages/shared-core/src/utils.ts index 623b1a4245..5b4d439984 100644 --- a/packages/shared-core/src/utils.ts +++ b/packages/shared-core/src/utils.ts @@ -97,17 +97,17 @@ export function trimOtherProps(object: any, allowedProps: string[]) { */ export const processSearchFilters = ( filters: SearchFilter[] | SearchFilterGroup | undefined -): SearchFilterGroup => { +): SearchFilterGroup | undefined => { + if (!filters) { + return + } + // Base search config. const defaultCfg: SearchFilterGroup = { logicalOperator: FilterGroupLogicalOperator.ALL, groups: [], } - if (!filters) { - return defaultCfg - } - const filterWhitelistKeys = [ "field", "operator", @@ -182,7 +182,7 @@ export const processSearchFilters = ( return migratedSetting } else if (!filters?.groups) { - return defaultCfg + return } return filters }