mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-13 17:10:06 +00:00
feat: read category from blueprint subgraph definition (#9053)
Read `category` from `definitions.subgraphs[0].category` in blueprint JSON files as a fallback default for node categorization. This allows blueprint authors to set the category directly in the blueprint file without needing backend `index.json` support. The precedence order is: 1. Explicit overrides (e.g. `info.category` from API, or `'Subgraph Blueprints/User'` for user blueprints) 2. `definitions.subgraphs[0].category` from the blueprint JSON content 3. Bare `'Subgraph Blueprints'` fallback Companion PR: Comfy-Org/ComfyUI#12552 (adds essential blueprints with categories matching the Figma design) ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-9053-feat-read-category-from-blueprint-subgraph-definition-30e6d73d3650810ca23bfc5a1e97cb31) by [Unito](https://www.unito.io) --------- Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
@@ -363,6 +363,96 @@ describe('useSubgraphStore', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('subgraph definition category', () => {
|
||||
it('should use category from subgraph definition as default', async () => {
|
||||
const mockGraphWithCategory = {
|
||||
nodes: [{ type: '123' }],
|
||||
definitions: {
|
||||
subgraphs: [{ id: '123', category: 'Image Processing' }]
|
||||
}
|
||||
}
|
||||
await mockFetch(
|
||||
{},
|
||||
{
|
||||
categorized: {
|
||||
name: 'Categorized Blueprint',
|
||||
info: { node_pack: 'test_pack' },
|
||||
data: JSON.stringify(mockGraphWithCategory)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
const nodeDef = useNodeDefStore().nodeDefs.find(
|
||||
(d) => d.name === 'SubgraphBlueprint.categorized'
|
||||
)
|
||||
expect(nodeDef).toBeDefined()
|
||||
expect(nodeDef?.category).toBe('Subgraph Blueprints/Image Processing')
|
||||
})
|
||||
|
||||
it('should use User override for user blueprints even with definition category', async () => {
|
||||
const mockGraphWithCategory = {
|
||||
nodes: [{ type: '123' }],
|
||||
definitions: {
|
||||
subgraphs: [{ id: '123', category: 'Image Processing' }]
|
||||
}
|
||||
}
|
||||
await mockFetch({ 'user-bp.json': mockGraphWithCategory })
|
||||
|
||||
const nodeDef = useNodeDefStore().nodeDefs.find(
|
||||
(d) => d.name === 'SubgraphBlueprint.user-bp'
|
||||
)
|
||||
expect(nodeDef).toBeDefined()
|
||||
expect(nodeDef?.category).toBe('Subgraph Blueprints/User')
|
||||
})
|
||||
|
||||
it('should fallback to bare Subgraph Blueprints when no category anywhere', async () => {
|
||||
await mockFetch(
|
||||
{},
|
||||
{
|
||||
no_cat_global: {
|
||||
name: 'No Category Global',
|
||||
info: { node_pack: 'test_pack' },
|
||||
data: JSON.stringify(mockGraph)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
const nodeDef = useNodeDefStore().nodeDefs.find(
|
||||
(d) => d.name === 'SubgraphBlueprint.no_cat_global'
|
||||
)
|
||||
expect(nodeDef).toBeDefined()
|
||||
expect(nodeDef?.category).toBe('Subgraph Blueprints')
|
||||
})
|
||||
|
||||
it('should let overrides take precedence over definition category', async () => {
|
||||
const mockGraphWithCategory = {
|
||||
nodes: [{ type: '123' }],
|
||||
definitions: {
|
||||
subgraphs: [{ id: '123', category: 'Image Processing' }]
|
||||
}
|
||||
}
|
||||
await mockFetch(
|
||||
{},
|
||||
{
|
||||
bp_override: {
|
||||
name: 'Override Blueprint',
|
||||
info: {
|
||||
node_pack: 'test_pack',
|
||||
category: 'Custom Category'
|
||||
},
|
||||
data: JSON.stringify(mockGraphWithCategory)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
const nodeDef = useNodeDefStore().nodeDefs.find(
|
||||
(d) => d.name === 'SubgraphBlueprint.bp_override'
|
||||
)
|
||||
expect(nodeDef).toBeDefined()
|
||||
expect(nodeDef?.category).toBe('Subgraph Blueprints/Custom Category')
|
||||
})
|
||||
})
|
||||
|
||||
describe('global blueprint filtering', () => {
|
||||
function globalBlueprint(
|
||||
overrides: Partial<GlobalSubgraphData['info']> = {}
|
||||
|
||||
Reference in New Issue
Block a user