fix: renaming keys may not refresh the browser view

This commit is contained in:
Lykin 2023-12-07 10:39:50 +08:00
parent d4d1c33cb3
commit 116513917d
1 changed files with 15 additions and 24 deletions

View File

@ -3,9 +3,9 @@ import {
endsWith, endsWith,
find, find,
get, get,
initial,
isEmpty, isEmpty,
join, join,
last,
map, map,
remove, remove,
set, set,
@ -1712,29 +1712,20 @@ const useBrowserStore = defineStore('browser', {
/** /**
* *
* @param {string} connName * @param {string} server
* @param {number} db * @param {number} db
* @param {string} key * @param {string} key
* @param {string} newKey * @param {string} newKey
* @private * @private
*/ */
_renameKeyNode(connName, db, key, newKey) { _renameKeyNode(server, db, key, newKey) {
const nodeMap = this._getNodeMap(connName, db) this._deleteKeyNode(server, db, key, false)
const nodeKey = `${ConnectionType.RedisValue}/${key}` const { success } = this._addKeyNodes(server, db, [newKey])
const newNodeKey = `${ConnectionType.RedisValue}/${newKey}`
const node = nodeMap.get(nodeKey) if (success) {
if (node != null) { const separator = this._getSeparator(server)
// replace node map item const layer = initial(key.split(separator)).join(separator)
const separator = this._getSeparator(connName) this._tidyNode(server, db, layer)
node.label = last(split(newKey, separator))
node.key = `${connName}/db${db}#${newNodeKey}`
node.redisKey = newKey
nodeMap[newNodeKey] = node
nodeMap.delete(nodeKey)
// replace key set item
const keySet = this._getKeySet(connName, db)
keySet.delete(key)
keySet.add(newKey)
} }
}, },
@ -1946,18 +1937,18 @@ const useBrowserStore = defineStore('browser', {
/** /**
* rename key * rename key
* @param {string} connName * @param {string} server
* @param {number} db * @param {number} db
* @param {string} key * @param {string} key
* @param {string} newKey * @param {string} newKey
* @returns {Promise<{[msg]: string, success: boolean, [nodeKey]: string}>} * @returns {Promise<{[msg]: string, success: boolean, [nodeKey]: string}>}
*/ */
async renameKey(connName, db, key, newKey) { async renameKey(server, db, key, newKey) {
const { success = false, msg } = await RenameKey(connName, db, key, newKey) const { success = false, msg } = await RenameKey(server, db, key, newKey)
if (success) { if (success) {
// delete old key and add new key struct // delete old key and add new key struct
this._renameKeyNode(connName, db, key, newKey) this._renameKeyNode(server, db, key, newKey)
return { success: true, nodeKey: `${connName}/db${db}#${ConnectionType.RedisValue}/${newKey}` } return { success: true, nodeKey: `${server}/db${db}#${ConnectionType.RedisValue}/${newKey}` }
} else { } else {
return { success: false, msg } return { success: false, msg }
} }