Browse Source

fix: reset cover image column id if user delete att field

pull/8869/head
Ramesh Mane 5 months ago
parent
commit
89a717c0bd
  1. 8
      packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue
  2. 48
      packages/nocodb/src/models/Column.ts
  3. 15
      packages/nocodb/src/services/columns.service.ts

8
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

48
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<T = any> 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;

15
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);

Loading…
Cancel
Save