feat: add a root node for multiple selection and deselection in multi-selection mode

This commit is contained in:
Lykin 2023-12-27 18:23:40 +08:00
parent b7433fadaa
commit 93b04071e2
4 changed files with 27 additions and 18 deletions

View File

@ -40,6 +40,7 @@ const props = defineProps({
const themeVars = useThemeVars() const themeVars = useThemeVars()
const render = useRender() const render = useRender()
const i18n = useI18n() const i18n = useI18n()
/** @type {Ref<UnwrapRef<string[]>>} */
const expandedKeys = ref([]) const expandedKeys = ref([])
const connectionStore = useConnectionStore() const connectionStore = useConnectionStore()
const browserStore = useBrowserStore() const browserStore = useBrowserStore()
@ -47,15 +48,6 @@ const prefStore = usePreferencesStore()
const tabStore = useTabStore() const tabStore = useTabStore()
const dialogStore = useDialogStore() const dialogStore = useDialogStore()
watchEffect(
() => {
if (!props.checkMode) {
tabStore.setCheckedKeys(props.server)
}
},
{ flush: 'post' },
)
/** /**
* *
* @type {ComputedRef<string[]>} * @type {ComputedRef<string[]>}
@ -82,9 +74,7 @@ const checkedKeys = computed(() => {
}) })
const data = computed(() => { const data = computed(() => {
// const dbs = get(browserStore.databases, props.server, []) return browserStore.getKeyStruct(props.server, props.checkMode)
// return dbs
return browserStore.getKeyList(props.server)
}) })
const backgroundColor = computed(() => { const backgroundColor = computed(() => {
@ -178,6 +168,10 @@ const renderContextLabel = (option) => {
return h('div', { class: 'context-menu-item' }, option.label) return h('div', { class: 'context-menu-item' }, option.label)
} }
/**
*
* @param {string} key
*/
const expandKey = (key) => { const expandKey = (key) => {
const idx = indexOf(expandedKeys.value, key) const idx = indexOf(expandedKeys.value, key)
if (idx === -1) { if (idx === -1) {
@ -563,6 +557,17 @@ const handleOutsideContextMenu = () => {
contextMenuParam.show = false contextMenuParam.show = false
} }
watchEffect(
() => {
if (!props.checkMode) {
tabStore.setCheckedKeys(props.server)
} else {
expandKey(`${ConnectionType.RedisDB}`)
}
},
{ flush: 'post' },
)
// the NTree node may get incorrect height after change data // the NTree node may get incorrect height after change data
// add key property to force refresh the component and then everything back to normal // add key property to force refresh the component and then everything back to normal
const treeKey = ref(0) const treeKey = ref(0)

View File

@ -112,7 +112,7 @@ export class RedisServerState {
// create root node // create root node
root = new RedisNodeItem({ root = new RedisNodeItem({
key: rootKey, key: rootKey,
label: this.separator, label: `db${this.db}`,
type: ConnectionType.RedisDB, type: ConnectionType.RedisDB,
children: [], children: [],
}) })

View File

@ -148,17 +148,21 @@ const useBrowserStore = defineStore('browser', {
}, },
/** /**
* get key list in current database * get key struct in current database
* @param server * @param {string} server
* @param {boolean} [includeRoot]
* @return {RedisNodeItem[]} * @return {RedisNodeItem[]}
*/ */
getKeyList(server) { getKeyStruct(server, includeRoot) {
/** @type {RedisServerState} **/ /** @type {RedisServerState} **/
const serverInst = this.servers[server] const serverInst = this.servers[server]
let rootNode = null let rootNode = null
if (serverInst != null) { if (serverInst != null) {
rootNode = serverInst.getRoot() rootNode = serverInst.getRoot()
} }
if (includeRoot === true) {
return [rootNode]
}
return get(rootNode, 'children', []) return get(rootNode, 'children', [])
}, },

View File

@ -29,8 +29,8 @@ const useTabStore = defineStore('tab', {
/** /**
* @typedef {Object} CheckedKey * @typedef {Object} CheckedKey
* @property {string[]} key * @property {string} key
* @property {string[]} redisKey * @property {string} [redisKey]
*/ */
/** /**