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