From e906a9196495e686b9b50ed69af7b57a7f3af052 Mon Sep 17 00:00:00 2001 From: tiny-craft <137850705+tiny-craft@users.noreply.github.com> Date: Tue, 4 Jul 2023 00:42:17 +0800 Subject: [PATCH] feat: complete function in toolbar of browser refactor: use uniform confirm dialog for delete key --- .../components/common/EditableTableColumn.vue | 2 +- .../content_value/ContentToolbar.vue | 32 +++---- .../src/components/sidebar/BrowserPane.vue | 91 ++++++++++++++----- .../src/components/sidebar/BrowserTree.vue | 11 +-- .../src/components/sidebar/ConnectionPane.vue | 13 +-- frontend/src/langs/en.json | 2 +- frontend/src/langs/zh-cn.json | 2 +- frontend/src/stores/connections.js | 10 +- frontend/src/style.scss | 13 +++ 9 files changed, 110 insertions(+), 66 deletions(-) diff --git a/frontend/src/components/common/EditableTableColumn.vue b/frontend/src/components/common/EditableTableColumn.vue index bec23b0..3c7b88a 100644 --- a/frontend/src/components/common/EditableTableColumn.vue +++ b/frontend/src/components/common/EditableTableColumn.vue @@ -25,7 +25,7 @@ const emit = defineEmits(['edit', 'delete', 'save', 'cancel']) - {{ $t('delete_key_tip', { key: props.bindKey }) }} + {{ $t('remove_tip', { name: props.bindKey }) }} diff --git a/frontend/src/components/content_value/ContentToolbar.vue b/frontend/src/components/content_value/ContentToolbar.vue index 676885a..fc41e54 100644 --- a/frontend/src/components/content_value/ContentToolbar.vue +++ b/frontend/src/components/content_value/ContentToolbar.vue @@ -10,6 +10,7 @@ import { useI18n } from 'vue-i18n' import { useMessage } from 'naive-ui' import IconButton from '../common/IconButton.vue' import useConnectionStore from '../../stores/connections.js' +import { useConfirmDialog } from '../../utils/confirm_dialog.js' const props = defineProps({ server: String, @@ -37,11 +38,15 @@ const onReloadKey = () => { connectionStore.loadKeyValue(props.server, props.db, props.keyPath) } -const onConfirmDelete = async () => { - const success = await connectionStore.removeKey(props.server, props.db, props.keyPath) - if (success) { - message.success(i18n.t('delete_key_succ', { key: props.keyPath })) - } +const confirmDialog = useConfirmDialog() +const onDeleteKey = () => { + confirmDialog.warning(i18n.t('remove_tip', { name: props.keyPath }), () => { + connectionStore.removeKey(props.server, props.db, props.keyPath).then((success) => { + if (success) { + message.success(i18n.t('delete_key_succ', { key: props.keyPath })) + } + }) + }) } @@ -86,20 +91,11 @@ const onConfirmDelete = async () => { - + diff --git a/frontend/src/langs/en.json b/frontend/src/langs/en.json index 16cce9c..2dad811 100644 --- a/frontend/src/langs/en.json +++ b/frontend/src/langs/en.json @@ -19,7 +19,6 @@ "forever": "Forever", "rename_key": "Rename Key", "delete_key": "Delete Key", - "delete_key_tip": "\"{key}\" will be deleted", "delete_key_succ": "\"{key}\" has been deleted", "copy_value": "Copy Value", "edit_value": "Edit Value", @@ -110,6 +109,7 @@ "copy_value_succ": "Value Copied !", "save_value_succ": "Value Saved !", "handle_succ": "Handle Success !", + "reload_succ": "Reload Success !", "field_required": "This item should not be blank", "spec_field_required": "\"{key}\" should not be blank", "no_connections": "No Connection", diff --git a/frontend/src/langs/zh-cn.json b/frontend/src/langs/zh-cn.json index 117832d..81e4e53 100644 --- a/frontend/src/langs/zh-cn.json +++ b/frontend/src/langs/zh-cn.json @@ -19,7 +19,6 @@ "forever": "永久", "rename_key": "重命名键", "delete_key": "删除键", - "delete_key_tip": "{key} 将会被删除", "delete_key_succ": "{key} 已被删除", "copy_value": "复制值", "edit_value": "修改值", @@ -113,6 +112,7 @@ "copy_succ": "已复制到剪切板", "save_value_succ": "已保存值", "handle_succ": "操作成功", + "reload_succ": "已重新载入", "field_required": "此项不能为空", "spec_field_required": "{key} 不能为空", "no_connections": "空空如也", diff --git a/frontend/src/stores/connections.js b/frontend/src/stores/connections.js index e450f6e..807b574 100644 --- a/frontend/src/stores/connections.js +++ b/frontend/src/stores/connections.js @@ -233,11 +233,17 @@ const useConnectionStore = defineStore('connections', { /** * open connection * @param {string} name + * @param {boolean} [reload] * @returns {Promise} */ - async openConnection(name) { + async openConnection(name, reload) { if (this.isConnected(name)) { - return + if (reload !== true) { + return + } else { + // reload mode, try close connection first + await CloseConnection(name) + } } const { data, success, msg } = await OpenConnection(name) diff --git a/frontend/src/style.scss b/frontend/src/style.scss index bc0f701..e76361f 100644 --- a/frontend/src/style.scss +++ b/frontend/src/style.scss @@ -111,3 +111,16 @@ body { min-width: 100px; padding-right: 10px; } + +.nav-pane-container { + overflow: hidden; + background-color: var(--bg-color); + + .nav-pane-bottom { + align-items: center; + gap: 8px; + padding: 3px 5px 5px 5px; + min-height: 35px; + border-top: var(--border-color) 1px solid; + } +}