diff --git a/packages/builder/src/stores/builder/components.js b/packages/builder/src/stores/builder/components.js index 0250ed6556..6c2c438f0c 100644 --- a/packages/builder/src/stores/builder/components.js +++ b/packages/builder/src/stores/builder/components.js @@ -206,9 +206,15 @@ export class ComponentStore extends BudiStore { setting?.type?.startsWith("filter") ) for (let setting of filterableTypes || []) { - enrichedComponent[setting.key] = utils.processSearchFilters( - enrichedComponent[setting.key] - ) + const isLegacy = Array.isArray(enrichedComponent[setting.key]) + + if (isLegacy) { + const processedSetting = utils.processSearchFilters( + enrichedComponent[setting.key] + ) + enrichedComponent[setting.key] = processedSetting + migrated = true + } } return migrated } @@ -575,9 +581,7 @@ export class ComponentStore extends BudiStore { const patchResult = patchFn(component, screen) // Post processing - const migrated = null - - this.migrateSettings(component) + const migrated = this.migrateSettings(component) // Returning an explicit false signifies that we should skip this // update. If we migrated something, ensure we never skip. diff --git a/packages/client/src/components/app/DataProvider.svelte b/packages/client/src/components/app/DataProvider.svelte index 7b90432bbf..a2ba674beb 100644 --- a/packages/client/src/components/app/DataProvider.svelte +++ b/packages/client/src/components/app/DataProvider.svelte @@ -19,9 +19,7 @@ let queryExtensions = {} let localFilters - $: if (filter) { - localFilters = Helpers.cloneDeep(filter) - } + $: localFilters = filter ? Helpers.cloneDeep(filter) : null $: defaultQuery = QueryUtils.buildQuery(localFilters) @@ -131,7 +129,7 @@ } const extendQuery = (defaultQuery, extensions) => { - return { + const extended = { [LogicalOperator.AND]: { conditions: [ ...(defaultQuery ? [defaultQuery] : []), @@ -140,6 +138,11 @@ }, onEmptyFilter: EmptyFilterOption.RETURN_NONE, } + + // If there are no conditions applied at all, clear the request. + return extended[LogicalOperator.AND]?.conditions?.length > 0 + ? extended + : null } const setUpAutoRefresh = autoRefresh => { diff --git a/packages/frontend-core/src/components/CoreFilterBuilder.svelte b/packages/frontend-core/src/components/CoreFilterBuilder.svelte index 405373e0a7..c711a57e1c 100644 --- a/packages/frontend-core/src/components/CoreFilterBuilder.svelte +++ b/packages/frontend-core/src/components/CoreFilterBuilder.svelte @@ -58,8 +58,13 @@ return { value: entry, label: Helpers.capitalise(entry) } }) + const onEmptyLabelling = { + [OnEmptyFilter.RETURN_ALL]: "All rows", + [OnEmptyFilter.RETURN_NONE]: "No rows", + } + const onEmptyOptions = Object.values(OnEmptyFilter).map(entry => { - return { value: entry, label: Helpers.capitalise(entry) } + return { value: entry, label: onEmptyLabelling[entry] } }) const context = getContext("context") @@ -151,7 +156,7 @@ const getGroupPrefix = groupIdx => { if (groupIdx == 0) { - return "Where" + return "When" } const operatorMapping = { [FilterOperator.ANY]: "or", @@ -191,16 +196,17 @@ if (targetFilter) { if (deleteFilter) { targetGroup.filters.splice(filterIdx, 1) + + // Clear the group entirely if no valid filters remain + if (targetGroup.filters.length === 0) { + editable.groups.splice(groupIdx, 1) + } } else if (filter) { targetGroup.filters[filterIdx] = filter } } else if (targetGroup) { if (deleteGroup) { - if (editable.groups.length > 1) { - editable.groups.splice(groupIdx, 1) - } else { - editable = {} - } + editable.groups.splice(groupIdx, 1) } else if (addFilter) { targetGroup.filters.push({ valueType: FilterValueType.VALUE, @@ -239,6 +245,9 @@ } } + // Set the request to null if the groups are emptied + editable = editable.groups.length ? editable : null + dispatch("change", editable) } @@ -294,7 +303,7 @@ placeholder={false} /> - of the following filters are met: + of the following filters are matched: