From 87ae2f73c65fcf091940bf63c12af306f521d467 Mon Sep 17 00:00:00 2001 From: Muhammed Mustafa Date: Fri, 10 Nov 2023 10:54:43 +0000 Subject: [PATCH] fix: Added rename option to view context menu --- .../smartsheet/toolbar/OpenedViewAction.vue | 92 ++++++++++++++++++- .../smartsheet/toolbar/ViewInfo.vue | 4 +- 2 files changed, 90 insertions(+), 6 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/toolbar/OpenedViewAction.vue b/packages/nc-gui/components/smartsheet/toolbar/OpenedViewAction.vue index 4bcf8acfe2..4e66861402 100644 --- a/packages/nc-gui/components/smartsheet/toolbar/OpenedViewAction.vue +++ b/packages/nc-gui/components/smartsheet/toolbar/OpenedViewAction.vue @@ -5,7 +5,7 @@ import { LockType } from '~/lib' import UploadIcon from '~icons/nc-icons/upload' import DownloadIcon from '~icons/nc-icons/download' -const { activeView, views } = storeToRefs(useViewsStore()) +const { activeView, views, openedViewsTab } = storeToRefs(useViewsStore()) const { loadViews, navigateToView } = useViewsStore() const { isMobileMode } = useGlobal() @@ -38,6 +38,14 @@ const quickImportDialogTypes: QuickImportDialogType[] = ['csv', 'excel'] const isViewIdCopied = ref(false) +const isRenaming = ref(false) + +const renameInputDom = ref() + +const viewRenameTitle = ref('') + +const error = ref() + const quickImportDialogs: Record<(typeof quickImportDialogTypes)[number], Ref> = quickImportDialogTypes.reduce( (acc: any, curr) => { acc[curr] = ref(false) @@ -126,6 +134,56 @@ const onImportClick = (dialog: any) => { dialog.value = true } +const onRenameMenuClick = () => { + isRenaming.value = true + isDropdownOpen.value = false + viewRenameTitle.value = activeView.value!.title + + setTimeout(() => { + renameInputDom.value.focus() + }) +} + +watch(renameInputDom, () => { + renameInputDom.value?.focus() +}) + +const onRenameBlur = async () => { + if (validate()) { + activeView.value!.title = viewRenameTitle.value + isRenaming.value = false + error.value = undefined + + await $api.dbView.update(activeView.value!.id!, { + title: viewRenameTitle.value, + }) + } else { + renameInputDom.value?.focus() + } +} + +/** validate view title */ +function validate() { + if (!viewRenameTitle.value || viewRenameTitle.value.trim().length < 0) { + error.value = t('msg.error.viewNameRequired') + + return false + } + + if (views.value.some((v) => v.title === viewRenameTitle.value && v.id !== activeView.value!.id)) { + error.value = t('msg.error.viewNameDuplicate') + return false + } + + return true +} + +watch(viewRenameTitle, () => { + if (error.value) { + error.value = undefined + } +}) + watch(isDropdownOpen, () => { setTimeout(() => { isViewIdCopied.value = false @@ -134,7 +192,33 @@ watch(isDropdownOpen, () => { + + - -