Browse Source

feat: undo/redo view rename

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/5332/head
mertmit 2 years ago
parent
commit
a1ec725a45
  1. 27
      packages/nc-gui/components/smartsheet/sidebar/MenuTop.vue
  2. 4
      packages/nc-gui/components/smartsheet/sidebar/RenameableMenuItem.vue

27
packages/nc-gui/components/smartsheet/sidebar/MenuTop.vue

@ -18,6 +18,7 @@ import {
useI18n,
useNuxtApp,
useRouter,
useUndoRedo,
viewTypeAlias,
watch,
} from '#imports'
@ -46,6 +47,8 @@ const { api } = useApi()
const router = useRouter()
const { addUndo } = useUndoRedo()
/** Selected view(s) for menu */
const selected = ref<string[]>([])
@ -165,7 +168,7 @@ function changeView(view: ViewType) {
}
/** Rename a view */
async function onRename(view: ViewType) {
async function onRename(view: ViewType, originalTitle?: string, undo = false) {
try {
await api.dbView.update(view.id!, {
title: view.title,
@ -178,6 +181,28 @@ async function onRename(view: ViewType) {
},
})
if (!undo) {
addUndo({
redo: {
fn: (v: ViewType, title: string) => {
const tempTitle = v.title
v.title = title
onRename(v, tempTitle, true)
},
args: [view, view.title],
},
undo: {
fn: (v: ViewType, title: string) => {
const tempTitle = v.title
v.title = title
onRename(v, tempTitle, true)
},
args: [view, originalTitle],
},
scope: activeView.value?.fk_model_id,
})
}
// View renamed successfully
message.success(t('msg.success.viewRenamed'))
} catch (e: any) {

4
packages/nc-gui/components/smartsheet/sidebar/RenameableMenuItem.vue

@ -27,7 +27,7 @@ interface Emits {
(event: 'changeView', view: Record<string, any>): void
(event: 'rename', view: ViewType): void
(event: 'rename', view: ViewType, originalTitle: string | undefined): void
(event: 'delete', view: ViewType): void
@ -142,7 +142,7 @@ async function onRename() {
return
}
emits('rename', vModel.value)
emits('rename', vModel.value, originalTitle)
onStopEdit()
}

Loading…
Cancel
Save