diff --git a/packages/server/src/api/controllers/view/viewsV2.ts b/packages/server/src/api/controllers/view/viewsV2.ts index b2a9e2f223..c872abba39 100644 --- a/packages/server/src/api/controllers/view/viewsV2.ts +++ b/packages/server/src/api/controllers/view/viewsV2.ts @@ -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) { 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>) + const parsedView: Omit = { 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 diff --git a/packages/server/src/api/routes/tests/viewV2.spec.ts b/packages/server/src/api/routes/tests/viewV2.spec.ts index e2b81f4cf0..14fe90b93e 100644 --- a/packages/server/src/api/routes/tests/viewV2.spec.ts +++ b/packages/server/src/api/routes/tests/viewV2.spec.ts @@ -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, diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 4adb2fda97..ad1688ef52 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -1,3 +1,4 @@ export * from "./documents" export * from "./sdk" export * from "./api" +export * from "./shared" diff --git a/packages/types/src/shared/typeUtils.ts b/packages/types/src/shared/typeUtils.ts index fbe215fdb9..df0e049455 100644 --- a/packages/types/src/shared/typeUtils.ts +++ b/packages/types/src/shared/typeUtils.ts @@ -3,3 +3,7 @@ export type DeepPartial = { } export type ISO8601 = string + +export type RequiredKeys = { + [K in keyof Required]: T[K] +}