Don't throw an error when atempting to update a view that includes non UI metadata overrides

This commit is contained in:
Andrew Kingston 2023-08-14 16:17:30 +01:00
parent 6a7e0d2d31
commit 4bfa0d8cb0
2 changed files with 6 additions and 45 deletions

View File

@ -22,7 +22,7 @@ export const createActions = context => {
await API.viewV2.update(newDefinition)
}
const addRow = async row => {
const saveRow = async row => {
const $datasource = get(datasource)
row.tableId = $datasource?.tableId
row._viewId = $datasource?.id
@ -32,14 +32,6 @@ export const createActions = context => {
}
}
const updateRow = async row => {
const $datasource = get(datasource)
return {
...(await API.patchRow(row, SuppressErrors)),
_viewId: $datasource.id,
}
}
const deleteRows = async rows => {
await API.viewV2.deleteRows({
viewId: get(datasource).id,
@ -73,8 +65,8 @@ export const createActions = context => {
actions: {
refreshDefinition,
saveDefinition,
addRow,
updateRow,
addRow: saveRow,
updateRow: saveRow,
deleteRows,
getRow,
isDatasourceValid,

View File

@ -10,41 +10,10 @@ import {
} from "@budibase/types"
import { builderSocket } from "../../../websockets"
async function parseSchema(ctx: Ctx, view: CreateViewRequest) {
async function parseSchema(view: CreateViewRequest) {
if (!view.schema) {
return
}
function hasOverrides(
newObj: Record<string, any>,
existingObj: Record<string, any>
) {
return Object.entries(newObj || {}).some(([key, value]) => {
const isObject = typeof value === "object"
const existing = existingObj[key]
if (isObject && hasOverrides(value, existing || {})) {
return true
}
if (!isObject && value !== existing) {
return true
}
})
}
const table = await sdk.tables.getTable(view.tableId)
for (const [
fieldName,
{ order, width, visible, icon, ...schemaNonUI },
] of Object.entries(view.schema)) {
const overrides = hasOverrides(schemaNonUI, table.schema[fieldName])
if (overrides) {
ctx.throw(
400,
"This endpoint does not support overriding non UI fields in the schema"
)
}
}
const finalViewSchema =
view.schema &&
Object.entries(view.schema).reduce((p, [fieldName, schemaValue]) => {
@ -74,7 +43,7 @@ export async function create(ctx: Ctx<CreateViewRequest, ViewResponse>) {
const view = ctx.request.body
const { tableId } = view
const schema = await parseSchema(ctx, view)
const schema = await parseSchema(view)
const parsedView: Omit<RequiredKeys<ViewV2>, "id" | "version"> = {
name: view.name,
@ -107,7 +76,7 @@ export async function update(ctx: Ctx<UpdateViewRequest, ViewResponse>) {
const { tableId } = view
const schema = await parseSchema(ctx, view)
const schema = await parseSchema(view)
const parsedView: RequiredKeys<ViewV2> = {
id: view.id,
name: view.name,