Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better badges for empty/loading model library folders #953

Merged
merged 6 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/components/common/TreeExplorer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,18 @@ const getTreeNodeIcon = (node: TreeExplorerNode) => {
}
const fillNodeInfo = (node: TreeExplorerNode): RenderedTreeExplorerNode => {
const children = node.children?.map(fillNodeInfo)
const totalLeaves = node.leaf
? 1
: children.reduce((acc, child) => acc + child.totalLeaves, 0)
return {
...node,
icon: getTreeNodeIcon(node),
children,
type: node.leaf ? 'node' : 'folder',
totalLeaves: node.leaf
? 1
: children.reduce((acc, child) => acc + child.totalLeaves, 0)
totalLeaves,
badgeText: node.getBadgeText
? node.getBadgeText(node)
: totalLeaves.toString()
mcmonkey4eva marked this conversation as resolved.
Show resolved Hide resolved
}
}
const onNodeContentClick = async (
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/TreeExplorerTreeNode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</span>
<Badge
v-if="!props.node.leaf"
:value="props.node.totalLeaves"
:value="props.node.badgeText"
severity="secondary"
class="leaf-count-badge"
/>
Expand Down
3 changes: 2 additions & 1 deletion src/components/common/__tests__/TreeExplorerTreeNode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
totalLeaves: 3,
icon: 'pi pi-folder',
type: 'folder',
handleRename: () => {}
handleRename: () => {},
badgeText: '3'
mcmonkey4eva marked this conversation as resolved.
Show resolved Hide resolved
} as RenderedTreeExplorerNode

beforeAll(() => {
Expand Down Expand Up @@ -56,7 +57,7 @@
expect(wrapper.findComponent(EditableText).props('modelValue')).toBe(
'Test Node'
)
expect(wrapper.findComponent(Badge).props()['value']).toBe(3)

Check failure on line 60 in src/components/common/__tests__/TreeExplorerTreeNode.spec.ts

View workflow job for this annotation

GitHub Actions / test

src/components/common/__tests__/TreeExplorerTreeNode.spec.ts > TreeExplorerTreeNode > renders correctly

AssertionError: expected '3' to be 3 // Object.is equality - Expected: 3 + Received: "3" ❯ src/components/common/__tests__/TreeExplorerTreeNode.spec.ts:60:59
})

it('makes node label editable when renamingEditingNode matches', async () => {
Expand Down
25 changes: 25 additions & 0 deletions src/components/sidebar/tabs/ModelLibrarySidebarTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,31 @@ const renderedRoot = computed<TreeExplorerNode<ComfyModelDef>>(() => {
return 'pi pi-file'
}
},
getBadgeText: (node: TreeExplorerNode<ComfyModelDef>) => {
if (node.leaf) {
return ''
}
if (node.children?.length === 1) {
const onlyChild = node.children[0]
if (onlyChild.data?.is_fake_object) {
if (onlyChild.data.name === '(No Content)') {
return '0'
} else if (onlyChild.data.name === 'Loading') {
return '?'
}
}
}
const getTotalLeaves = (node: TreeExplorerNode<ComfyModelDef>) => {
mcmonkey4eva marked this conversation as resolved.
Show resolved Hide resolved
if (node.leaf) {
return 1
}
return node.children.reduce(
(acc, child) => acc + getTotalLeaves(child),
0
)
}
return getTotalLeaves(node).toString()
},
children,
draggable: node.leaf,
handleClick: (
Expand Down
25 changes: 15 additions & 10 deletions src/types/treeExplorerTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,39 @@ export interface TreeExplorerNode<T = any> {
data?: T
children?: TreeExplorerNode<T>[]
icon?: string
/** Function to override what icon to use for the node */
getIcon?: (node: TreeExplorerNode<T>) => string
// Function to handle renaming the node
/** Function to override what text to use for the leaf-count badge on a folder node */
getBadgeText?: (node: TreeExplorerNode<T>) => string
/** Function to handle renaming the node */
handleRename?: (
node: TreeExplorerNode<T>,
newName: string
) => void | Promise<void>
// Function to handle deleting the node
/** Function to handle deleting the node */
handleDelete?: (node: TreeExplorerNode<T>) => void | Promise<void>
// Function to handle adding a child node
/** Function to handle adding a child node */
handleAddChild?: (
node: TreeExplorerNode<T>,
child: TreeExplorerNode<T>
) => void | Promise<void>
// Whether the node is draggable
/** Whether the node is draggable */
draggable?: boolean
// Whether the node is droppable
/** Whether the node is droppable */
droppable?: boolean
// Function to handle dropping a node
/** Function to handle dropping a node */
handleDrop?: (
node: TreeExplorerNode<T>,
data: TreeExplorerDragAndDropData
) => void | Promise<void>
// Function to handle clicking a node
/** Function to handle clicking a node */
handleClick?: (
node: TreeExplorerNode<T>,
event: MouseEvent
) => void | Promise<void>
// Function to handle errors
/** Function to handle errors */
handleError?: (error: Error) => void
// Extra context menu items
/** Extra context menu items */
contextMenuItems?:
| MenuItem[]
| ((targetNode: RenderedTreeExplorerNode) => MenuItem[])
Expand All @@ -46,8 +49,10 @@ export interface RenderedTreeExplorerNode<T = any> extends TreeExplorerNode<T> {
children?: RenderedTreeExplorerNode<T>[]
icon: string
type: 'folder' | 'node'
// Total number of leaves in the subtree
/** Total number of leaves in the subtree */
totalLeaves: number
/** Text to display on the leaf-count badge */
badgeText: string
mcmonkey4eva marked this conversation as resolved.
Show resolved Hide resolved
}

export type TreeExplorerDragAndDropData<T = any> = {
Expand Down
Loading