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