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) => {
tabStore.setExpandedKeys(props.server, value)
if (!meta.node) {
const expand = meta.action === 'expand'
if (expand) {
tabStore.addExpandedKey(props.server, value)
} else {
tabStore.removeExpandedKey(props.server, value)
}
let node = meta.node
if (!node) {
return
}
// keep expand or collapse children while they own more than 1 child
let node = meta.node
while (node != null && size(node.children) === 1) {
const key = node.children[0].key
switch (meta.action) {
case 'expand':
do {
const key = node.key
if (expand) {
if (node.type === ConnectionType.RedisKey) {
node.expanded = true
if (!includes(value, key)) {
tabStore.addExpandedKey(props.server, key)
}
break
case 'collapse':
} else {
node.expanded = false
tabStore.removeExpandedKey(props.server, key)
}
if (size(node.children) === 1) {
node = node.children[0]
} else {
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 { TabItem } from '@/objects/tabItem.js'
@ -658,12 +658,15 @@ const useTabStore = defineStore('tab', {
/**
* set expanded keys for server
* @param {string} server
* @param {string[]} keys
* @param {string|string[]} keys
*/
setExpandedKeys(server, keys = []) {
/** @type TabItem**/
let tab = find(this.tabList, { name: server })
if (tab != null) {
if (typeof keys === 'string') {
keys = [keys]
}
if (isEmpty(keys)) {
tab.expandedKeys = []
} else {
@ -675,13 +678,20 @@ const useTabStore = defineStore('tab', {
/**
*
* @param {string} server
* @param {string} key
* @param {string|string[]} keys
*/
addExpandedKey(server, key) {
addExpandedKey(server, keys) {
/** @type TabItem**/
let tab = find(this.tabList, { name: server })
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)
}
}
}
},