Allow passing no query to the search API.

This commit is contained in:
Dean 2024-09-17 11:18:32 +01:00
parent 7e37420c97
commit 7f3d88265e
5 changed files with 16 additions and 11 deletions

View File

@ -40,7 +40,7 @@ export const buildTableEndpoints = API => ({
sortType, sortType,
paginate, paginate,
}) => { }) => {
if (!tableId || !query) { if (!tableId) {
return { return {
rows: [], rows: [],
} }
@ -48,7 +48,7 @@ export const buildTableEndpoints = API => ({
return await API.post({ return await API.post({
url: `/api/${tableId}/search`, url: `/api/${tableId}/search`,
body: { body: {
query, ...(query ? { query } : {}),
bookmark, bookmark,
limit, limit,
sort, sort,

View File

@ -32,7 +32,7 @@ export default class UserFetch extends DataFetch {
const { cursor, query } = get(this.store) const { cursor, query } = get(this.store)
let finalQuery let finalQuery
// convert old format to new one - we now allow use of the lucene format // 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) finalQuery = utils.isSupportedUserSearch(rest)
? query ? query

View File

@ -64,7 +64,7 @@ export default class ViewV2Fetch extends DataFetch {
try { try {
const res = await this.API.viewV2.fetch({ const res = await this.API.viewV2.fetch({
viewId: datasource.id, viewId: datasource.id,
query, ...(query ? { query } : {}),
paginate, paginate,
limit, limit,
bookmark: cursor, bookmark: cursor,

View File

@ -574,7 +574,12 @@ export const buildQueryLegacy = (
export const buildQuery = ( export const buildQuery = (
filter?: SearchFilterGroup | SearchFilter[] filter?: SearchFilterGroup | SearchFilter[]
): SearchFilters | undefined => { ): SearchFilters | undefined => {
const parsedFilter: SearchFilterGroup = processSearchFilters(filter) const parsedFilter: SearchFilterGroup | undefined =
processSearchFilters(filter)
if (!parsedFilter) {
return
}
const operatorMap: { [key in FilterGroupLogicalOperator]: LogicalOperator } = const operatorMap: { [key in FilterGroupLogicalOperator]: LogicalOperator } =
{ {

View File

@ -97,17 +97,17 @@ export function trimOtherProps(object: any, allowedProps: string[]) {
*/ */
export const processSearchFilters = ( export const processSearchFilters = (
filters: SearchFilter[] | SearchFilterGroup | undefined filters: SearchFilter[] | SearchFilterGroup | undefined
): SearchFilterGroup => { ): SearchFilterGroup | undefined => {
if (!filters) {
return
}
// Base search config. // Base search config.
const defaultCfg: SearchFilterGroup = { const defaultCfg: SearchFilterGroup = {
logicalOperator: FilterGroupLogicalOperator.ALL, logicalOperator: FilterGroupLogicalOperator.ALL,
groups: [], groups: [],
} }
if (!filters) {
return defaultCfg
}
const filterWhitelistKeys = [ const filterWhitelistKeys = [
"field", "field",
"operator", "operator",
@ -182,7 +182,7 @@ export const processSearchFilters = (
return migratedSetting return migratedSetting
} else if (!filters?.groups) { } else if (!filters?.groups) {
return defaultCfg return
} }
return filters return filters
} }