fix: expanded mark may not update

This commit is contained in:
Lykin 2024-05-11 13:01:20 +08:00
parent 84b493b26a
commit e2264b33b0
2 changed files with 38 additions and 22 deletions

View File

@ -240,29 +240,35 @@ const onUpdateSelectedKeys = (keys, options) => {
} }
const onUpdateExpanded = (value, option, meta) => { const onUpdateExpanded = (value, option, meta) => {
tabStore.setExpandedKeys(props.server, value) const expand = meta.action === 'expand'
if (!meta.node) { if (expand) {
tabStore.addExpandedKey(props.server, value)
} else {
tabStore.removeExpandedKey(props.server, value)
}
let node = meta.node
if (!node) {
return return
} }
// keep expand or collapse children while they own more than 1 child // keep expand or collapse children while they own more than 1 child
let node = meta.node do {
while (node != null && size(node.children) === 1) { const key = node.key
const key = node.children[0].key if (expand) {
switch (meta.action) { if (node.type === ConnectionType.RedisKey) {
case 'expand':
node.expanded = true node.expanded = true
if (!includes(value, key)) {
tabStore.addExpandedKey(props.server, key) tabStore.addExpandedKey(props.server, key)
} }
break } else {
case 'collapse':
node.expanded = false node.expanded = false
tabStore.removeExpandedKey(props.server, key) tabStore.removeExpandedKey(props.server, key)
}
if (size(node.children) === 1) {
node = node.children[0]
} else {
break break
} }
node = node.children[0] } while (true)
}
} }
/** /**

View File

@ -1,4 +1,4 @@
import { assign, find, findIndex, get, indexOf, isEmpty, pullAt, remove, set, size } from 'lodash' import { assign, find, findIndex, get, includes, indexOf, isEmpty, pullAt, remove, set, size } from 'lodash'
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import { TabItem } from '@/objects/tabItem.js' import { TabItem } from '@/objects/tabItem.js'
@ -658,12 +658,15 @@ const useTabStore = defineStore('tab', {
/** /**
* set expanded keys for server * set expanded keys for server
* @param {string} server * @param {string} server
* @param {string[]} keys * @param {string|string[]} keys
*/ */
setExpandedKeys(server, keys = []) { setExpandedKeys(server, keys = []) {
/** @type TabItem**/ /** @type TabItem**/
let tab = find(this.tabList, { name: server }) let tab = find(this.tabList, { name: server })
if (tab != null) { if (tab != null) {
if (typeof keys === 'string') {
keys = [keys]
}
if (isEmpty(keys)) { if (isEmpty(keys)) {
tab.expandedKeys = [] tab.expandedKeys = []
} else { } else {
@ -675,13 +678,20 @@ const useTabStore = defineStore('tab', {
/** /**
* *
* @param {string} server * @param {string} server
* @param {string} key * @param {string|string[]} keys
*/ */
addExpandedKey(server, key) { addExpandedKey(server, keys) {
/** @type TabItem**/ /** @type TabItem**/
let tab = find(this.tabList, { name: server }) let tab = find(this.tabList, { name: server })
if (tab != null) { if (tab != null) {
tab.expandedKeys.push(key) if (typeof keys === 'string') {
keys = [keys]
}
for (const k of keys) {
if (!includes(tab.expandedKeys, k)) {
tab.expandedKeys.push(k)
}
}
} }
}, },