Browse Source

Merge pull request #6889 from nocodb/nc-fix/hide-column-for-other-view-on-col-creation

Hide column for other view on col creation
pull/6904/head
Raju Udava 1 year ago committed by GitHub
parent
commit
456fe95279
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      packages/nc-gui/components/smartsheet/header/Menu.vue
  2. 8
      packages/nc-gui/composables/useColumnCreateStore.ts
  3. 1
      packages/nocodb-sdk/src/lib/Api.ts
  4. 24
      packages/nocodb/src/models/Column.ts
  5. 58
      packages/nocodb/src/models/View.ts
  6. 3
      packages/nocodb/src/schema/swagger.json

3
packages/nc-gui/components/smartsheet/header/Menu.vue

@ -170,9 +170,10 @@ const duplicateColumn = async () => {
await $api.dbTableColumn.create(meta!.value!.id!, { await $api.dbTableColumn.create(meta!.value!.id!, {
...columnCreatePayload, ...columnCreatePayload,
pv: false, pv: false,
view_id: view.value!.id as string,
column_order: { column_order: {
order: newColumnOrder, order: newColumnOrder,
view_id: view.value?.id as string, view_id: view.value!.id as string,
}, },
} as ColumnReqType) } as ColumnReqType)
await getMeta(meta!.value!.id!, true) await getMeta(meta!.value!.id!, true)

8
packages/nc-gui/composables/useColumnCreateStore.ts

@ -50,6 +50,8 @@ const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState
const sqlUi = ref(meta.value?.source_id ? sqlUis.value[meta.value?.source_id] : Object.values(sqlUis.value)[0]) const sqlUi = ref(meta.value?.source_id ? sqlUis.value[meta.value?.source_id] : Object.values(sqlUis.value)[0])
const { activeView } = storeToRefs(useViewsStore())
const isEdit = computed(() => !!column?.value?.id) const isEdit = computed(() => !!column?.value?.id)
const isMysql = computed(() => isMysqlFunc(meta.value?.source_id ? meta.value?.source_id : Object.keys(sqlUis.value)[0])) const isMysql = computed(() => isMysqlFunc(meta.value?.source_id ? meta.value?.source_id : Object.keys(sqlUis.value)[0]))
@ -275,7 +277,11 @@ const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState
// }; // };
// } // }
} }
await $api.dbTableColumn.create(meta.value?.id as string, { ...formState.value, ...columnPosition }) await $api.dbTableColumn.create(meta.value?.id as string, {
...formState.value,
...columnPosition,
view_id: activeView.value!.id as string,
})
/** if LTAR column then force reload related table meta */ /** if LTAR column then force reload related table meta */
if (isLinksOrLTAR(formState.value) && meta.value?.id !== formState.value.childId) { if (isLinksOrLTAR(formState.value) && meta.value?.id !== formState.value.childId) {

1
packages/nocodb-sdk/src/lib/Api.ts

@ -504,6 +504,7 @@ export type ColumnReqType = (
view_id?: string; view_id?: string;
}; };
title: string; title: string;
view_id?: string;
}; };
/** /**

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

@ -99,6 +99,7 @@ export default class Column<T = any> implements ColumnType {
[key: string]: any; [key: string]: any;
fk_model_id: string; fk_model_id: string;
uidt: UITypes | string; uidt: UITypes | string;
view_id?: string;
} & Pick<ColumnReqType, 'column_order'>, } & Pick<ColumnReqType, 'column_order'>,
ncMeta = Noco.ncMeta, ncMeta = Noco.ncMeta,
) { ) {
@ -185,7 +186,7 @@ export default class Column<T = any> implements ColumnType {
{ {
fk_column_id: row.id, fk_column_id: row.id,
fk_model_id: column.fk_model_id, fk_model_id: column.fk_model_id,
show: true, show: !column.view_id,
column_order: column.column_order, column_order: column.column_order,
}, },
ncMeta, ncMeta,
@ -196,6 +197,27 @@ export default class Column<T = any> implements ColumnType {
`${column.fk_model_id}:default:*`, `${column.fk_model_id}:default:*`,
); );
if (column.view_id) {
const viewColId = await View.getViewColumnId(
{
viewId: column.view_id,
colId: row.id,
},
ncMeta,
);
if (viewColId) {
await View.updateColumn(
column.view_id,
viewColId,
{
show: true,
},
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,

3
packages/nocodb/src/schema/swagger.json

@ -17427,6 +17427,9 @@
"maxLength": 255, "maxLength": 255,
"minLength": 1, "minLength": 1,
"type": "string" "type": "string"
},
"view_id": {
"type": "string"
} }
}, },
"required": [ "required": [

Loading…
Cancel
Save