From 89a717c0bd190bc6352b8831675a41b505cd62f4 Mon Sep 17 00:00:00 2001 From: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com> Date: Wed, 26 Jun 2024 19:03:35 +0000 Subject: [PATCH] fix: reset cover image column id if user delete att field --- .../smartsheet/toolbar/FieldsMenu.vue | 8 ++-- packages/nocodb/src/models/Column.ts | 48 ++++++++++++++++++- .../nocodb/src/services/columns.service.ts | 15 +++++- 3 files changed, 64 insertions(+), 7 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue b/packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue index 93feb4a2f1..05802c87a2 100644 --- a/packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue +++ b/packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue @@ -158,12 +158,10 @@ const updateCoverImage = async (val?: string | null) => { const coverImageColumnId = computed({ get: () => { const fk_cover_image_col_id = - (activeView.value?.type === ViewTypes.GALLERY || - activeView.value?.type === ViewTypes.KANBAN || - activeView.value?.type === ViewTypes.CALENDAR) && - activeView.value?.view - ? (activeView.value?.view as GalleryType).fk_cover_image_col_id + (activeView.value?.type === ViewTypes.GALLERY || activeView.value?.type === ViewTypes.KANBAN) && activeView.value?.view + ? (activeView.value?.view as GalleryType | KanbanType).fk_cover_image_col_id : undefined + // check if `fk_cover_image_col_id` is in `coverOptions` // e.g. in share view, users may not share the cover image column if (coverOptions.value?.find((o) => o.value === fk_cover_image_col_id)) return fk_cover_image_col_id diff --git a/packages/nocodb/src/models/Column.ts b/packages/nocodb/src/models/Column.ts index 960e1eac33..ad10d60123 100644 --- a/packages/nocodb/src/models/Column.ts +++ b/packages/nocodb/src/models/Column.ts @@ -17,7 +17,7 @@ import Sort from '~/models/Sort'; import Filter from '~/models/Filter'; import QrCodeColumn from '~/models/QrCodeColumn'; import BarcodeColumn from '~/models/BarcodeColumn'; -import { LinksColumn } from '~/models'; +import { GalleryView, KanbanView, LinksColumn } from '~/models'; import { extractProps } from '~/helpers/extractProps'; import { NcError } from '~/helpers/catchError'; import addFormulaErrorIfMissingColumn from '~/helpers/addFormulaErrorIfMissingColumn'; @@ -872,6 +872,52 @@ export default class Column implements ColumnType { await Filter.delete(context, filter.id, ncMeta); } } + // Set Gallery & Kanban view `fk_cover_image_col_id` value to null + { + const promises = []; + + // Gallery views + const galleryViews: GalleryView[] = await ncMeta.metaList2( + context.workspace_id, + context.base_id, + MetaTable.GALLERY_VIEW, + { + condition: { + fk_cover_image_col_id: id, + }, + }, + ); + + for (const galleryView of galleryViews) { + promises.push( + GalleryView.update(context, galleryView.fk_view_id, { + fk_cover_image_col_id: null, + }), + ); + } + + // Kanban views + const kanbanViews: KanbanView[] = await ncMeta.metaList2( + context.workspace_id, + context.base_id, + MetaTable.GALLERY_VIEW, + { + condition: { + fk_cover_image_col_id: id, + }, + }, + ); + + for (const kanbanView of kanbanViews) { + promises.push( + KanbanView.update(context, kanbanView.fk_view_id, { + fk_cover_image_col_id: null, + }), + ); + } + + await Promise.all(promises); + } // Delete from view columns let colOptionTableName = null; diff --git a/packages/nocodb/src/services/columns.service.ts b/packages/nocodb/src/services/columns.service.ts index 22835fb791..7181f1b277 100644 --- a/packages/nocodb/src/services/columns.service.ts +++ b/packages/nocodb/src/services/columns.service.ts @@ -12,6 +12,7 @@ import { substituteColumnIdWithAliasInFormula, UITypes, validateFormulaAndExtractTreeWithType, + ViewTypes, } from 'nocodb-sdk'; import { pluralize, singularize } from 'inflection'; import hash from 'object-hash'; @@ -22,7 +23,7 @@ import type { UserType, } from 'nocodb-sdk'; import type SqlMgrv2 from '~/db/sql-mgr/v2/SqlMgrv2'; -import type { Base, LinkToAnotherRecordColumn } from '~/models'; +import type { Base, GalleryView, LinkToAnotherRecordColumn } from '~/models'; import type CustomKnex from '~/db/CustomKnex'; import type SqlClient from '~/db/sql-client/lib/SqlClient'; import type { BaseModelSqlv2 } from '~/db/BaseModelSqlv2'; @@ -2375,6 +2376,18 @@ export class ColumnsService { } return c; }), + views: table.views.map((view) => { + if ( + [ViewTypes.GALLERY, ViewTypes.KANBAN].includes(view.type) && + (view.view as KanbanView | GalleryView)?.fk_cover_image_col_id === + param.columnId + ) { + (view.view as KanbanView | GalleryView).fk_cover_image_col_id = + null; + } + + return view; + }), }; await sqlMgr.sqlOpPlus(source, 'tableUpdate', tableUpdateBody);