From c01269cd4bd2487bab5fbf5b60d8e2eeaebcc31b Mon Sep 17 00:00:00 2001 From: mertmit Date: Mon, 20 Mar 2023 21:48:45 +0300 Subject: [PATCH] feat: undo/redo table rename Signed-off-by: mertmit --- .../nc-gui/components/dlg/TableRename.vue | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/packages/nc-gui/components/dlg/TableRename.vue b/packages/nc-gui/components/dlg/TableRename.vue index a57c9dc86c..e7b6f63920 100644 --- a/packages/nc-gui/components/dlg/TableRename.vue +++ b/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() 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 () => {
@@ -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()" />