Merge pull request #14954 from Budibase/fix-filter-count-conditions

Fix issue counting number of filters when legacy structure is used
This commit is contained in:
Andrew Kingston 2024-11-04 16:48:58 +00:00 committed by GitHub
commit 52b48db5eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 8 deletions

View File

@ -5,13 +5,13 @@
Button,
Drawer,
DrawerContent,
Helpers,
} from "@budibase/bbui"
import { createEventDispatcher } from "svelte"
import { getDatasourceForProvider, getSchemaForDatasource } from "dataBinding"
import FilterBuilder from "./FilterBuilder.svelte"
import { tables, selectedScreen } from "stores/builder"
import { search } from "@budibase/frontend-core"
import { utils } from "@budibase/shared-core"
const dispatch = createEventDispatcher()
@ -22,7 +22,7 @@
let drawer
$: localFilters = Helpers.cloneDeep(value)
$: localFilters = value
$: datasource = getDatasourceForProvider($selectedScreen, componentInstance)
$: dsSchema = getSchemaForDatasource($selectedScreen, datasource)?.schema
$: schemaFields = search.getFields(
@ -30,8 +30,7 @@
Object.values(schema || dsSchema || {}),
{ allowLinks: true }
)
$: text = getText(value?.groups)
$: text = getText(value)
async function saveFilter() {
dispatch("change", localFilters)
@ -39,11 +38,14 @@
drawer.hide()
}
const getText = (filterGroups = []) => {
const allFilters = filterGroups.reduce((acc, group) => {
const getText = filters => {
if (Array.isArray(filters)) {
filters = utils.processSearchFilters(filters)
}
const groups = filters?.groups || []
const allFilters = groups.reduce((acc, group) => {
return (acc += group.filters.filter(filter => filter.field).length)
}, 0)
if (allFilters === 0) {
return "No filters set"
} else {
@ -62,7 +64,7 @@
on:drawerShow
on:drawerShow={() => {
// Reset to the currently available value.
localFilters = Helpers.cloneDeep(value)
localFilters = value
}}
>
<Button cta slot="buttons" on:click={saveFilter}>Save</Button>