Skip to content

Commit

Permalink
Fix create group node command error states (#1209)
Browse files Browse the repository at this point in the history
* Fix edge cases

* Add playwright test

* nit
  • Loading branch information
huchenlei authored Oct 10, 2024
1 parent b89f467 commit ec8e6f7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 15 deletions.
4 changes: 4 additions & 0 deletions browser_tests/ComfyPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,10 @@ export class ComfyPage {
await this.nextFrame()
}

async getVisibleToastCount() {
return await this.page.locator('.p-toast:visible').count()
}

async clickTextEncodeNode1() {
await this.canvas.click({
position: {
Expand Down
16 changes: 16 additions & 0 deletions browser_tests/groupNode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,20 @@ test.describe('Group Node', () => {
})
})
})

test.describe('Keybindings', () => {
test('Convert to group node, no selection', async ({ comfyPage }) => {
expect(await comfyPage.getVisibleToastCount()).toBe(0)
await comfyPage.page.keyboard.press('Alt+g')
await comfyPage.page.waitForTimeout(300)
expect(await comfyPage.getVisibleToastCount()).toBe(1)
})
test('Convert to group node, selected 1 node', async ({ comfyPage }) => {
expect(await comfyPage.getVisibleToastCount()).toBe(0)
await comfyPage.clickTextEncodeNode1()
await comfyPage.page.keyboard.press('Alt+g')
await comfyPage.page.waitForTimeout(300)
expect(await comfyPage.getVisibleToastCount()).toBe(1)
})
})
})
35 changes: 20 additions & 15 deletions src/extensions/core/groupNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1450,22 +1450,27 @@ const replaceLegacySeparators = (nodes: ComfyNode[]): void => {
}
}

function convertSelectedNodesToGroupNode() {
if (
!app.canvas.selected_nodes ||
Object.keys(app.canvas.selected_nodes).length === 0
) {
useToastStore().add({
severity: 'error',
summary: 'No nodes selected',
detail: 'Please select nodes to convert to group node',
life: 3000
})
return
/**
* Convert selected nodes to a group node
* @throws {Error} if no nodes are selected
* @throws {Error} if a group node is already selected
* @throws {Error} if a group node is selected
*
* The context menu item should not be available if any of the above conditions are met.
* The error is automatically handled by the commandStore when the command is executed.
*/
async function convertSelectedNodesToGroupNode() {
const nodes = Object.values(app.canvas.selected_nodes ?? {})
if (nodes.length === 0) {
throw new Error('No nodes selected')
}

const nodes = Object.values(app.canvas.selected_nodes)
return GroupNodeHandler.fromNodes(nodes)
if (nodes.length === 1) {
throw new Error('Please select multiple nodes to convert to group node')
}
if (nodes.some((n) => GroupNodeHandler.isGroupNode(n))) {
throw new Error('Selected nodes contain a group node')
}
return await GroupNodeHandler.fromNodes(nodes)
}

function ungroupSelectedGroupNodes() {
Expand Down

0 comments on commit ec8e6f7

Please sign in to comment.