Skip to content

Commit

Permalink
Attach isLeaf info (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei authored Jul 29, 2024
1 parent 7d75cc9 commit 73f4e51
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/components/sidebar/tabs/NodeLibrarySideBarTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,8 @@ const renderedRoot = computed(() => {
return fillNodeInfo(root.value)
})
const fillNodeInfo = (node: TreeNode): TreeNode => {
const isLeaf = node.children === undefined || node.children.length === 0
const isExpanded = expandedKeys.value[node.key]
const icon = isLeaf
const icon = node.leaf
? 'pi pi-circle-fill'
: isExpanded
? 'pi pi-folder-open'
Expand All @@ -112,8 +111,8 @@ const fillNodeInfo = (node: TreeNode): TreeNode => {
...node,
icon,
children,
type: isLeaf ? 'node' : 'folder',
totalNodes: isLeaf
type: node.leaf ? 'node' : 'folder',
totalNodes: node.leaf
? 1
: children.reduce((acc, child) => acc + child.totalNodes, 0)
}
Expand Down
6 changes: 4 additions & 2 deletions src/stores/nodeDefStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ export const useNodeDefStore = defineStore('nodeDef', {
const root: TreeNode = {
key: 'root',
label: 'Nodes',
leaf: false,
children: []
}
for (const nodeDef of Object.values(state.nodeDefsByName)) {
Expand All @@ -270,15 +271,16 @@ export const useNodeDefStore = defineStore('nodeDef', {
key += `/${part}`
let next = current.children.find((child) => child.label === part)
if (!next) {
next = { key, label: part, children: [] }
next = { key, label: part, children: [], leaf: false }
current.children.push(next)
}
current = next
}
current.children.push({
label: nodeDef.display_name,
data: nodeDef,
key: `${key}/${nodeDef.name}`
key: `${key}/${nodeDef.name}`,
leaf: true
})
}
return root
Expand Down

0 comments on commit 73f4e51

Please sign in to comment.