Fix types
This commit is contained in:
parent
831df35c5e
commit
c4ba33cf5b
|
@ -1,10 +1,16 @@
|
||||||
import { makePropSafe as safe } from "@budibase/string-templates"
|
import { makePropSafe as safe } from "@budibase/string-templates"
|
||||||
import { API } from "../api/index.js"
|
import { API } from "../api/index.js"
|
||||||
import { UILogicalOperator } from "@budibase/types"
|
import {
|
||||||
|
BasicOperator,
|
||||||
|
LegacyFilter,
|
||||||
|
UIColumn,
|
||||||
|
UILogicalOperator,
|
||||||
|
UISearchFilter,
|
||||||
|
} from "@budibase/types"
|
||||||
import { Constants } from "@budibase/frontend-core"
|
import { Constants } from "@budibase/frontend-core"
|
||||||
|
|
||||||
// Map of data types to component types for search fields inside blocks
|
// Map of data types to component types for search fields inside blocks
|
||||||
const schemaComponentMap = {
|
const schemaComponentMap: Record<string, string> = {
|
||||||
string: "stringfield",
|
string: "stringfield",
|
||||||
options: "optionsfield",
|
options: "optionsfield",
|
||||||
number: "numberfield",
|
number: "numberfield",
|
||||||
|
@ -19,7 +25,16 @@ const schemaComponentMap = {
|
||||||
* @param searchColumns the search columns to use
|
* @param searchColumns the search columns to use
|
||||||
* @param schema the datasource schema
|
* @param schema the datasource schema
|
||||||
*/
|
*/
|
||||||
export const enrichSearchColumns = async (searchColumns, schema) => {
|
export const enrichSearchColumns = async (
|
||||||
|
searchColumns: string[],
|
||||||
|
schema: Record<
|
||||||
|
string,
|
||||||
|
{
|
||||||
|
tableId: string
|
||||||
|
type: string
|
||||||
|
}
|
||||||
|
>
|
||||||
|
) => {
|
||||||
if (!searchColumns?.length || !schema) {
|
if (!searchColumns?.length || !schema) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
@ -61,12 +76,16 @@ export const enrichSearchColumns = async (searchColumns, schema) => {
|
||||||
* @param columns the enriched search column structure
|
* @param columns the enriched search column structure
|
||||||
* @param formId the ID of the form containing the search fields
|
* @param formId the ID of the form containing the search fields
|
||||||
*/
|
*/
|
||||||
export const enrichFilter = (filter, columns, formId) => {
|
export const enrichFilter = (
|
||||||
|
filter: UISearchFilter,
|
||||||
|
columns: UIColumn[],
|
||||||
|
formId: string
|
||||||
|
) => {
|
||||||
if (!columns?.length) {
|
if (!columns?.length) {
|
||||||
return filter
|
return filter
|
||||||
}
|
}
|
||||||
|
|
||||||
let newFilters = []
|
const newFilters: LegacyFilter[] = []
|
||||||
columns?.forEach(column => {
|
columns?.forEach(column => {
|
||||||
const safePath = column.name.split(".").map(safe).join(".")
|
const safePath = column.name.split(".").map(safe).join(".")
|
||||||
const stringType = column.type === "string" || column.type === "formula"
|
const stringType = column.type === "string" || column.type === "formula"
|
||||||
|
@ -99,7 +118,7 @@ export const enrichFilter = (filter, columns, formId) => {
|
||||||
newFilters.push({
|
newFilters.push({
|
||||||
field: column.name,
|
field: column.name,
|
||||||
type: column.type,
|
type: column.type,
|
||||||
operator: stringType ? "string" : "equal",
|
operator: stringType ? BasicOperator.STRING : BasicOperator.EQUAL,
|
||||||
valueType: "Binding",
|
valueType: "Binding",
|
||||||
value: `{{ ${binding} }}`,
|
value: `{{ ${binding} }}`,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue