From b6fcdf301dbb352cd00dba25434ee894af7231fc Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Mon, 9 Dec 2024 11:59:04 +0000 Subject: [PATCH] PR comments --- .../src/events/publishers/table.ts | 2 +- .../src/api/controllers/view/viewsV2.ts | 33 ++++++++----------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/packages/backend-core/src/events/publishers/table.ts b/packages/backend-core/src/events/publishers/table.ts index de765e2cdd..77a2c3e1a4 100644 --- a/packages/backend-core/src/events/publishers/table.ts +++ b/packages/backend-core/src/events/publishers/table.ts @@ -29,7 +29,7 @@ async function updated(oldTable: Table, newTable: Table) { for (const key in newTable.schema) { if (!oldTable.schema[key]) { const newColumn = newTable.schema[key] - if ("default" in newColumn) { + if ("default" in newColumn && newColumn.default != null) { defaultValues = true } if (newColumn.type === FieldType.AI) { diff --git a/packages/server/src/api/controllers/view/viewsV2.ts b/packages/server/src/api/controllers/view/viewsV2.ts index 2751a81234..66a6194096 100644 --- a/packages/server/src/api/controllers/view/viewsV2.ts +++ b/packages/server/src/api/controllers/view/viewsV2.ts @@ -187,29 +187,22 @@ async function handleViewEvents(existingView: ViewV2, view: ViewV2) { // if new columns in the view for (const key in view.schema) { - if (!existingView?.schema?.[key]) { - // view calculations - // @ts-expect-error non calculation types just won't have the calculationType field - const calculationType = view.schema[key].calculationType - if (calculationType) { - await events.view.calculationCreated({ - calculationType, - tableId: view.tableId, - }) - } + if ("calculationType" in view.schema[key] && !existingView?.schema?.[key]) { + await events.view.calculationCreated({ + calculationType: view.schema[key].calculationType, + tableId: view.tableId, + }) } // view joins - if (view.schema[key].columns) { - for (const column in view.schema[key]?.columns) { - // if the new column is visible and it wasn't before - if ( - !existingView?.schema?.[key].columns?.[column].visible && - view.schema?.[key].columns?.[column].visible - ) { - // new view join exposing a column - await events.view.viewJoinCreated({ tableId: view.tableId }) - } + for (const column in view.schema[key]?.columns ?? []) { + // if the new column is visible and it wasn't before + if ( + !existingView?.schema?.[key].columns?.[column].visible && + view.schema?.[key].columns?.[column].visible + ) { + // new view join exposing a column + await events.view.viewJoinCreated({ tableId: view.tableId }) } } }