Updating view stores.
This commit is contained in:
parent
786bfdb0e2
commit
2fed6008fa
|
@ -1,6 +1,23 @@
|
||||||
import { writable, derived, get } from "svelte/store"
|
import { writable, derived, get } from "svelte/store"
|
||||||
import { tables } from "./tables"
|
import { tables } from "./tables"
|
||||||
import { API } from "api"
|
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() {
|
export function createViewsV2Store() {
|
||||||
const store = writable({
|
const store = writable({
|
||||||
|
@ -12,7 +29,7 @@ export function createViewsV2Store() {
|
||||||
const views = Object.values(table?.views || {}).filter(view => {
|
const views = Object.values(table?.views || {}).filter(view => {
|
||||||
return view.version === 2
|
return view.version === 2
|
||||||
})
|
})
|
||||||
list = list.concat(views)
|
list = list.concat(views.map(view => convertToSearchFilterGroup(view)))
|
||||||
})
|
})
|
||||||
return {
|
return {
|
||||||
...$store,
|
...$store,
|
||||||
|
@ -34,6 +51,7 @@ export function createViewsV2Store() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const create = async view => {
|
const create = async view => {
|
||||||
|
view = convertToSearchFilters(view)
|
||||||
const savedViewResponse = await API.viewV2.create(view)
|
const savedViewResponse = await API.viewV2.create(view)
|
||||||
const savedView = savedViewResponse.data
|
const savedView = savedViewResponse.data
|
||||||
replaceView(savedView.id, savedView)
|
replaceView(savedView.id, savedView)
|
||||||
|
@ -41,6 +59,7 @@ export function createViewsV2Store() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const save = async view => {
|
const save = async view => {
|
||||||
|
view = convertToSearchFilters(view)
|
||||||
const res = await API.viewV2.update(view)
|
const res = await API.viewV2.update(view)
|
||||||
const savedView = res?.data
|
const savedView = res?.data
|
||||||
replaceView(view.id, savedView)
|
replaceView(view.id, savedView)
|
||||||
|
@ -51,6 +70,7 @@ export function createViewsV2Store() {
|
||||||
if (!viewId) {
|
if (!viewId) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
view = convertToSearchFilterGroup(view)
|
||||||
const existingView = get(derivedStore).list.find(view => view.id === viewId)
|
const existingView = get(derivedStore).list.find(view => view.id === viewId)
|
||||||
const tableIndex = get(tables).list.findIndex(table => {
|
const tableIndex = get(tables).list.findIndex(table => {
|
||||||
return table._id === view?.tableId || table._id === existingView?.tableId
|
return table._id === view?.tableId || table._id === existingView?.tableId
|
||||||
|
|
|
@ -1,4 +1,14 @@
|
||||||
import { get } from "svelte/store"
|
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
|
const SuppressErrors = true
|
||||||
|
|
||||||
|
@ -6,7 +16,7 @@ export const createActions = context => {
|
||||||
const { API, datasource, columns } = context
|
const { API, datasource, columns } = context
|
||||||
|
|
||||||
const saveDefinition = async newDefinition => {
|
const saveDefinition = async newDefinition => {
|
||||||
await API.viewV2.update(newDefinition)
|
await API.viewV2.update(convertToSearchFilters(newDefinition))
|
||||||
}
|
}
|
||||||
|
|
||||||
const saveRow = async row => {
|
const saveRow = async row => {
|
||||||
|
|
Loading…
Reference in New Issue