Browse Source

fix: Added getViewColumnId and fixed issue with view column creation

pull/6889/head
Muhammed Mustafa 1 year ago
parent
commit
fb9642b0bc
  1. 14
      packages/nocodb/src/models/Column.ts
  2. 58
      packages/nocodb/src/models/View.ts

14
packages/nocodb/src/models/Column.ts

@ -198,15 +198,25 @@ export default class Column<T = any> implements ColumnType {
); );
if (column.view_id) { if (column.view_id) {
await View.insertOrUpdateColumn( const viewColId = await View.getViewColumnId(
{
viewId: column.view_id,
colId: row.id,
},
ncMeta,
);
if (viewColId) {
await View.updateColumn(
column.view_id, column.view_id,
row.id, viewColId,
{ {
show: true, show: true,
}, },
ncMeta, ncMeta,
); );
} }
}
return col; return col;
} }

58
packages/nocodb/src/models/View.ts

@ -680,6 +680,64 @@ export default class View implements ViewType {
return (this.columns = await View.getColumns(this.id, ncMeta)); return (this.columns = await View.getColumns(this.id, ncMeta));
} }
static async getViewColumnId(
{
viewId,
colId,
}: {
viewId: string;
colId: string;
},
ncMeta = Noco.ncMeta,
) {
const view = await this.get(viewId);
if (!view) return undefined;
let tableName;
let cacheScope;
switch (view.type) {
case ViewTypes.GRID:
tableName = MetaTable.GRID_VIEW_COLUMNS;
cacheScope = CacheScope.GRID_VIEW_COLUMN;
break;
case ViewTypes.GALLERY:
tableName = MetaTable.GALLERY_VIEW_COLUMNS;
cacheScope = CacheScope.GALLERY_VIEW_COLUMN;
break;
case ViewTypes.MAP:
tableName = MetaTable.MAP_VIEW_COLUMNS;
cacheScope = CacheScope.MAP_VIEW_COLUMN;
break;
case ViewTypes.FORM:
tableName = MetaTable.FORM_VIEW_COLUMNS;
cacheScope = CacheScope.FORM_VIEW_COLUMN;
break;
case ViewTypes.KANBAN:
tableName = MetaTable.KANBAN_VIEW_COLUMNS;
cacheScope = CacheScope.KANBAN_VIEW_COLUMN;
break;
}
const key = `${cacheScope}:viewColumnId:${colId}`;
const o = await NocoCache.get(key, CacheGetType.TYPE_STRING);
if (o) return o;
const viewColumn = await ncMeta.metaGet2(null, null, tableName, {
fk_view_id: viewId,
fk_column_id: colId,
});
if (!viewColumn) return undefined;
await NocoCache.set(key, viewColumn.id);
return viewColumn?.id;
}
static async updateColumn( static async updateColumn(
viewId: string, viewId: string,
colId: string, colId: string,

Loading…
Cancel
Save