From 882a056cd9a8a942330c5468f2f065430e2b960b Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 2 Jul 2024 13:58:16 +0200 Subject: [PATCH 1/3] Don't trim any fields on view crud endpoints --- .../src/api/controllers/view/viewsV2.ts | 5 --- .../src/api/routes/tests/viewV2.spec.ts | 36 +++++++++---------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/packages/server/src/api/controllers/view/viewsV2.ts b/packages/server/src/api/controllers/view/viewsV2.ts index 76807b796a..4208772fa6 100644 --- a/packages/server/src/api/controllers/view/viewsV2.ts +++ b/packages/server/src/api/controllers/view/viewsV2.ts @@ -33,11 +33,6 @@ async function parseSchema(view: CreateViewRequest) { p[fieldName] = fieldSchema return p }, {} as Record>) - for (let [key, column] of Object.entries(finalViewSchema)) { - if (!column.visible && !column.readonly) { - delete finalViewSchema[key] - } - } return finalViewSchema } diff --git a/packages/server/src/api/routes/tests/viewV2.spec.ts b/packages/server/src/api/routes/tests/viewV2.spec.ts index 99ff4f8db7..5d83cd8616 100644 --- a/packages/server/src/api/routes/tests/viewV2.spec.ts +++ b/packages/server/src/api/routes/tests/viewV2.spec.ts @@ -218,6 +218,10 @@ describe.each([ order: 1, width: 100, }, + Category: { + visible: false, + icon: "ic", + }, }, id: createdView.id, version: 2, @@ -269,9 +273,8 @@ describe.each([ ...newView, schema: { id: { visible: true }, - Price: { - visible: true, - }, + Price: { visible: true }, + Category: { visible: false }, }, id: expect.any(String), version: 2, @@ -759,6 +762,7 @@ describe.each([ order: 1, width: 100, }, + Category: { visible: false, icon: "ic" }, }, id: view.id, version: 2, @@ -873,7 +877,8 @@ describe.each([ await db.getDB(config.appId!).put(tableToUpdate) view = await config.api.viewV2.get(view.id) - await config.api.viewV2.update({ + await config.api.viewV2.update( + { ...view, schema: { ...view.schema, @@ -881,22 +886,14 @@ describe.each([ visible: false, }, }, - }) - - expect(await config.api.viewV2.get(view.id)).toEqual( - expect.objectContaining({ - schema: { - id: expect.objectContaining({ - visible: false, - }), - Price: expect.objectContaining({ - visible: false, - }), - Category: expect.objectContaining({ - visible: true, - }), + }, + { + status: 400, + body: { + message: 'You can\'t hide "id" because it is a required field.', + status: 400, }, - }) + } ) }) }) @@ -938,7 +935,6 @@ describe.each([ Category: { visible: true }, }, }) - expect(res.schema?.Price).toBeUndefined() const view = await config.api.viewV2.get(res.id) const updatedTable = await config.api.table.get(table._id!) From 53af94f971ba03d6ba2568dc7328b24e21329c6f Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 2 Jul 2024 14:02:16 +0200 Subject: [PATCH 2/3] Fix search returning non visible columns --- packages/server/src/api/controllers/row/views.ts | 4 +++- packages/server/src/api/routes/tests/viewV2.spec.ts | 13 +++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/server/src/api/controllers/row/views.ts b/packages/server/src/api/controllers/row/views.ts index 63ce12f0ab..12e76155bc 100644 --- a/packages/server/src/api/controllers/row/views.ts +++ b/packages/server/src/api/controllers/row/views.ts @@ -25,7 +25,9 @@ export async function searchView( ctx.throw(400, `This method only supports viewsV2`) } - const viewFields = Object.keys(view.schema || {}) + const viewFields = Object.entries(view.schema || {}) + .filter(([_, value]) => value.visible) + .map(([key]) => key) const { body } = ctx.request // Enrich saved query with ephemeral query params. diff --git a/packages/server/src/api/routes/tests/viewV2.spec.ts b/packages/server/src/api/routes/tests/viewV2.spec.ts index 5d83cd8616..43a6d39172 100644 --- a/packages/server/src/api/routes/tests/viewV2.spec.ts +++ b/packages/server/src/api/routes/tests/viewV2.spec.ts @@ -879,14 +879,14 @@ describe.each([ view = await config.api.viewV2.get(view.id) await config.api.viewV2.update( { - ...view, - schema: { - ...view.schema, - Price: { - visible: false, + ...view, + schema: { + ...view.schema, + Price: { + visible: false, + }, }, }, - }, { status: 400, body: { @@ -1201,6 +1201,7 @@ describe.each([ ], schema: { id: { visible: true }, + one: { visible: false }, two: { visible: true }, }, }) From 07d538f6fc573d32588c041e4e3fc77c8d1b75ef Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 2 Jul 2024 14:02:49 +0200 Subject: [PATCH 3/3] Don't trim fields on view enrich schema --- packages/server/src/sdk/app/views/index.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/server/src/sdk/app/views/index.ts b/packages/server/src/sdk/app/views/index.ts index b6ac7b6f6b..fce57a390d 100644 --- a/packages/server/src/sdk/app/views/index.ts +++ b/packages/server/src/sdk/app/views/index.ts @@ -160,14 +160,10 @@ export function enrichSchema( for (const key of Object.keys(schema)) { // if nothing specified in view, then it is not visible const ui = view.schema?.[key] || { visible: false } - if (ui.visible === false) { - schema[key].visible = false - } else { - schema[key] = { - ...schema[key], - ...ui, - order: anyViewOrder ? ui?.order ?? undefined : schema[key].order, - } + schema[key] = { + ...schema[key], + ...ui, + order: anyViewOrder ? ui?.order ?? undefined : schema[key].order, } }