From fca74cab57ec83b4ad0e902d44492884c333964a Mon Sep 17 00:00:00 2001 From: Pranav C Date: Mon, 11 Oct 2021 18:51:07 +0530 Subject: [PATCH] feat: make view name unique, add view_name in shared view table Signed-off-by: Pranav C --- .../components/spreadsheetNavDrawer.vue | 3 ++ .../spreadsheet/dialog/createViewDialog.vue | 5 ++- .../src/lib/noco/common/XcMigrationSource.ts | 5 ++- .../nocodb/src/lib/noco/meta/NcMetaMgrEE.ts | 1 + .../migrations/nc_005_add_view_name_column.ts | 38 +++++++++++++++++++ 5 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 packages/nocodb/src/lib/noco/migrations/nc_005_add_view_name_column.ts diff --git a/packages/nc-gui/components/project/spreadsheet/components/spreadsheetNavDrawer.vue b/packages/nc-gui/components/project/spreadsheet/components/spreadsheetNavDrawer.vue index 548df113f8..f2b4815b0f 100644 --- a/packages/nc-gui/components/project/spreadsheet/components/spreadsheetNavDrawer.vue +++ b/packages/nc-gui/components/project/spreadsheet/components/spreadsheetNavDrawer.vue @@ -420,6 +420,7 @@ :meta="meta" :copy-view="copyViewRef" :alias="meta._tn" + :views-list="viewsList" @created="onViewCreate" /> @@ -717,6 +718,7 @@ export default { parent_model_title: this.meta._tn }) this.$toast.success('View renamed successfully').goAway(3000) + this.$set(view, 'edit', false) } catch (e) { this.$toast.error(e.message).goAway(3000) } @@ -762,6 +764,7 @@ export default { extraViewParams: this.extraViewParams, selectedViewId: this.selectedViewId }, + view_name: this.selectedView.title, type: this.selectedView.type, show_as: this.selectedView.show_as, password: this.sharedViewPassword diff --git a/packages/nc-gui/components/project/spreadsheet/dialog/createViewDialog.vue b/packages/nc-gui/components/project/spreadsheet/dialog/createViewDialog.vue index c51ca9bc0d..7f29649d5d 100644 --- a/packages/nc-gui/components/project/spreadsheet/dialog/createViewDialog.vue +++ b/packages/nc-gui/components/project/spreadsheet/dialog/createViewDialog.vue @@ -11,7 +11,7 @@ ref="name" v-model="view_name" label="View Name" - :rules="[v=>!!v || 'View name required']" + :rules="[v=>!!v || 'View name required', v => viewsList.every((v1) => (v1.alias || v1.title) !== v) || 'View name should be unique']" autofocus /> @@ -39,7 +39,7 @@ export default { name: 'CreateViewDialog', - props: ['value', 'nodes', 'table', 'alias', 'show_as', 'viewsCount', 'primaryValueColumn', 'meta', 'copyView'], + props: ['value', 'nodes', 'table', 'alias', 'show_as', 'viewsCount', 'primaryValueColumn', 'meta', 'copyView', 'viewsList'], data: () => ({ valid: false, view_name: '', @@ -74,6 +74,7 @@ export default { }, methods: { async createView() { + if (!this.valid) { return } let showFields = null let attachmentCol if (this.show_as === 'gallery') { diff --git a/packages/nocodb/src/lib/noco/common/XcMigrationSource.ts b/packages/nocodb/src/lib/noco/common/XcMigrationSource.ts index 88bc4eb6bf..b9253838f0 100644 --- a/packages/nocodb/src/lib/noco/common/XcMigrationSource.ts +++ b/packages/nocodb/src/lib/noco/common/XcMigrationSource.ts @@ -2,6 +2,7 @@ import * as project from '../migrations/nc_001_init'; import * as m2m from '../migrations/nc_002_add_m2m'; import * as fkn from '../migrations/nc_003_add_fkn_column'; import * as viewType from '../migrations/nc_004_add_view_type_column'; +import * as viewName from '../migrations/nc_005_add_view_name_column'; // Create a custom migration source class export default class XcMigrationSource { @@ -10,7 +11,7 @@ export default class XcMigrationSource { // arguments to getMigrationName and getMigration public getMigrations(): Promise { // In this example we are just returning migration names - return Promise.resolve(['project', 'm2m', 'fkn', 'viewType']); + return Promise.resolve(['project', 'm2m', 'fkn', 'viewType', 'viewName']); } public getMigrationName(migration): string { @@ -27,6 +28,8 @@ export default class XcMigrationSource { return fkn; case 'viewType': return viewType; + case 'viewName': + return viewName; } } } diff --git a/packages/nocodb/src/lib/noco/meta/NcMetaMgrEE.ts b/packages/nocodb/src/lib/noco/meta/NcMetaMgrEE.ts index 24f28b9d36..8ad861d9c3 100644 --- a/packages/nocodb/src/lib/noco/meta/NcMetaMgrEE.ts +++ b/packages/nocodb/src/lib/noco/meta/NcMetaMgrEE.ts @@ -184,6 +184,7 @@ export default class NcMetaMgrEE extends NcMetaMgr { project_id: args.project_id, db_alias: this.getDbAlias(args), model_name: args.args.model_name, + view_name: args.args.view_name, meta: JSON.stringify(args.args.meta), query_params: JSON.stringify(args.args.query_params), view_id: uuidv4(), diff --git a/packages/nocodb/src/lib/noco/migrations/nc_005_add_view_name_column.ts b/packages/nocodb/src/lib/noco/migrations/nc_005_add_view_name_column.ts new file mode 100644 index 0000000000..d606525d88 --- /dev/null +++ b/packages/nocodb/src/lib/noco/migrations/nc_005_add_view_name_column.ts @@ -0,0 +1,38 @@ +import Knex from 'knex'; + +const up = async (knex: Knex) => { + await knex.schema.alterTable('nc_shared_views', table => { + table.integer('view_name'); + }); +}; + +const down = async knex => { + await knex.schema.alterTable('nc_shared_views', table => { + table.dropColumns('view_name'); + }); +}; + +export { up, down }; + +/** + * @copyright Copyright (c) 2021, Xgene Cloud Ltd + * + * @author Naveen MR + * @author Pranav C Balan + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */