From f7f394972dd8811c6a7964be0178c6b1948bf49e Mon Sep 17 00:00:00 2001 From: Lykin <137850705+tiny-craft@users.noreply.github.com> Date: Tue, 12 Dec 2023 16:15:30 +0800 Subject: [PATCH] fix: select incorrect database when double click key layer #99 --- backend/services/browser_service.go | 13 ++++++++++++- frontend/src/components/sidebar/BrowserPane.vue | 4 ++++ frontend/src/components/sidebar/BrowserTree.vue | 2 +- frontend/src/components/sidebar/ConnectionTree.vue | 7 ------- frontend/src/stores/tab.js | 4 ++-- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/backend/services/browser_service.go b/backend/services/browser_service.go index d75919f..9d26af9 100644 --- a/backend/services/browser_service.go +++ b/backend/services/browser_service.go @@ -87,7 +87,18 @@ func (b *browserService) Stop() { func (b *browserService) OpenConnection(name string) (resp types.JSResp) { // get connection config selConn := Connection().getConnection(name) - item, err := b.getRedisClient(name, selConn.LastDB) + // correct last database index + lastDB := selConn.LastDB + if selConn.DBFilterType == "show" && !sliceutil.Contains(selConn.DBFilterList, lastDB) { + lastDB = selConn.DBFilterList[0] + } else if selConn.DBFilterType == "hide" && sliceutil.Contains(selConn.DBFilterList, lastDB) { + lastDB = selConn.DBFilterList[0] + } + if lastDB != selConn.LastDB { + Connection().SaveLastDB(name, lastDB) + } + + item, err := b.getRedisClient(name, lastDB) if err != nil { resp.Msg = err.Error() return diff --git a/frontend/src/components/sidebar/BrowserPane.vue b/frontend/src/components/sidebar/BrowserPane.vue index c6560d7..5bb61fc 100644 --- a/frontend/src/components/sidebar/BrowserPane.vue +++ b/frontend/src/components/sidebar/BrowserPane.vue @@ -152,6 +152,10 @@ const onDisconnect = () => { } const handleSelectDB = async (db) => { + if (db === props.db) { + return + } + try { loading.value = true browserStore.setKeyFilter(props.server, {}) diff --git a/frontend/src/components/sidebar/BrowserTree.vue b/frontend/src/components/sidebar/BrowserTree.vue index 1789853..ad853ed 100644 --- a/frontend/src/components/sidebar/BrowserTree.vue +++ b/frontend/src/components/sidebar/BrowserTree.vue @@ -295,7 +295,7 @@ const onUpdateSelectedKeys = (keys, options) => { } } // default is load blank key to display server status - tabStore.openBlank(props.server) + tabStore.openBlank(props.server, props.db) } finally { tabStore.setSelectedKeys(props.server, keys) } diff --git a/frontend/src/components/sidebar/ConnectionTree.vue b/frontend/src/components/sidebar/ConnectionTree.vue index c6b217f..4aa8a46 100644 --- a/frontend/src/components/sidebar/ConnectionTree.vue +++ b/frontend/src/components/sidebar/ConnectionTree.vue @@ -49,13 +49,6 @@ const contextMenuParam = reactive({ currentNode: null, }) -const renderIcon = (icon) => { - return () => { - return h(NIcon, null, { - default: () => h(icon), - }) - } -} const menuOptions = { [ConnectionType.Group]: ({ opened }) => [ { diff --git a/frontend/src/stores/tab.js b/frontend/src/stores/tab.js index 8120564..88b359b 100644 --- a/frontend/src/stores/tab.js +++ b/frontend/src/stores/tab.js @@ -151,7 +151,7 @@ const useTabStore = defineStore('tab', { }, openBlank(server) { - this.upsertTab({ server, db: 0 }) + this.upsertTab({ server }) }, /** @@ -194,7 +194,7 @@ const useTabStore = defineStore('tab', { // tab.title = db !== undefined ? `${server}/db${db}` : `${server}` tab.title = server tab.server = server - tab.db = db + tab.db = db == null ? tab.db : db tab.type = type tab.ttl = ttl tab.key = key