From 60c55b06eddd7188a51864e83a05cb47d52a661b Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 27 Sep 2024 10:39:50 +0100 Subject: [PATCH 01/37] Update new view popover to allow for creating calculation views --- packages/bbui/src/List/ListItem.svelte | 75 ++++++++++++++++--- .../components/common/DetailPopover.svelte | 5 +- .../_components/CreateViewButton.svelte | 32 +++++++- packages/types/src/documents/app/view.ts | 1 + 4 files changed, 99 insertions(+), 14 deletions(-) diff --git a/packages/bbui/src/List/ListItem.svelte b/packages/bbui/src/List/ListItem.svelte index 5b6152781a..ee6e325921 100644 --- a/packages/bbui/src/List/ListItem.svelte +++ b/packages/bbui/src/List/ListItem.svelte @@ -8,17 +8,22 @@ export let url = null export let hoverable = false export let showArrow = false + export let selected = false -
+
{#if icon} - +
+ +
{/if}
{#if title} @@ -33,7 +38,7 @@ {/if}
-
+
{#if showArrow} @@ -49,9 +54,12 @@ flex-direction: row; justify-content: space-between; border: 1px solid var(--spectrum-global-color-gray-300); - transition: background 130ms ease-out; + transition: background 130ms ease-out, border-color 130ms ease-out; gap: var(--spacing-m); color: var(--spectrum-global-color-gray-800); + cursor: pointer; + position: relative; + box-sizing: border-box; } .list-item:not(:first-child) { border-top: none; @@ -64,27 +72,71 @@ border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; } - .hoverable:hover { - cursor: pointer; + .list-item.hoverable:not(.selected):hover { background: var(--spectrum-global-color-gray-200); + border-color: var(--spectrum-global-color-gray-400); } - .left, - .right { + /* Selection is only meant for standalone list items (non stacked) so we just set a fixed border radius */ + .list-item.selected { + background-color: var(--spectrum-global-color-blue-100); + border-color: var(--spectrum-global-color-blue-100); + } + .list-item.selected:after { + content: ""; + position: absolute; + height: 100%; + width: 100%; + border: 1px solid var(--spectrum-global-color-blue-400); + pointer-events: none; + top: 0; + left: 0; + border-radius: 4px; + box-sizing: border-box; + z-index: 1; + opacity: 0.5; + } + + /* Large icons */ + .list-item.large .list-item__icon { + background-color: var(--spectrum-global-color-gray-200); + padding: 4px; + border-radius: 4px; + border: 1px solid var(--spectrum-global-color-gray-300); + transition: background-color 130ms ease-out, border-color 130ms ease-out, + color 130ms ease-out; + } + .list-item.large.hoverable:not(.selected):hover .list-item__icon { + background-color: var(--spectrum-global-color-gray-300); + } + .list-item.large.selected .list-item__icon { + background-color: var(--spectrum-global-color-blue-400); + color: white; + border-color: var(--spectrum-global-color-blue-100); + } + + /* Internal layout */ + .list-item__left, + .list-item__right { display: flex; flex-direction: row; align-items: center; gap: var(--spacing-s); } - .left { + .list-item.large .list-item__left, + .list-item.large .list-item__right { + gap: var(--spacing-m); + } + .list-item__left { width: 0; flex: 1 1 auto; } - .right { + .list-item__right { flex: 0 0 auto; color: var(--spectrum-global-color-gray-600); } + /* Text */ .list-item__text { flex: 1 1 auto; width: 0; @@ -96,6 +148,7 @@ text-overflow: ellipsis; } .list-item__subtitle { - color: var(--spectrum-global-color-gray-600); + color: var(--spectrum-global-color-gray-700); + font-size: 12px; } diff --git a/packages/builder/src/components/common/DetailPopover.svelte b/packages/builder/src/components/common/DetailPopover.svelte index bc891bfe42..c437804b33 100644 --- a/packages/builder/src/components/common/DetailPopover.svelte +++ b/packages/builder/src/components/common/DetailPopover.svelte @@ -4,6 +4,7 @@ export let title export let align = "left" export let showPopover + export let width let popover let anchor @@ -22,8 +23,8 @@ import DetailPopover from "components/common/DetailPopover.svelte" - import { Input, notifications, Button, Icon } from "@budibase/bbui" + import { Input, notifications, Button, Icon, ListItem } from "@budibase/bbui" import { goto } from "@roxi/routify" import { viewsV2 } from "stores/builder" export let table export let firstView = false + let calculation = false let name let popover @@ -39,6 +40,7 @@ tableId: table._id, schema: enrichSchema(table.schema), primaryDisplay: table.primaryDisplay, + calculation, }) notifications.success(`View ${name} created`) $goto(`./${newView.id}`) @@ -52,6 +54,7 @@ title="Create view" bind:this={popover} on:open={() => (name = null)} + width={540} > {#if firstView} @@ -66,6 +69,28 @@
{/if} +
+
+ (calculation = false)} + selected={!calculation} + icon="Rail" + /> +
+
+ (calculation = true)} + selected={calculation} + icon="123" + /> +
+
From 6d294be646543fce3b2094502fe5037b280e3679 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 9 Oct 2024 09:45:47 +0100 Subject: [PATCH 08/37] Add saving of calculation view updates --- .../grid/GridViewCalculationButton.svelte | 32 ++++++++++++------- .../_components/CreateViewButton.svelte | 2 +- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/buttons/grid/GridViewCalculationButton.svelte b/packages/builder/src/components/backend/DataTable/buttons/grid/GridViewCalculationButton.svelte index 96a7d0ef8c..3644a846ba 100644 --- a/packages/builder/src/components/backend/DataTable/buttons/grid/GridViewCalculationButton.svelte +++ b/packages/builder/src/components/backend/DataTable/buttons/grid/GridViewCalculationButton.svelte @@ -41,7 +41,7 @@ const open = () => { calculations = extractCalculations(schema) - groupings = extractGroupings(schema) + groupings = calculations.length ? extractGroupings(schema) : [] modal?.show() } @@ -138,18 +138,26 @@ const save = async () => { let schema = {} - const rand = ("" + Math.random()).substring(2) + // Add calculations + for (let calc of calculations) { + const name = `${calc.type} of ${calc.field}` + schema[name] = { + calculationType: calc.type, + field: calc.field, + visible: true, + } + } + + // Add groupings + for (let grouping of groupings) { + schema[grouping.field] = { + visible: true, + } + } await datasource.actions.saveDefinition({ ...$definition, primaryDisplay: null, - schema: { - ["Average game length " + rand]: { - visible: true, - calculationType: CalculationType.AVG, - field: "Game Length", - width: 300, - }, - }, + schema, }) await rows.actions.refreshData() } @@ -168,7 +176,9 @@ > {#if !calculations.length}
- Add your first calculation + + Add your first calculation +
{:else}
diff --git a/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/_components/CreateViewButton.svelte b/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/_components/CreateViewButton.svelte index 253c386b9e..e531e54d87 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/_components/CreateViewButton.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/_components/CreateViewButton.svelte @@ -39,7 +39,7 @@ const newView = await viewsV2.create({ name: trimmedName, tableId: table._id, - schema: enrichSchema(table.schema), + schema: calculation ? {} : enrichSchema(table.schema), primaryDisplay: calculation ? undefined : table.primaryDisplay, type: calculation ? ViewV2Type.CALCULATION : undefined, }) From f3b601d2943e8e4425aaf0039d873c3a8cf768f4 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 10 Oct 2024 14:37:10 +0100 Subject: [PATCH 09/37] Improve view calculation configuration --- .../grid/GridViewCalculationButton.svelte | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/builder/src/components/backend/DataTable/buttons/grid/GridViewCalculationButton.svelte b/packages/builder/src/components/backend/DataTable/buttons/grid/GridViewCalculationButton.svelte index 3644a846ba..6ccabaaf43 100644 --- a/packages/builder/src/components/backend/DataTable/buttons/grid/GridViewCalculationButton.svelte +++ b/packages/builder/src/components/backend/DataTable/buttons/grid/GridViewCalculationButton.svelte @@ -125,6 +125,11 @@ const deleteCalc = idx => { calculations = calculations.toSpliced(idx, 1) + + // Remove any groupings if clearing the last calculation + if (!calculations.length) { + groupings = [] + } } const addGrouping = () => { @@ -138,6 +143,10 @@ const save = async () => { let schema = {} + // Prune empty stuff + calculations = calculations.filter(calc => calc.type && calc.field) + groupings = groupings.filter(grouping => grouping.field) + // Add calculations for (let calc of calculations) { const name = `${calc.type} of ${calc.field}` @@ -154,9 +163,18 @@ visible: true, } } + + // Ensure primary display is visible + let primaryDisplay = $definition.primaryDisplay + if (!primaryDisplay || !schema[primaryDisplay]) { + primaryDisplay = groupings[0]?.field + } + console.log("pd", primaryDisplay, groupings) + + // Save changes await datasource.actions.saveDefinition({ ...$definition, - primaryDisplay: null, + primaryDisplay, schema, }) await rows.actions.refreshData() From bf1bf1956adc1eba06150b43f9625f86ac494784 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 10 Oct 2024 14:42:52 +0100 Subject: [PATCH 10/37] Fix edge cases when saving view calcultion schema --- .../buttons/grid/GridViewCalculationButton.svelte | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/buttons/grid/GridViewCalculationButton.svelte b/packages/builder/src/components/backend/DataTable/buttons/grid/GridViewCalculationButton.svelte index 6ccabaaf43..f147179bc2 100644 --- a/packages/builder/src/components/backend/DataTable/buttons/grid/GridViewCalculationButton.svelte +++ b/packages/builder/src/components/backend/DataTable/buttons/grid/GridViewCalculationButton.svelte @@ -12,7 +12,7 @@ const { definition, datasource, rows } = getContext("grid") const calculationTypeOptions = [ { - label: "Average (mean)", + label: "Average", value: CalculationType.AVG, }, { @@ -149,7 +149,8 @@ // Add calculations for (let calc of calculations) { - const name = `${calc.type} of ${calc.field}` + const typeOption = calculationTypeOptions.find(x => x.value === calc.type) + const name = `${typeOption.label} ${calc.field}` schema[name] = { calculationType: calc.type, field: calc.field, @@ -160,16 +161,16 @@ // Add groupings for (let grouping of groupings) { schema[grouping.field] = { + ...$definition.schema[grouping.field], visible: true, } } - // Ensure primary display is visible + // Ensure primary display is valid let primaryDisplay = $definition.primaryDisplay if (!primaryDisplay || !schema[primaryDisplay]) { primaryDisplay = groupings[0]?.field } - console.log("pd", primaryDisplay, groupings) // Save changes await datasource.actions.saveDefinition({ From 1cbae366834fc0380d3e1617f950ad8b0fb4fb36 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 10 Oct 2024 14:52:13 +0100 Subject: [PATCH 11/37] Don't bother fetching data if no calculations defined --- .../src/components/grid/stores/columns.js | 1 - packages/frontend-core/src/fetch/ViewV2Fetch.js | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/frontend-core/src/components/grid/stores/columns.js b/packages/frontend-core/src/components/grid/stores/columns.js index 36fb6659a9..4358deeb2c 100644 --- a/packages/frontend-core/src/components/grid/stores/columns.js +++ b/packages/frontend-core/src/components/grid/stores/columns.js @@ -164,7 +164,6 @@ export const initialise = context => { } // Override a few properties for primary display if (field === primaryDisplay) { - column.visible = true column.order = 0 column.primaryDisplay = true } diff --git a/packages/frontend-core/src/fetch/ViewV2Fetch.js b/packages/frontend-core/src/fetch/ViewV2Fetch.js index 40135746df..6bfef0927f 100644 --- a/packages/frontend-core/src/fetch/ViewV2Fetch.js +++ b/packages/frontend-core/src/fetch/ViewV2Fetch.js @@ -1,3 +1,4 @@ +import { ViewV2Type } from "@budibase/types" import DataFetch from "./DataFetch.js" import { get } from "svelte/store" @@ -39,6 +40,19 @@ export default class ViewV2Fetch extends DataFetch { this.options const { cursor, query, definition } = get(this.store) + // If this is a calculation view and we have no calculations, return nothing + if ( + definition.type === ViewV2Type.CALCULATION && + !Object.values(definition.schema || {}).some(x => x.calculationType) + ) { + return { + rows: [], + hasNextPage: false, + cursor: null, + error: null, + } + } + // If sort/filter params are not defined, update options to store the // params built in to this view. This ensures that we can accurately // compare old and new params and skip a redundant API call. @@ -67,6 +81,7 @@ export default class ViewV2Fetch extends DataFetch { return { rows: [], hasNextPage: false, + cursor: null, error, } } From 88b2f423f781016b5270b5c5ab171f002aee8872 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 10 Oct 2024 16:05:02 +0100 Subject: [PATCH 12/37] Improve UX when editing view calculations --- packages/bbui/src/Modal/ModalContent.svelte | 3 + .../grid/GridViewCalculationButton.svelte | 119 +++++++++--------- .../_components/Component/InfoDisplay.svelte | 12 +- 3 files changed, 69 insertions(+), 65 deletions(-) diff --git a/packages/bbui/src/Modal/ModalContent.svelte b/packages/bbui/src/Modal/ModalContent.svelte index 22a14c358f..8a80b2fdb9 100644 --- a/packages/bbui/src/Modal/ModalContent.svelte +++ b/packages/bbui/src/Modal/ModalContent.svelte @@ -147,6 +147,9 @@ .spectrum-Dialog--extraLarge { width: 1000px; } + .spectrum-Dialog--medium { + width: 540px; + } .content-grid { display: grid; diff --git a/packages/builder/src/components/backend/DataTable/buttons/grid/GridViewCalculationButton.svelte b/packages/builder/src/components/backend/DataTable/buttons/grid/GridViewCalculationButton.svelte index f147179bc2..b61163c5ce 100644 --- a/packages/builder/src/components/backend/DataTable/buttons/grid/GridViewCalculationButton.svelte +++ b/packages/builder/src/components/backend/DataTable/buttons/grid/GridViewCalculationButton.svelte @@ -5,8 +5,10 @@ ModalContent, Select, Icon, + Multiselect, } from "@budibase/bbui" - import { CalculationType, FieldType } from "@budibase/types" + import { CalculationType, canGroupBy, FieldType } from "@budibase/types" + import InfoDisplay from "pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Component/InfoDisplay.svelte" import { getContext } from "svelte" const { definition, datasource, rows } = getContext("grid") @@ -35,13 +37,16 @@ let modal let calculations = [] - let groupings = [] + let groupBy = [] + let schema = {} $: schema = $definition?.schema || {} + $: count = extractCalculations($definition?.schema || {}).length + $: groupByOptions = getGroupByOptions(schema) const open = () => { calculations = extractCalculations(schema) - groupings = calculations.length ? extractGroupings(schema) : [] + groupBy = calculations.length ? extractGroupBy(schema) : [] modal?.show() } @@ -59,15 +64,13 @@ })) } - const extractGroupings = schema => { + const extractGroupBy = schema => { if (!schema) { return [] } - return Object.keys(schema) - .filter(field => { - return schema[field].calculationType == null && schema[field].visible - }) - .map(field => ({ field })) + return Object.keys(schema).filter(field => { + return schema[field].calculationType == null && schema[field].visible + }) } // Gets the available types for a given calculation @@ -103,18 +106,16 @@ .map(([field]) => field) } - // Gets the available fields to group by for a given grouping - const getGroupingOptions = (self, groupings, schema) => { + // Gets the available fields to group by + const getGroupByOptions = schema => { return Object.entries(schema) .filter(([field, fieldSchema]) => { // Don't allow grouping by calculations if (fieldSchema.calculationType) { return false } - // Don't allow duplicates - return !groupings.some(grouping => { - return grouping !== self && grouping.field === field - }) + // Don't allow complex types + return canGroupBy(fieldSchema.type) }) .map(([field]) => field) } @@ -126,71 +127,65 @@ const deleteCalc = idx => { calculations = calculations.toSpliced(idx, 1) - // Remove any groupings if clearing the last calculation + // Remove any grouping if clearing the last calculation if (!calculations.length) { - groupings = [] + groupBy = [] } } - const addGrouping = () => { - groupings = [...groupings, {}] - } - - const deleteGrouping = idx => { - groupings = groupings.toSpliced(idx, 1) - } - const save = async () => { - let schema = {} - - // Prune empty stuff - calculations = calculations.filter(calc => calc.type && calc.field) - groupings = groupings.filter(grouping => grouping.field) + let newSchema = {} // Add calculations for (let calc of calculations) { + if (!calc.type || !calc.field) { + continue + } const typeOption = calculationTypeOptions.find(x => x.value === calc.type) const name = `${typeOption.label} ${calc.field}` - schema[name] = { + newSchema[name] = { calculationType: calc.type, field: calc.field, visible: true, } } - // Add groupings - for (let grouping of groupings) { - schema[grouping.field] = { - ...$definition.schema[grouping.field], - visible: true, + // Add other fields + for (let field of Object.keys(schema)) { + if (schema[field].calculationType) { + continue + } + newSchema[field] = { + ...schema[field], + visible: groupBy.includes(field), } } // Ensure primary display is valid let primaryDisplay = $definition.primaryDisplay - if (!primaryDisplay || !schema[primaryDisplay]) { - primaryDisplay = groupings[0]?.field + if (!primaryDisplay || !newSchema[primaryDisplay]?.visible) { + primaryDisplay = groupBy[0] } // Save changes await datasource.actions.saveDefinition({ ...$definition, primaryDisplay, - schema, + schema: newSchema, }) await rows.actions.refreshData() } - Configure calculations + Configure calculations{count ? `: ${count}` : ""} {#if !calculations.length} @@ -222,32 +217,30 @@ color="var(--spectrum-global-color-gray-700)" /> {/each} - {#each groupings as group, idx} - {idx === 0 ? "Group by" : "and"} - of Date: Wed, 23 Oct 2024 15:06:57 +0100 Subject: [PATCH 27/37] Update usages of queryUI and ensure processSearchFilters isn't called with nullish values --- .../SetupPanel/AutomationBlockSetup.svelte | 2 +- .../buttons/TableFilterButton.svelte | 4 +-- .../buttons/grid/GridFilterButton.svelte | 2 ++ .../builder/src/stores/builder/components.js | 2 +- .../builder/src/stores/builder/viewsV2.js | 27 +------------------ .../grid/stores/datasources/viewV2.js | 18 +++---------- 6 files changed, 10 insertions(+), 45 deletions(-) diff --git a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte index cbac1bf2ff..28872dcace 100644 --- a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte +++ b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte @@ -798,7 +798,7 @@ break } } - return utils.processSearchFilters(filters) + return utils.processSearchFilters(filters || []) } function saveFilters(key) { diff --git a/packages/builder/src/components/backend/DataTable/buttons/TableFilterButton.svelte b/packages/builder/src/components/backend/DataTable/buttons/TableFilterButton.svelte index e616e27467..68d2ad4447 100644 --- a/packages/builder/src/components/backend/DataTable/buttons/TableFilterButton.svelte +++ b/packages/builder/src/components/backend/DataTable/buttons/TableFilterButton.svelte @@ -17,7 +17,7 @@ let drawer - $: localFilters = utils.processSearchFilters(filters) + $: localFilters = utils.processSearchFilters(filters || []) $: schemaFields = search.getFields( $tables.list, @@ -61,7 +61,7 @@ title="Filtering" on:drawerHide on:drawerShow={() => { - localFilters = utils.processSearchFilters(filters) + localFilters = utils.processSearchFilters(filters || []) }} forceModal > diff --git a/packages/builder/src/components/backend/DataTable/buttons/grid/GridFilterButton.svelte b/packages/builder/src/components/backend/DataTable/buttons/grid/GridFilterButton.svelte index f927f84876..ea083add87 100644 --- a/packages/builder/src/components/backend/DataTable/buttons/grid/GridFilterButton.svelte +++ b/packages/builder/src/components/backend/DataTable/buttons/grid/GridFilterButton.svelte @@ -7,6 +7,8 @@ const onFilter = e => { filter.set(e.detail || []) } + + $: console.log($filter) {#key $datasource} diff --git a/packages/builder/src/stores/builder/components.js b/packages/builder/src/stores/builder/components.js index 6c2c438f0c..166122c885 100644 --- a/packages/builder/src/stores/builder/components.js +++ b/packages/builder/src/stores/builder/components.js @@ -210,7 +210,7 @@ export class ComponentStore extends BudiStore { if (isLegacy) { const processedSetting = utils.processSearchFilters( - enrichedComponent[setting.key] + enrichedComponent[setting.key] || [] ) enrichedComponent[setting.key] = processedSetting migrated = true diff --git a/packages/builder/src/stores/builder/viewsV2.js b/packages/builder/src/stores/builder/viewsV2.js index 3d67686344..70af03e75f 100644 --- a/packages/builder/src/stores/builder/viewsV2.js +++ b/packages/builder/src/stores/builder/viewsV2.js @@ -3,29 +3,6 @@ import { tables } from "./tables" import { API } from "api" import { dataFilters } from "@budibase/shared-core" -function convertToSearchFilters(view) { - // convert from UISearchFilter type - if (view?.query) { - return { - ...view, - queryUI: view.query, - query: dataFilters.buildQuery(view.query), - } - } - return view -} - -function convertToUISearchFilter(view) { - if (view?.queryUI) { - return { - ...view, - query: view.queryUI, - queryUI: undefined, - } - } - return view -} - export function createViewsV2Store() { const store = writable({ selectedViewId: null, @@ -36,7 +13,7 @@ export function createViewsV2Store() { const views = Object.values(table?.views || {}).filter(view => { return view.version === 2 }) - list = list.concat(views.map(view => convertToUISearchFilter(view))) + list = list.concat(views) }) return { ...$store, @@ -58,7 +35,6 @@ export function createViewsV2Store() { } const create = async view => { - view = convertToSearchFilters(view) const savedViewResponse = await API.viewV2.create(view) const savedView = savedViewResponse.data replaceView(savedView.id, savedView) @@ -66,7 +42,6 @@ export function createViewsV2Store() { } const save = async view => { - view = convertToSearchFilters(view) const res = await API.viewV2.update(view) const savedView = res?.data replaceView(view.id, savedView) diff --git a/packages/frontend-core/src/components/grid/stores/datasources/viewV2.js b/packages/frontend-core/src/components/grid/stores/datasources/viewV2.js index 56a7479b44..281443cbc3 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/viewV2.js +++ b/packages/frontend-core/src/components/grid/stores/datasources/viewV2.js @@ -1,25 +1,13 @@ import { get } from "svelte/store" import { dataFilters } from "@budibase/shared-core" -function convertToSearchFilters(view) { - // convert from SearchFilterGroup type - if (view?.query) { - return { - ...view, - queryUI: view.query, - query: dataFilters.buildQuery(view.query), - } - } - return view -} - const SuppressErrors = true export const createActions = context => { const { API, datasource, columns } = context const saveDefinition = async newDefinition => { - await API.viewV2.update(convertToSearchFilters(newDefinition)) + await API.viewV2.update(newDefinition) } const saveRow = async row => { @@ -138,7 +126,7 @@ export const initialise = context => { } // Only override filter state if we don't have an initial filter if (!get(initialFilter)) { - filter.set($definition.queryUI || $definition.query) + filter.set($definition.queryUI) } }) ) @@ -197,7 +185,7 @@ export const initialise = context => { if (JSON.stringify($filter) !== JSON.stringify($view.queryUI)) { await datasource.actions.saveDefinition({ ...$view, - query: $filter, + queryUI: $filter, }) // Refresh data since view definition changed From de26d151af24450485d3b9a3635f155cccab1364 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 23 Oct 2024 15:07:19 +0100 Subject: [PATCH 28/37] Remove log --- .../backend/DataTable/buttons/TableFilterButton.svelte | 3 --- .../backend/DataTable/buttons/grid/GridFilterButton.svelte | 2 -- 2 files changed, 5 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/buttons/TableFilterButton.svelte b/packages/builder/src/components/backend/DataTable/buttons/TableFilterButton.svelte index 68d2ad4447..5bd1a675b5 100644 --- a/packages/builder/src/components/backend/DataTable/buttons/TableFilterButton.svelte +++ b/packages/builder/src/components/backend/DataTable/buttons/TableFilterButton.svelte @@ -18,18 +18,15 @@ let drawer $: localFilters = utils.processSearchFilters(filters || []) - $: schemaFields = search.getFields( $tables.list, Object.values(schema || {}), { allowLinks: true } ) - $: filterCount = localFilters?.groups?.reduce((acc, group) => { return (acc += group.filters.filter(filter => filter.field).length) }, 0) || 0 - $: bindings = [ { type: "context", diff --git a/packages/builder/src/components/backend/DataTable/buttons/grid/GridFilterButton.svelte b/packages/builder/src/components/backend/DataTable/buttons/grid/GridFilterButton.svelte index ea083add87..f927f84876 100644 --- a/packages/builder/src/components/backend/DataTable/buttons/grid/GridFilterButton.svelte +++ b/packages/builder/src/components/backend/DataTable/buttons/grid/GridFilterButton.svelte @@ -7,8 +7,6 @@ const onFilter = e => { filter.set(e.detail || []) } - - $: console.log($filter) {#key $datasource} From 6ac6db706dff2378ae13067a936db62e2780ea9c Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 23 Oct 2024 16:10:57 +0100 Subject: [PATCH 29/37] Revert default param --- .../automation/SetupPanel/AutomationBlockSetup.svelte | 2 +- .../backend/DataTable/buttons/TableFilterButton.svelte | 4 ++-- packages/builder/src/stores/builder/components.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte index 28872dcace..cbac1bf2ff 100644 --- a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte +++ b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte @@ -798,7 +798,7 @@ break } } - return utils.processSearchFilters(filters || []) + return utils.processSearchFilters(filters) } function saveFilters(key) { diff --git a/packages/builder/src/components/backend/DataTable/buttons/TableFilterButton.svelte b/packages/builder/src/components/backend/DataTable/buttons/TableFilterButton.svelte index 5bd1a675b5..74b7d06ea5 100644 --- a/packages/builder/src/components/backend/DataTable/buttons/TableFilterButton.svelte +++ b/packages/builder/src/components/backend/DataTable/buttons/TableFilterButton.svelte @@ -17,7 +17,7 @@ let drawer - $: localFilters = utils.processSearchFilters(filters || []) + $: localFilters = utils.processSearchFilters(filters) $: schemaFields = search.getFields( $tables.list, Object.values(schema || {}), @@ -58,7 +58,7 @@ title="Filtering" on:drawerHide on:drawerShow={() => { - localFilters = utils.processSearchFilters(filters || []) + localFilters = utils.processSearchFilters(filters) }} forceModal > diff --git a/packages/builder/src/stores/builder/components.js b/packages/builder/src/stores/builder/components.js index 166122c885..6c2c438f0c 100644 --- a/packages/builder/src/stores/builder/components.js +++ b/packages/builder/src/stores/builder/components.js @@ -210,7 +210,7 @@ export class ComponentStore extends BudiStore { if (isLegacy) { const processedSetting = utils.processSearchFilters( - enrichedComponent[setting.key] || [] + enrichedComponent[setting.key] ) enrichedComponent[setting.key] = processedSetting migrated = true From b6dbe542361874ebdefa3bc6687b2fc74d0b3ac3 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 23 Oct 2024 16:12:21 +0100 Subject: [PATCH 30/37] Remove old reference to deleted code --- packages/builder/src/stores/builder/viewsV2.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/builder/src/stores/builder/viewsV2.js b/packages/builder/src/stores/builder/viewsV2.js index 70af03e75f..43c94770ab 100644 --- a/packages/builder/src/stores/builder/viewsV2.js +++ b/packages/builder/src/stores/builder/viewsV2.js @@ -52,7 +52,6 @@ export function createViewsV2Store() { if (!viewId) { return } - view = convertToUISearchFilter(view) const existingView = get(derivedStore).list.find(view => view.id === viewId) const tableIndex = get(tables).list.findIndex(table => { return table._id === view?.tableId || table._id === existingView?.tableId From c8c5cbe16ccbac9123009c656a8bbc4ed3cedada Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 23 Oct 2024 16:24:02 +0100 Subject: [PATCH 31/37] Update more usages of processing search filters --- .../SetupPanel/AutomationBlockSetup.svelte | 4 +++- .../DataTable/buttons/TableFilterButton.svelte | 13 ++----------- packages/builder/src/stores/builder/components.js | 1 - .../src/components/CoreFilterBuilder.svelte | 14 ++++++++++++-- .../components/grid/stores/datasources/viewV2.js | 1 + 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte index cbac1bf2ff..b422154290 100644 --- a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte +++ b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte @@ -798,7 +798,9 @@ break } } - return utils.processSearchFilters(filters) + return Array.isArray(filters) + ? utils.processSearchFilters(filters) + : filters } function saveFilters(key) { diff --git a/packages/builder/src/components/backend/DataTable/buttons/TableFilterButton.svelte b/packages/builder/src/components/backend/DataTable/buttons/TableFilterButton.svelte index 74b7d06ea5..ca4c76c968 100644 --- a/packages/builder/src/components/backend/DataTable/buttons/TableFilterButton.svelte +++ b/packages/builder/src/components/backend/DataTable/buttons/TableFilterButton.svelte @@ -5,7 +5,6 @@ import { getUserBindings } from "dataBinding" import { makePropSafe } from "@budibase/string-templates" import { search } from "@budibase/frontend-core" - import { utils } from "@budibase/shared-core" import { tables } from "stores/builder" export let schema @@ -17,7 +16,7 @@ let drawer - $: localFilters = utils.processSearchFilters(filters) + $: localFilters = filters $: schemaFields = search.getFields( $tables.list, Object.values(schema || {}), @@ -53,15 +52,7 @@ {filterCount ? `Filter: ${filterCount}` : "Filter"} - { - localFilters = utils.processSearchFilters(filters) - }} - forceModal -> +