Persist only UI schema overrides
This commit is contained in:
parent
b528257bbe
commit
bce75c91a6
|
@ -2,22 +2,36 @@ import sdk from "../../../sdk"
|
|||
import {
|
||||
CreateViewRequest,
|
||||
Ctx,
|
||||
UIFieldMetadata,
|
||||
UpdateViewRequest,
|
||||
ViewResponse,
|
||||
ViewV2,
|
||||
RequiredKeys,
|
||||
} from "@budibase/types"
|
||||
|
||||
export async function create(ctx: Ctx<CreateViewRequest, ViewResponse>) {
|
||||
const view = ctx.request.body
|
||||
const { tableId } = view
|
||||
|
||||
const schemaUI =
|
||||
view.schema &&
|
||||
Object.entries(view.schema).reduce((p, [fieldName, schemaValue]) => {
|
||||
p[fieldName] = {
|
||||
order: schemaValue.order,
|
||||
width: schemaValue.width,
|
||||
visible: schemaValue.visible,
|
||||
icon: schemaValue.icon,
|
||||
}
|
||||
return p
|
||||
}, {} as Record<string, RequiredKeys<UIFieldMetadata>>)
|
||||
|
||||
const parsedView: Omit<ViewV2, "id" | "version"> = {
|
||||
name: view.name,
|
||||
tableId: view.tableId,
|
||||
query: view.query,
|
||||
sort: view.sort,
|
||||
columns: view.schema && Object.keys(view.schema),
|
||||
schemaUI: view.schema,
|
||||
schemaUI,
|
||||
}
|
||||
const result = await sdk.views.create(tableId, parsedView)
|
||||
ctx.status = 201
|
||||
|
|
|
@ -90,7 +90,7 @@ describe("/v2/views", () => {
|
|||
})
|
||||
})
|
||||
|
||||
it("persist schema overrides", async () => {
|
||||
it("persist only UI schema overrides", async () => {
|
||||
const newView: CreateViewRequest = {
|
||||
name: generator.name(),
|
||||
tableId: config.table!._id!,
|
||||
|
@ -99,11 +99,14 @@ describe("/v2/views", () => {
|
|||
name: "name",
|
||||
type: FieldType.STRING,
|
||||
visible: true,
|
||||
order: 1,
|
||||
width: 100,
|
||||
},
|
||||
lastname: {
|
||||
name: "lastname",
|
||||
type: FieldType.STRING,
|
||||
visible: false,
|
||||
icon: "ic",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -116,14 +119,13 @@ describe("/v2/views", () => {
|
|||
columns: ["name", "lastname"],
|
||||
schemaUI: {
|
||||
name: {
|
||||
name: "name",
|
||||
type: FieldType.STRING,
|
||||
visible: true,
|
||||
order: 1,
|
||||
width: 100,
|
||||
},
|
||||
lastname: {
|
||||
name: "lastname",
|
||||
type: FieldType.STRING,
|
||||
visible: false,
|
||||
icon: "ic",
|
||||
},
|
||||
},
|
||||
id: createdView.id,
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
export * from "./documents"
|
||||
export * from "./sdk"
|
||||
export * from "./api"
|
||||
export * from "./shared"
|
||||
|
|
|
@ -3,3 +3,7 @@ export type DeepPartial<T> = {
|
|||
}
|
||||
|
||||
export type ISO8601 = string
|
||||
|
||||
export type RequiredKeys<T> = {
|
||||
[K in keyof Required<T>]: T[K]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue