From 52c3372ef952d57bd09e8d44665f8c730c17c6c8 Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Thu, 11 Aug 2022 14:59:19 +0200 Subject: [PATCH 1/6] fix(gui-v2): abort renaming view on failed validation --- packages/nc-gui-v2/components/smartsheet/sidebar/MenuTop.vue | 4 +++- .../components/smartsheet/sidebar/RenameableMenuItem.vue | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/nc-gui-v2/components/smartsheet/sidebar/MenuTop.vue b/packages/nc-gui-v2/components/smartsheet/sidebar/MenuTop.vue index 411dce49dc..d207685fc1 100644 --- a/packages/nc-gui-v2/components/smartsheet/sidebar/MenuTop.vue +++ b/packages/nc-gui-v2/components/smartsheet/sidebar/MenuTop.vue @@ -148,12 +148,14 @@ async function onRename(view: ViewType) { message: valid, duration: 2, }) + + return } try { await api.dbView.update(view.id!, { title: view.title, - order: view.order, + order: String(view.order), }) notification.success({ diff --git a/packages/nc-gui-v2/components/smartsheet/sidebar/RenameableMenuItem.vue b/packages/nc-gui-v2/components/smartsheet/sidebar/RenameableMenuItem.vue index d28ad94026..32db58713a 100644 --- a/packages/nc-gui-v2/components/smartsheet/sidebar/RenameableMenuItem.vue +++ b/packages/nc-gui-v2/components/smartsheet/sidebar/RenameableMenuItem.vue @@ -8,11 +8,11 @@ interface Props { } interface Emits { - (event: 'openModal', data: { type: ViewTypes; title?: string }): void (event: 'update:view', data: Record): void (event: 'changeView', view: Record): void (event: 'rename', view: Record): void (event: 'delete', view: Record): void + (event: 'openModal', data: { type: ViewTypes; title?: string; copyViewId?: string }): void } const props = defineProps() From 3ea6f02d5655b4b182b6b2772efa23871a996d8c Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Thu, 11 Aug 2022 15:01:12 +0200 Subject: [PATCH 2/6] chore(gui-v2): make `required` prop optional in Cell.vue --- packages/nc-gui-v2/components/smartsheet-header/Cell.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nc-gui-v2/components/smartsheet-header/Cell.vue b/packages/nc-gui-v2/components/smartsheet-header/Cell.vue index 8585a49221..e5d32acd1e 100644 --- a/packages/nc-gui-v2/components/smartsheet-header/Cell.vue +++ b/packages/nc-gui-v2/components/smartsheet-header/Cell.vue @@ -5,7 +5,7 @@ import { inject, toRef } from 'vue' import { ColumnInj, IsFormInj, MetaInj } from '~/context' import { useProvideColumnCreateStore } from '#imports' -const props = defineProps<{ column: ColumnType & { meta: any }; required: boolean; hideMenu?: boolean }>() +const props = defineProps<{ column: ColumnType & { meta: any }; required?: boolean; hideMenu?: boolean }>() const hideMenu = toRef(props, 'hideMenu') From 5c6fa6aacbe5e45f4ce7f8ff3e4a279f38e6c024 Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Thu, 11 Aug 2022 15:17:33 +0200 Subject: [PATCH 3/6] fix(gui-v2): pass validation cb to `RenameableMenuItem` and validate before rename event --- .../components/smartsheet/sidebar/MenuTop.vue | 18 ++++-------------- .../smartsheet/sidebar/RenameableMenuItem.vue | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/packages/nc-gui-v2/components/smartsheet/sidebar/MenuTop.vue b/packages/nc-gui-v2/components/smartsheet/sidebar/MenuTop.vue index d207685fc1..0d60374ebe 100644 --- a/packages/nc-gui-v2/components/smartsheet/sidebar/MenuTop.vue +++ b/packages/nc-gui-v2/components/smartsheet/sidebar/MenuTop.vue @@ -61,12 +61,12 @@ function markItem(id: string) { } /** validate view title */ -function validate(value?: string) { - if (!value || value.trim().length < 0) { +function validate(view: Record) { + if (!view.title || view.title.trim().length < 0) { return 'View name is required' } - if (views.value.every((v1) => v1.title !== value)) { + if (views.value.some((v) => v.title === view.title && v.id !== view.id)) { return 'View name should be unique' } @@ -141,17 +141,6 @@ function changeView(view: { id: string; alias?: string; title?: string; type: Vi /** Rename a view */ async function onRename(view: ViewType) { - const valid = validate(view.title) - - if (valid !== true) { - notification.error({ - message: valid, - duration: 2, - }) - - return - } - try { await api.dbView.update(view.id!, { title: view.title, @@ -195,6 +184,7 @@ function onDeleted() { :id="view.id" :key="view.id" :view="view" + :on-validate="validate" class="transition-all ease-in duration-300" :class="[ isMarked === view.id ? 'bg-gray-200' : '', diff --git a/packages/nc-gui-v2/components/smartsheet/sidebar/RenameableMenuItem.vue b/packages/nc-gui-v2/components/smartsheet/sidebar/RenameableMenuItem.vue index 32db58713a..1e9186be49 100644 --- a/packages/nc-gui-v2/components/smartsheet/sidebar/RenameableMenuItem.vue +++ b/packages/nc-gui-v2/components/smartsheet/sidebar/RenameableMenuItem.vue @@ -1,10 +1,12 @@