Browse Source

fix: Added rename option to view context menu

pull/6888/head
Muhammed Mustafa 1 year ago
parent
commit
87ae2f73c6
  1. 92
      packages/nc-gui/components/smartsheet/toolbar/OpenedViewAction.vue
  2. 4
      packages/nc-gui/components/smartsheet/toolbar/ViewInfo.vue

92
packages/nc-gui/components/smartsheet/toolbar/OpenedViewAction.vue

@ -5,7 +5,7 @@ import { LockType } from '~/lib'
import UploadIcon from '~icons/nc-icons/upload' import UploadIcon from '~icons/nc-icons/upload'
import DownloadIcon from '~icons/nc-icons/download' import DownloadIcon from '~icons/nc-icons/download'
const { activeView, views } = storeToRefs(useViewsStore()) const { activeView, views, openedViewsTab } = storeToRefs(useViewsStore())
const { loadViews, navigateToView } = useViewsStore() const { loadViews, navigateToView } = useViewsStore()
const { isMobileMode } = useGlobal() const { isMobileMode } = useGlobal()
@ -38,6 +38,14 @@ const quickImportDialogTypes: QuickImportDialogType[] = ['csv', 'excel']
const isViewIdCopied = ref(false) const isViewIdCopied = ref(false)
const isRenaming = ref(false)
const renameInputDom = ref()
const viewRenameTitle = ref('')
const error = ref<string | undefined>()
const quickImportDialogs: Record<(typeof quickImportDialogTypes)[number], Ref<boolean>> = quickImportDialogTypes.reduce( const quickImportDialogs: Record<(typeof quickImportDialogTypes)[number], Ref<boolean>> = quickImportDialogTypes.reduce(
(acc: any, curr) => { (acc: any, curr) => {
acc[curr] = ref(false) acc[curr] = ref(false)
@ -126,6 +134,56 @@ const onImportClick = (dialog: any) => {
dialog.value = true 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, () => { watch(isDropdownOpen, () => {
setTimeout(() => { setTimeout(() => {
isViewIdCopied.value = false isViewIdCopied.value = false
@ -134,7 +192,33 @@ watch(isDropdownOpen, () => {
</script> </script>
<template> <template>
<NcDropdown v-model:visible="isDropdownOpen"> <div
v-if="isRenaming"
class="h-6 relative"
:class="{
'max-w-2/5': !isSharedBase && !isMobileMode && activeView?.is_default,
'max-w-3/5': !isSharedBase && !isMobileMode && !activeView?.is_default,
}"
>
<input
ref="renameInputDom"
v-model="viewRenameTitle"
class="ml-0.25 w-full px-1 py-0.5 rounded-md font-medium text-gray-800"
:class="{
'outline-brand-500': !error,
'outline-red-500': error,
}"
@blur="onRenameBlur"
@keydown.enter="onRenameBlur"
/>
<NcTooltip v-if="error" class="absolute top-0.25 -right-0.5">
<template #title>
{{ error }}
</template>
<GeneralIcon icon="info" class="cursor-pointer" />
</NcTooltip>
</div>
<NcDropdown v-else v-model:visible="isDropdownOpen">
<div <div
class="truncate nc-active-view-title !hover:(bg-gray-100 text-gray-800) ml-0.25 pl-1 pr-0.25 rounded-md py-1 cursor-pointer" class="truncate nc-active-view-title !hover:(bg-gray-100 text-gray-800) ml-0.25 pl-1 pr-0.25 rounded-md py-1 cursor-pointer"
:class="{ :class="{
@ -179,7 +263,7 @@ watch(isDropdownOpen, () => {
</NcTooltip> </NcTooltip>
<NcDivider /> <NcDivider />
<template v-if="!activeView?.is_default"> <template v-if="!activeView?.is_default">
<NcMenuItem> <NcMenuItem @click="onRenameMenuClick">
<GeneralIcon icon="edit" /> <GeneralIcon icon="edit" />
Rename View Rename View
</NcMenuItem> </NcMenuItem>
@ -262,6 +346,8 @@ watch(isDropdownOpen, () => {
</template> </template>
</NcDropdown> </NcDropdown>
<LazySmartsheetToolbarReload v-if="openedViewsTab === 'view' && !isMobileMode && !isRenaming" />
<template v-if="currentBaseId"> <template v-if="currentBaseId">
<LazyDlgQuickImport <LazyDlgQuickImport
v-for="tp in quickImportDialogTypes" v-for="tp in quickImportDialogTypes"

4
packages/nc-gui/components/smartsheet/toolbar/ViewInfo.vue

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
const { isMobileMode } = useGlobal() const { isMobileMode } = useGlobal()
const { openedViewsTab, activeView } = storeToRefs(useViewsStore()) const { activeView } = storeToRefs(useViewsStore())
const { base, isSharedBase } = storeToRefs(useBase()) const { base, isSharedBase } = storeToRefs(useBase())
const { baseUrl } = useBase() const { baseUrl } = useBase()
@ -132,7 +132,5 @@ const openedBaseUrl = computed(() => {
<SmartsheetToolbarOpenedViewAction /> <SmartsheetToolbarOpenedViewAction />
</template> </template>
<LazySmartsheetToolbarReload v-if="openedViewsTab === 'view' && !isMobileMode" />
</div> </div>
</template> </template>

Loading…
Cancel
Save