Browse Source

feat: undo/redo table rename

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/5332/head
mertmit 2 years ago
parent
commit
c01269cd4b
  1. 29
      packages/nc-gui/components/dlg/TableRename.vue

29
packages/nc-gui/components/dlg/TableRename.vue

@ -14,6 +14,7 @@ import {
useNuxtApp,
useProject,
useTabs,
useUndoRedo,
useVModel,
validateTableName,
watchEffect,
@ -43,6 +44,8 @@ const projectStore = useProject()
const { loadTables, isMysql, isMssql, isPg } = projectStore
const { tables, project } = storeToRefs(projectStore)
const { addUndo } = useUndoRedo()
const inputEl = $ref<ComponentPublicInstance>()
let loading = $ref(false)
@ -113,7 +116,7 @@ watchEffect(
{ flush: 'post' },
)
const renameTable = async () => {
const renameTable = async (undo = false) => {
if (!tableMeta) return
loading = true
@ -126,6 +129,26 @@ const renameTable = async () => {
dialogShow.value = false
if (!undo) {
addUndo({
redo: {
fn: (t: string) => {
formState.title = t
renameTable(true)
},
args: [formState.title],
},
undo: {
fn: (t: string) => {
formState.title = t
renameTable(true)
},
args: [tableMeta.title],
},
scope: tableMeta.project_id,
})
}
await loadTables()
// update metas
@ -161,7 +184,7 @@ const renameTable = async () => {
<template #footer>
<a-button key="back" @click="dialogShow = false">{{ $t('general.cancel') }}</a-button>
<a-button key="submit" type="primary" :loading="loading" @click="renameTable">{{ $t('general.submit') }}</a-button>
<a-button key="submit" type="primary" :loading="loading" @click="renameTable()">{{ $t('general.submit') }}</a-button>
</template>
<div class="pl-10 pr-10 pt-5">
@ -175,7 +198,7 @@ const renameTable = async () => {
v-model:value="formState.title"
hide-details
:placeholder="$t('msg.info.enterTableName')"
@keydown.enter="renameTable"
@keydown.enter="renameTable()"
/>
</a-form-item>
</a-form>

Loading…
Cancel
Save