From 1a49db245067382853c2b22ff5308a5ee0c6db45 Mon Sep 17 00:00:00 2001 From: tiny-craft <137850705+tiny-craft@users.noreply.github.com> Date: Sat, 7 Oct 2023 15:57:29 +0800 Subject: [PATCH] feat: add cancel operation to the waiting spin for opening connections #9 chore: update common message config --- .../src/components/sidebar/ConnectionTree.vue | 31 ++++++++++++++----- frontend/src/langs/en.json | 1 + frontend/src/langs/zh-cn.json | 1 + frontend/src/utils/discrete.js | 1 + 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/frontend/src/components/sidebar/ConnectionTree.vue b/frontend/src/components/sidebar/ConnectionTree.vue index ffd60a0..87b35a6 100644 --- a/frontend/src/components/sidebar/ConnectionTree.vue +++ b/frontend/src/components/sidebar/ConnectionTree.vue @@ -21,7 +21,7 @@ import usePreferencesStore from 'stores/preferences.js' const themeVars = useThemeVars() const i18n = useI18n() -const openingConnection = ref(false) +const connectingServer = ref('') const connectionStore = useConnectionStore() const tabStore = useTabStore() const prefStore = usePreferencesStore() @@ -287,18 +287,21 @@ const onUpdateSelectedKeys = (keys, option) => { */ const openConnection = async (name) => { try { + connectingServer.value = name if (!connectionStore.isConnected(name)) { - openingConnection.value = true await connectionStore.openConnection(name) } - tabStore.upsertTab({ - server: name, - }) + // check if connection already canceled before finish open + if (!isEmpty(connectingServer.value)) { + tabStore.upsertTab({ + server: name, + }) + } } catch (e) { $message.error(e.message) // node.isLeaf = undefined } finally { - openingConnection.value = false + connectingServer.value = '' } } @@ -467,6 +470,13 @@ const handleDrop = ({ node, dragNode, dropPosition }) => { connectionStore.connections = Array.from(connectionStore.connections) saveSort() } + +const onCancelOpen = () => { + if (!isEmpty(connectingServer.value)) { + connectionStore.closeConnection(connectingServer.value) + connectingServer.value = '' + } +}