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 all 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
8 changes: 5 additions & 3 deletions src/components/common/TreeExplorer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,16 @@ 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) : null
}
}
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 ?? props.node.totalLeaves"
severity="secondary"
class="leaf-count-badge"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('TreeExplorerTreeNode', () => {
expect(wrapper.findComponent(EditableText).props('modelValue')).toBe(
'Test Node'
)
expect(wrapper.findComponent(Badge).props()['value']).toBe(3)
expect(wrapper.findComponent(Badge).props()['value'].toString()).toBe('3')
})

it('makes node label editable when renamingEditingNode matches', async () => {
Expand Down
16 changes: 16 additions & 0 deletions src/components/sidebar/tabs/ModelLibrarySidebarTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@ const renderedRoot = computed<TreeExplorerNode<ComfyModelDef>>(() => {
return 'pi pi-file'
}
},
getBadgeText: (node: TreeExplorerNode<ComfyModelDef>) => {
if (node.leaf) {
return null
}
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 '?'
}
}
}
return null
},
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
}

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