Change filter query to store the expected shape
This commit is contained in:
parent
74287370df
commit
77568af704
|
@ -6,6 +6,7 @@ import {
|
|||
SortType,
|
||||
ViewV2,
|
||||
} from "@budibase/types"
|
||||
import { dataFilters } from "@budibase/shared-core"
|
||||
import sdk from "../../../sdk"
|
||||
|
||||
export async function searchView(ctx: UserCtx<void, SearchResponse>) {
|
||||
|
@ -29,11 +30,12 @@ export async function searchView(ctx: UserCtx<void, SearchResponse>) {
|
|||
undefined
|
||||
|
||||
ctx.status = 200
|
||||
const query = dataFilters.buildLuceneQuery(view.query || [])
|
||||
const result = await quotas.addQuery(
|
||||
() =>
|
||||
sdk.rows.search({
|
||||
tableId: view.tableId,
|
||||
query: view.query || {},
|
||||
query,
|
||||
fields: viewFields,
|
||||
...getSortOptions(ctx, view),
|
||||
}),
|
||||
|
|
|
@ -869,7 +869,14 @@ describe("/rows", () => {
|
|||
)
|
||||
|
||||
const createViewResponse = await config.api.viewV2.create({
|
||||
query: { equal: { age: 40 } },
|
||||
query: [
|
||||
{
|
||||
operator: "equal",
|
||||
field: "age",
|
||||
value: "40",
|
||||
type: FieldType.NUMBER,
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
const response = await config.api.viewV2.search(createViewResponse.id)
|
||||
|
|
|
@ -181,9 +181,13 @@ export const buildLuceneQuery = (filter: SearchFilter[]) => {
|
|||
}
|
||||
if (operator.startsWith("range") && query.range) {
|
||||
const minint =
|
||||
SqlNumberTypeRangeMap[externalType]?.min || Number.MIN_SAFE_INTEGER
|
||||
SqlNumberTypeRangeMap[
|
||||
externalType as keyof typeof SqlNumberTypeRangeMap
|
||||
]?.min || Number.MIN_SAFE_INTEGER
|
||||
const maxint =
|
||||
SqlNumberTypeRangeMap[externalType]?.max || Number.MAX_SAFE_INTEGER
|
||||
SqlNumberTypeRangeMap[
|
||||
externalType as keyof typeof SqlNumberTypeRangeMap
|
||||
]?.max || Number.MAX_SAFE_INTEGER
|
||||
if (!query.range[field]) {
|
||||
query.range[field] = {
|
||||
low: type === "number" ? minint : "0000-00-00T00:00:00.000Z",
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import { FieldType } from "../../documents"
|
||||
|
||||
export type SearchFilter = {
|
||||
operator: keyof SearchQuery
|
||||
field: string
|
||||
type: any
|
||||
type?: FieldType
|
||||
value: any
|
||||
externalType: "integer" | "int" | "smallint" | "mediumint"
|
||||
externalType?: string
|
||||
}
|
||||
|
||||
export type SearchQuery = {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import { SortOrder, SortType } from "../../api"
|
||||
import { SearchFilters } from "../../sdk"
|
||||
import { TableSchema, UIFieldMetadata } from "./table"
|
||||
import { SearchFilter, SortOrder, SortType } from "../../api"
|
||||
import { UIFieldMetadata } from "./table"
|
||||
|
||||
export interface View {
|
||||
name: string
|
||||
|
@ -20,7 +19,7 @@ export interface ViewV2 {
|
|||
name: string
|
||||
primaryDisplay?: string
|
||||
tableId: string
|
||||
query?: SearchFilters
|
||||
query?: SearchFilter[]
|
||||
sort?: {
|
||||
field: string
|
||||
order?: SortOrder
|
||||
|
|
Loading…
Reference in New Issue