fix: expanded mark may not update
This commit is contained in:
parent
84b493b26a
commit
e2264b33b0
|
@ -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':
|
||||
node.expanded = false
|
||||
tabStore.removeExpandedKey(props.server, key)
|
||||
break
|
||||
tabStore.addExpandedKey(props.server, key)
|
||||
}
|
||||
} else {
|
||||
node.expanded = false
|
||||
tabStore.removeExpandedKey(props.server, key)
|
||||
}
|
||||
node = node.children[0]
|
||||
}
|
||||
if (size(node.children) === 1) {
|
||||
node = node.children[0]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
} while (true)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in New Issue