Allow ViewV2 types
This commit is contained in:
parent
ac0ae34808
commit
ff3bbf6217
|
@ -55,7 +55,10 @@ export async function save(ctx: Ctx) {
|
|||
existingTable.views[viewName] = existingTable.views[originalName]
|
||||
}
|
||||
await db.put(table)
|
||||
await handleViewEvents(existingTable.views[viewName], table.views[viewName])
|
||||
await handleViewEvents(
|
||||
existingTable.views[viewName] as View,
|
||||
table.views[viewName]
|
||||
)
|
||||
|
||||
ctx.body = table.views[viewName]
|
||||
builderSocket?.emitTableUpdate(ctx, table)
|
||||
|
|
|
@ -10,6 +10,10 @@ export const backfill = async (appDb: Database, timestamp: string | number) => {
|
|||
|
||||
if (table.views) {
|
||||
for (const view of Object.values(table.views)) {
|
||||
if (sdk.views.isV2(view)) {
|
||||
continue
|
||||
}
|
||||
|
||||
await events.view.created(view, timestamp)
|
||||
|
||||
if (view.calculation) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { HTTPError, context } from "@budibase/backend-core"
|
||||
import { ViewV2 } from "@budibase/types"
|
||||
import { View, ViewV2 } from "@budibase/types"
|
||||
|
||||
import sdk from "../../../sdk"
|
||||
import { utils as coreUtils } from "@budibase/backend-core"
|
||||
|
@ -9,9 +9,9 @@ export async function get(
|
|||
viewId: string
|
||||
): Promise<ViewV2 | undefined> {
|
||||
const table = await sdk.tables.getTable(tableId)
|
||||
const view = Object.values(table.views!).find(v => isV2(v) && v.id === viewId)
|
||||
const views = Object.values(table.views!)
|
||||
const view = views.find(v => isV2(v) && v.id === viewId) as ViewV2 | undefined
|
||||
|
||||
// @ts-ignore TODO
|
||||
return view
|
||||
}
|
||||
|
||||
|
@ -29,13 +29,12 @@ export async function create(
|
|||
const table = await sdk.tables.getTable(tableId)
|
||||
table.views ??= {}
|
||||
|
||||
// @ts-ignore: TODO
|
||||
table.views[view.name] = view
|
||||
await db.put(table)
|
||||
return view
|
||||
}
|
||||
|
||||
function isV2(view: object): view is ViewV2 {
|
||||
export function isV2(view: View | ViewV2): view is ViewV2 {
|
||||
return (view as ViewV2).version === 2
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { Document } from "../../document"
|
||||
import { View } from "../view"
|
||||
import { View, ViewV2 } from "../view"
|
||||
import { RenameColumn } from "../../../sdk"
|
||||
import { TableSchema } from "./schema"
|
||||
|
||||
export interface Table extends Document {
|
||||
type?: string
|
||||
views?: { [key: string]: View }
|
||||
views?: { [key: string]: View | ViewV2 }
|
||||
name: string
|
||||
primary?: string[]
|
||||
schema: TableSchema
|
||||
|
|
Loading…
Reference in New Issue