Merge pull request #15026 from Budibase/fix/block-native-searching
Fix block native search
This commit is contained in:
commit
1a65ef3e4b
|
@ -1,5 +1,7 @@
|
||||||
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 { OnEmptyFilter } from "@budibase/frontend-core/src/constants.js"
|
||||||
|
|
||||||
// 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 = {
|
||||||
|
@ -60,7 +62,11 @@ export const enrichSearchColumns = async (searchColumns, schema) => {
|
||||||
* @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, columns, formId) => {
|
||||||
let enrichedFilter = [...(filter || [])]
|
if (!columns?.length) {
|
||||||
|
return filter
|
||||||
|
}
|
||||||
|
|
||||||
|
let newFilters = []
|
||||||
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"
|
||||||
|
@ -69,7 +75,7 @@ export const enrichFilter = (filter, columns, formId) => {
|
||||||
|
|
||||||
// For dates, use a range of the entire day selected
|
// For dates, use a range of the entire day selected
|
||||||
if (dateType) {
|
if (dateType) {
|
||||||
enrichedFilter.push({
|
newFilters.push({
|
||||||
field: column.name,
|
field: column.name,
|
||||||
type: column.type,
|
type: column.type,
|
||||||
operator: "rangeLow",
|
operator: "rangeLow",
|
||||||
|
@ -79,7 +85,7 @@ export const enrichFilter = (filter, columns, formId) => {
|
||||||
const format = "YYYY-MM-DDTHH:mm:ss.SSSZ"
|
const format = "YYYY-MM-DDTHH:mm:ss.SSSZ"
|
||||||
let hbs = `{{ date (add (date ${binding} "x") 86399999) "${format}" }}`
|
let hbs = `{{ date (add (date ${binding} "x") 86399999) "${format}" }}`
|
||||||
hbs = `{{#if ${binding} }}${hbs}{{/if}}`
|
hbs = `{{#if ${binding} }}${hbs}{{/if}}`
|
||||||
enrichedFilter.push({
|
newFilters.push({
|
||||||
field: column.name,
|
field: column.name,
|
||||||
type: column.type,
|
type: column.type,
|
||||||
operator: "rangeHigh",
|
operator: "rangeHigh",
|
||||||
|
@ -90,7 +96,7 @@ export const enrichFilter = (filter, columns, formId) => {
|
||||||
|
|
||||||
// For other fields, do an exact match
|
// For other fields, do an exact match
|
||||||
else {
|
else {
|
||||||
enrichedFilter.push({
|
newFilters.push({
|
||||||
field: column.name,
|
field: column.name,
|
||||||
type: column.type,
|
type: column.type,
|
||||||
operator: stringType ? "string" : "equal",
|
operator: stringType ? "string" : "equal",
|
||||||
|
@ -99,5 +105,16 @@ export const enrichFilter = (filter, columns, formId) => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return enrichedFilter
|
|
||||||
|
return {
|
||||||
|
logicalOperator: UILogicalOperator.ALL,
|
||||||
|
onEmptyFilter: OnEmptyFilter.RETURN_ALL,
|
||||||
|
groups: [
|
||||||
|
...(filter?.groups || []),
|
||||||
|
{
|
||||||
|
logicalOperator: UILogicalOperator.ALL,
|
||||||
|
filters: newFilters,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue