Clean up dead code and improve behaviour when emptying filter config
This commit is contained in:
parent
1d3130f8cc
commit
162d0d0c7e
|
@ -39,13 +39,13 @@
|
|||
export let toReadable
|
||||
export let toRuntime
|
||||
|
||||
$: editableFilters = filters
|
||||
? Helpers.cloneDeep(filters)
|
||||
: {
|
||||
logicalOperator: FilterGroupLogicalOperator.ALL,
|
||||
onEmptyFilter: EmptyFilterOption.RETURN_NONE,
|
||||
groups: [],
|
||||
}
|
||||
const defaultConf = {
|
||||
logicalOperator: FilterGroupLogicalOperator.ALL,
|
||||
onEmptyFilter: EmptyFilterOption.RETURN_NONE,
|
||||
groups: [],
|
||||
}
|
||||
|
||||
$: editableFilters = filters ? Helpers.cloneDeep(filters) : null
|
||||
|
||||
$: {
|
||||
if (
|
||||
|
@ -191,7 +191,7 @@
|
|||
} = req
|
||||
|
||||
let editable = Helpers.cloneDeep(editableFilters)
|
||||
let targetGroup = editable.groups?.[groupIdx]
|
||||
let targetGroup = editable?.groups?.[groupIdx]
|
||||
let targetFilter = targetGroup?.filters?.[filterIdx]
|
||||
|
||||
if (targetFilter) {
|
||||
|
@ -202,7 +202,11 @@
|
|||
}
|
||||
} else if (targetGroup) {
|
||||
if (deleteGroup) {
|
||||
editable.groups.splice(groupIdx, 1)
|
||||
if (editable.groups.length > 1) {
|
||||
editable.groups.splice(groupIdx, 1)
|
||||
} else {
|
||||
editable = {}
|
||||
}
|
||||
} else if (addFilter) {
|
||||
targetGroup.filters.push({
|
||||
valueType: FilterValueType.VALUE,
|
||||
|
@ -214,6 +218,9 @@
|
|||
}
|
||||
}
|
||||
} else if (addGroup) {
|
||||
if (!editable) {
|
||||
editable = defaultConf
|
||||
}
|
||||
editable.groups.push({
|
||||
logicalOperator: Constants.FilterOperator.ANY,
|
||||
filters: [
|
||||
|
@ -381,7 +388,7 @@
|
|||
{/if}
|
||||
|
||||
<div class="filters-footer">
|
||||
{#if behaviourFilters && editableFilters?.groups.length}
|
||||
{#if behaviourFilters && editableFilters?.groups?.length}
|
||||
<div class="empty-filter">
|
||||
<span>Return</span>
|
||||
<span class="empty-filter-picker">
|
||||
|
|
|
@ -183,7 +183,7 @@ export default class DataFetch {
|
|||
}
|
||||
|
||||
// Build the query
|
||||
let query = this.features.supportsSearch ? this.options.query : null
|
||||
let query = this.options.query || null
|
||||
|
||||
if (!query && this.features.supportsSearch) {
|
||||
query = buildQuery(filter || defaultQuery)
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import { makePropSafe as safe } from "@budibase/string-templates"
|
||||
import { Helpers } from "@budibase/bbui"
|
||||
import * as Constants from "../constants"
|
||||
|
||||
export const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
|
||||
|
||||
|
@ -352,58 +351,3 @@ export const buildMultiStepFormBlockDefaultProps = props => {
|
|||
title,
|
||||
}
|
||||
}
|
||||
|
||||
export const handleFilterChange = (req, filters) => {
|
||||
const {
|
||||
groupIdx,
|
||||
filterIdx,
|
||||
filter,
|
||||
group,
|
||||
addFilter,
|
||||
addGroup,
|
||||
deleteGroup,
|
||||
deleteFilter,
|
||||
logicalOperator,
|
||||
onEmptyFilter,
|
||||
} = req
|
||||
|
||||
let editable = Helpers.cloneDeep(filters)
|
||||
let targetGroup = editable.groups?.[groupIdx]
|
||||
let targetFilter = targetGroup?.filters?.[filterIdx]
|
||||
|
||||
if (targetFilter) {
|
||||
if (deleteFilter) {
|
||||
targetGroup.filters.splice(filterIdx, 1)
|
||||
} else if (filter) {
|
||||
targetGroup.filters[filterIdx] = filter
|
||||
}
|
||||
} else if (targetGroup) {
|
||||
if (deleteGroup) {
|
||||
editable.groups.splice(groupIdx, 1)
|
||||
} else if (addFilter) {
|
||||
targetGroup.filters.push({})
|
||||
} else if (group) {
|
||||
editable.groups[groupIdx] = {
|
||||
...targetGroup,
|
||||
...group,
|
||||
}
|
||||
}
|
||||
} else if (addGroup) {
|
||||
editable.groups.push({
|
||||
logicalOperator: Constants.FilterOperator.ANY,
|
||||
filters: [{}],
|
||||
})
|
||||
} else if (logicalOperator) {
|
||||
editable = {
|
||||
...editable,
|
||||
logicalOperator,
|
||||
}
|
||||
} else if (onEmptyFilter) {
|
||||
editable = {
|
||||
...editable,
|
||||
onEmptyFilter,
|
||||
}
|
||||
}
|
||||
|
||||
return editable
|
||||
}
|
||||
|
|
|
@ -321,6 +321,11 @@ const builderFilter = (expression: SearchFilter) => {
|
|||
containsAny: {},
|
||||
}
|
||||
let { operator, field, type, value, externalType, onEmptyFilter } = expression
|
||||
|
||||
if (!operator || !field) {
|
||||
return
|
||||
}
|
||||
|
||||
const queryOperator = operator as SearchFilterOperator
|
||||
const isHbs =
|
||||
typeof value === "string" && (value.match(HBS_REGEX) || []).length > 0
|
||||
|
@ -446,7 +451,9 @@ export const buildQuery = (filter: SearchFilterGroup | SearchFilter[]) => {
|
|||
conditions: parsedFilter.groups?.map((group: SearchFilterGroup) => {
|
||||
return {
|
||||
[operatorMap[group.logicalOperator]]: {
|
||||
conditions: group.filters?.map(x => builderFilter(x)),
|
||||
conditions: group.filters
|
||||
?.map(x => builderFilter(x))
|
||||
.filter(filter => filter),
|
||||
},
|
||||
}
|
||||
}),
|
||||
|
|
|
@ -182,7 +182,7 @@ export const processSearchFilters = (
|
|||
|
||||
return migratedSetting
|
||||
} else if (!filters?.groups) {
|
||||
return defaultCfg
|
||||
return null
|
||||
}
|
||||
return filters
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue