diff --git a/packages/builder/src/stores/builder/viewsV2.js b/packages/builder/src/stores/builder/viewsV2.js index 9bd32f4a24..a3ceb623a9 100644 --- a/packages/builder/src/stores/builder/viewsV2.js +++ b/packages/builder/src/stores/builder/viewsV2.js @@ -1,6 +1,23 @@ import { writable, derived, get } from "svelte/store" import { tables } from "./tables" import { API } from "api" +import { dataFilters } from "@budibase/shared-core" + +function convertToSearchFilters(view) { + // convert from SearchFilterGroup type + if (view.query) { + view.queryUI = view.query + view.query = dataFilters.buildQuery(view.query) + } + return view +} + +function convertToSearchFilterGroup(view) { + if (view.queryUI) { + view.query = view.queryUI + } + return view +} export function createViewsV2Store() { const store = writable({ @@ -12,7 +29,7 @@ export function createViewsV2Store() { const views = Object.values(table?.views || {}).filter(view => { return view.version === 2 }) - list = list.concat(views) + list = list.concat(views.map(view => convertToSearchFilterGroup(view))) }) return { ...$store, @@ -34,6 +51,7 @@ 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) @@ -41,6 +59,7 @@ 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) @@ -51,6 +70,7 @@ export function createViewsV2Store() { if (!viewId) { return } + view = convertToSearchFilterGroup(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 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 bf5e7c2628..13c46f9d34 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/viewV2.js +++ b/packages/frontend-core/src/components/grid/stores/datasources/viewV2.js @@ -1,4 +1,14 @@ import { get } from "svelte/store" +import { dataFilters } from "@budibase/shared-core" + +function convertToSearchFilters(view) { + // convert from SearchFilterGroup type + if (view.query) { + view.queryUI = view.query + view.query = dataFilters.buildQuery(view.query) + } + return view +} const SuppressErrors = true @@ -6,7 +16,7 @@ export const createActions = context => { const { API, datasource, columns } = context const saveDefinition = async newDefinition => { - await API.viewV2.update(newDefinition) + await API.viewV2.update(convertToSearchFilters(newDefinition)) } const saveRow = async row => {