From d2e9df874c37f29aebadb560d212e0d17899e1e9 Mon Sep 17 00:00:00 2001 From: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com> Date: Mon, 26 Feb 2024 07:08:45 +0000 Subject: [PATCH 1/3] fix(nocodb): incorrect switch break statement in column delete service --- packages/nocodb/src/services/columns.service.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/nocodb/src/services/columns.service.ts b/packages/nocodb/src/services/columns.service.ts index 33306cd326..b90b90dfda 100644 --- a/packages/nocodb/src/services/columns.service.ts +++ b/packages/nocodb/src/services/columns.service.ts @@ -2256,12 +2256,10 @@ export class ColumnsService { break; } case UITypes.SingleSelect: { - if (column.uidt === UITypes.SingleSelect) { - if (await KanbanView.IsColumnBeingUsedAsGroupingField(column.id)) { - NcError.badRequest( - `The column '${column.column_name}' is being used in Kanban View. Please delete Kanban View first.`, - ); - } + if (await KanbanView.IsColumnBeingUsedAsGroupingField(column.id)) { + NcError.badRequest( + `The column '${column.column_name}' is being used in Kanban View. Please delete Kanban View first.`, + ); } /* falls through to default */ } @@ -2272,7 +2270,7 @@ export class ColumnsService { `The column '${column.column_name}' is being used in Calendar View. Please delete Calendar View first.`, ); } - break; + /* falls through to default */ } // on deleting created/last modified columns, keep the column in table and delete the column from meta From fdac2b825c544835bcc8b85b4897016ac8a9b45e Mon Sep 17 00:00:00 2001 From: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com> Date: Mon, 26 Feb 2024 07:08:45 +0000 Subject: [PATCH 2/3] fix(nocodb): column drop issue due to incorect switch case arrangement --- .../nocodb/src/services/columns.service.ts | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/packages/nocodb/src/services/columns.service.ts b/packages/nocodb/src/services/columns.service.ts index b90b90dfda..43d94eaf4f 100644 --- a/packages/nocodb/src/services/columns.service.ts +++ b/packages/nocodb/src/services/columns.service.ts @@ -2091,6 +2091,17 @@ export class ColumnsService { ProjectMgrv2.getSqlMgr({ id: source.base_id }, ncMeta), ); + /** + * @Note: When using 'falls through to default' cases in a switch statement, + * it is crucial to place them after cases with break statements. + * Additionally, include a check for column.uidt inside these 'falls through to default' cases + * to conditionally execute logic based on the value of column.uidt. + * + * This check becomes essential when there are multiple 'falls through to default' cases. + * By adding the column.uidt check, we ensure that each case has its own specific conditions. + * This prevents unintended execution of logic from subsequent cases due to fall-through, + * providing a more controlled and predictable behavior in the switch statement. + */ switch (column.uidt) { case UITypes.Lookup: case UITypes.Rollup: @@ -2099,6 +2110,14 @@ export class ColumnsService { case UITypes.Formula: await Column.delete(param.columnId, ncMeta); break; + // on deleting created/last modified columns, keep the column in table and delete the column from meta + case UITypes.CreatedTime: + case UITypes.LastModifiedTime: + case UITypes.CreatedBy: + case UITypes.LastModifiedBy: { + await Column.delete(param.columnId, ncMeta); + break; + } // Since Links is just an extended version of LTAR, we can use the same logic case UITypes.Links: case UITypes.LinkToAnotherRecord: @@ -2256,7 +2275,10 @@ export class ColumnsService { break; } case UITypes.SingleSelect: { - if (await KanbanView.IsColumnBeingUsedAsGroupingField(column.id)) { + if ( + column.uidt === UITypes.SingleSelect && + (await KanbanView.IsColumnBeingUsedAsGroupingField(column.id)) + ) { NcError.badRequest( `The column '${column.column_name}' is being used in Kanban View. Please delete Kanban View first.`, ); @@ -2265,23 +2287,16 @@ export class ColumnsService { } case UITypes.DateTime: case UITypes.Date: { - if (await CalendarRange.IsColumnBeingUsedAsRange(column.id, ncMeta)) { + if ( + [UITypes.DateTime, UITypes.Date].includes(column.uidt) && + (await CalendarRange.IsColumnBeingUsedAsRange(column.id, ncMeta)) + ) { NcError.badRequest( `The column '${column.column_name}' is being used in Calendar View. Please delete Calendar View first.`, ); } /* falls through to default */ } - - // on deleting created/last modified columns, keep the column in table and delete the column from meta - case UITypes.CreatedTime: - case UITypes.LastModifiedTime: - case UITypes.CreatedBy: - case UITypes.LastModifiedBy: - { - await Column.delete(param.columnId, ncMeta); - } - break; default: { const tableUpdateBody = { ...table, From 2dd44b4ef6f2838f9ec93116f1fdff4d866575a8 Mon Sep 17 00:00:00 2001 From: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com> Date: Mon, 26 Feb 2024 07:08:45 +0000 Subject: [PATCH 3/3] fix(nocodb): PR review changes #2402 --- packages/nocodb/src/services/columns.service.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/nocodb/src/services/columns.service.ts b/packages/nocodb/src/services/columns.service.ts index 43d94eaf4f..82f3b142ca 100644 --- a/packages/nocodb/src/services/columns.service.ts +++ b/packages/nocodb/src/services/columns.service.ts @@ -2275,10 +2275,7 @@ export class ColumnsService { break; } case UITypes.SingleSelect: { - if ( - column.uidt === UITypes.SingleSelect && - (await KanbanView.IsColumnBeingUsedAsGroupingField(column.id)) - ) { + if (await KanbanView.IsColumnBeingUsedAsGroupingField(column.id)) { NcError.badRequest( `The column '${column.column_name}' is being used in Kanban View. Please delete Kanban View first.`, );