From 53d5ecca8cdce45ae0cfd876db1438e27334095a Mon Sep 17 00:00:00 2001 From: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com> Date: Tue, 15 Oct 2024 11:08:04 +0530 Subject: [PATCH] Nc fix: kanban view issues (#9649) * fix(nc-gui): don't update kanban view stack options if it is shared view * fix(nocodb): update groupingFieldColumn from view meta on updating select field * fix(nc-gui): error cannot read property map of undefined * fix(nc-gui): don't remove record from uncategorizedStack in public view --- .../nc-gui/composables/useKanbanViewStore.ts | 7 +++- packages/nocodb/src/models/KanbanView.ts | 24 ++++++------- .../nocodb/src/services/columns.service.ts | 34 ++++++++++++++++++- 3 files changed, 49 insertions(+), 16 deletions(-) diff --git a/packages/nc-gui/composables/useKanbanViewStore.ts b/packages/nc-gui/composables/useKanbanViewStore.ts index b0262cb4eb..cf8e78cd2d 100644 --- a/packages/nc-gui/composables/useKanbanViewStore.ts +++ b/packages/nc-gui/composables/useKanbanViewStore.ts @@ -220,6 +220,10 @@ const [useProvideKanbanViewStore, useKanbanViewStore] = useInjectionState( // eslint-disable-next-line @typescript-eslint/no-unused-vars const { collapsed, ...rest } = stackMetaObj.value[fk_grp_col_id][idx] if (!deepCompare(rest, option)) { + // Don't update stack meta if it is shared view and + // shared view meta grouping field options not matched with actual column options + if (isPublic.value) continue + // update the option in stackMetaObj stackMetaObj.value[fk_grp_col_id][idx] = { ...stackMetaObj.value[fk_grp_col_id][idx], @@ -482,7 +486,7 @@ const [useProvideKanbanViewStore, useKanbanViewStore] = useInjectionState( // update to groupingField value to target value formattedData.value.set( stackTitle, - formattedData.value.get(stackTitle)!.map((o) => ({ + (formattedData.value.get(stackTitle) || []).map((o) => ({ ...o, row: { ...o.row, @@ -624,6 +628,7 @@ const [useProvideKanbanViewStore, useKanbanViewStore] = useInjectionState( } function removeRowFromUncategorizedStack() { + if (isPublic.value) return // remove the last record formattedData.value.get(null)!.pop() // decrease total count by 1 diff --git a/packages/nocodb/src/models/KanbanView.ts b/packages/nocodb/src/models/KanbanView.ts index c2b49f80a0..7da60da6a1 100644 --- a/packages/nocodb/src/models/KanbanView.ts +++ b/packages/nocodb/src/models/KanbanView.ts @@ -65,24 +65,20 @@ export default class KanbanView implements KanbanType { return view && new KanbanView(view); } - public static async IsColumnBeingUsedAsGroupingField( + public static async getViewsByGroupingColId( context: NcContext, columnId: string, ncMeta = Noco.ncMeta, ) { - return ( - ( - await ncMeta.metaList2( - context.workspace_id, - context.base_id, - MetaTable.KANBAN_VIEW, - { - condition: { - fk_grp_col_id: columnId, - }, - }, - ) - ).length > 0 + return await ncMeta.metaList2( + context.workspace_id, + context.base_id, + MetaTable.KANBAN_VIEW, + { + condition: { + fk_grp_col_id: columnId, + }, + }, ); } diff --git a/packages/nocodb/src/services/columns.service.ts b/packages/nocodb/src/services/columns.service.ts index 1668774fad..923f4eee17 100644 --- a/packages/nocodb/src/services/columns.service.ts +++ b/packages/nocodb/src/services/columns.service.ts @@ -65,6 +65,7 @@ import Noco from '~/Noco'; import NcConnectionMgrv2 from '~/utils/common/NcConnectionMgrv2'; import { MetaTable } from '~/utils/globals'; import { MetaService } from '~/meta/meta.service'; +import { parseMetaProp } from 'src/utils/modelUtils'; // todo: move export enum Altered { @@ -1243,6 +1244,27 @@ export class ColumnsService { await Column.update(context, param.columnId, { ...colBody, }); + + if (colBody.uidt === UITypes.SingleSelect) { + const kanbanViewsByColId = await KanbanView.getViewsByGroupingColId( + context, + column.id, + ); + + for (const kanbanView of kanbanViewsByColId) { + const view = await View.get(context, kanbanView.fk_view_id); + if (!view?.uuid) continue; + // Update groupingFieldColumn from view meta which will be used in shared kanban view + view.meta = parseMetaProp(view); + await View.update(context, view.id, { + ...view, + meta: { + ...view.meta, + groupingFieldColumn: colBody, + }, + }); + } + } } else if (colBody.uidt === UITypes.User) { // handle default value for user column if (typeof colBody.cdf !== 'string') { @@ -1517,6 +1539,15 @@ export class ColumnsService { baseModel.getTnPath(table.table_name), column.column_name, ]); + } else if ( + column.uidt === UITypes.SingleSelect && + column.uidt !== colBody.uidt && + (await KanbanView.getViewsByGroupingColId(context, column.id)).length > + 0 + ) { + NcError.badRequest( + `The column '${column.column_name}' is being used in Kanban View. Please update stack by field or delete Kanban View first.`, + ); } colBody = await getColumnPropsFromUIDT(colBody, source); @@ -2585,7 +2616,8 @@ export class ColumnsService { } case UITypes.SingleSelect: { if ( - await KanbanView.IsColumnBeingUsedAsGroupingField(context, column.id) + (await KanbanView.getViewsByGroupingColId(context, column.id)) + .length > 0 ) { NcError.badRequest( `The column '${column.column_name}' is being used in Kanban View. Please delete Kanban View first.`,