mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-26 07:57:36 +00:00
*PR Created by the Glary-Bot Agent* --- Group Nodes are a legacy feature superseded by Subgraphs. This PR removes every UI entry point for *creating* a new Group Node while keeping the loading, ungrouping, and management code intact so existing workflows that contain Group Nodes continue to load and can still be unpacked or managed. ## Removed creation entry points - `Comfy.GroupNode.ConvertSelectedNodesToGroupNode` command - `Alt+G` keybinding - "Convert to Group Node (Deprecated)" canvas and node right-click menu items (`groupNode.ts` `getCanvasMenuItems` / `getNodeMenuItems`) - "Convert to Group Node" entry in the Vue selection menu (`useSelectionMenuOptions.ts`) - Associated `MENU_ORDER` entry in `contextMenuConverter.ts` - `convertSelectedNodesToGroupNode` / `convertDisabled` helpers in `groupNode.ts` - `BadgeVariant.DEPRECATED` enum member (no remaining consumers; knip-clean) - Matching `en` locale strings in `main.json` (`contextMenu.Convert to Group Node`, `commands.Convert selected nodes to group node`) and `commands.json` (`Comfy_GroupNode_ConvertSelectedNodesToGroupNode`) - Browser-test helpers `convertToGroupNode` / `convertAllNodesToGroupNode` and the three tests that exercised the creation flow ## Preserved (intentionally) - `GroupNodeHandler`, `GroupNodeConfig`, `GroupNodeBuilder`, `ManageGroupDialog` - `beforeConfigureGraph` / `nodeCreated` hooks that load and initialize Group Nodes from saved workflows - "Manage Group Nodes" canvas menu item, the `Comfy.GroupNode.ManageGroupNodes` command, and the per-node "Manage Group Node" / "Convert to nodes" options on existing group node instances - "Ungroup selected group nodes" command + `Alt+Shift+G` keybinding so users can disassemble existing group nodes in legacy workflows - Reduced `browser_tests/tests/groupNode.spec.ts` covering surviving behaviors: workflow loading (legacy `/` separator, hidden-input config, v1.3.3 fixture), copy/paste of already-loaded group nodes across workflows, and opening the Manage Group Node dialog ## Verification - `pnpm typecheck` clean - `pnpm typecheck:browser` clean - `pnpm format` clean - `pnpm knip` clean (no new findings; pre-existing flac.ts tag warning unchanged) - `pnpm test:unit` — 796 files, 10,789 tests pass (8 pre-existing skipped); includes a regression test in `useSelectionMenuOptions.test.ts` asserting the Vue selection menu no longer offers a Convert to Group Node option - Pre-commit hooks (oxfmt, oxlint, eslint, typecheck, typecheck:browser) passed - Manual verification against a live dev server: programmatically inspecting the GroupNode extension showed `getCanvasMenuItems` returns only `[Manage Group Nodes]`, `getNodeMenuItems` returns `[]`, and the `ConvertSelectedNodesToGroupNode` command + Alt+G keybinding are absent from the registries. Visually captured the node right-click menu (attached screenshot) — "Convert to Subgraph" remains, no "Convert to Group Node" entry - Browser E2E suite not executed locally (sandbox has no GPU and Playwright requires a full backend; the reduced spec will run in CI) - Non-English locales not modified — per `src/locales/CONTRIBUTING.md` they are regenerated by CI ## Notes for reviewers - This is a surgical removal of creation only; loading any older workflow that already contains group nodes will continue to work. - If you'd like to also remove the management UI (`Manage Group Nodes` command/menu/dialog) or the ungroup command in a follow-up, happy to open a separate PR. ## Screenshots  ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-12347-feat-remove-ability-to-create-Group-Nodes-3656d73d365081d488bfd98ffd7545c0) by [Unito](https://www.unito.io) --------- Co-authored-by: Glary-Bot <glary-bot@users.noreply.github.com> Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: Amp <amp@ampcode.com>
273 lines
7.9 KiB
TypeScript
273 lines
7.9 KiB
TypeScript
import type { Locator } from '@playwright/test'
|
|
|
|
import type {
|
|
GraphAddOptions,
|
|
LGraph,
|
|
LGraphNode
|
|
} from '@/lib/litegraph/src/litegraph'
|
|
import type {
|
|
ComfyWorkflowJSON,
|
|
NodeId
|
|
} from '@/platform/workflow/validation/schemas/workflowSchema'
|
|
import type { ComfyPage } from '@e2e/fixtures/ComfyPage'
|
|
import { DefaultGraphPositions } from '@e2e/fixtures/constants/defaultGraphPositions'
|
|
import type { Position, Size } from '@e2e/fixtures/types'
|
|
import { NodeReference } from '@e2e/fixtures/utils/litegraphUtils'
|
|
|
|
export class NodeOperationsHelper {
|
|
public readonly promptDialogInput: Locator
|
|
|
|
constructor(private comfyPage: ComfyPage) {
|
|
this.promptDialogInput = this.page.getByRole('dialog').getByRole('textbox')
|
|
}
|
|
|
|
private get page() {
|
|
return this.comfyPage.page
|
|
}
|
|
|
|
async getGraphNodesCount(): Promise<number> {
|
|
return await this.page.evaluate(() => {
|
|
return window.app?.graph?.nodes?.length || 0
|
|
})
|
|
}
|
|
|
|
async getSelectedGraphNodesCount(): Promise<number> {
|
|
return await this.page.evaluate(() => {
|
|
return (
|
|
window.app?.graph?.nodes?.filter(
|
|
(node: LGraphNode) => node.is_selected === true
|
|
).length || 0
|
|
)
|
|
})
|
|
}
|
|
|
|
async getSelectedNodeIds(): Promise<NodeId[]> {
|
|
return await this.page.evaluate(() => {
|
|
const selected = window.app?.canvas?.selected_nodes
|
|
if (!selected) return []
|
|
return Object.keys(selected).map(Number)
|
|
})
|
|
}
|
|
|
|
/**
|
|
* Add a node to the graph by type.
|
|
* @param type - The node type (e.g. 'KSampler', 'VAEDecode')
|
|
* @param options - GraphAddOptions (ghost, skipComputeOrder). When ghost is
|
|
* true and position is provided, a synthetic MouseEvent is created as the
|
|
* dragEvent.
|
|
* @param position - When ghost is true, client coordinates for the ghost
|
|
* placement dragEvent. Otherwise, world coordinates assigned to node.pos.
|
|
*/
|
|
async addNode(
|
|
type: string,
|
|
options?: Omit<GraphAddOptions, 'dragEvent'>,
|
|
position?: Position
|
|
): Promise<NodeReference> {
|
|
const id = await this.page.evaluate(
|
|
([nodeType, opts, pos]) => {
|
|
const node = window.LiteGraph!.createNode(nodeType)!
|
|
const addOpts: Record<string, unknown> = { ...opts }
|
|
if (opts?.ghost && pos) {
|
|
addOpts.dragEvent = new MouseEvent('click', {
|
|
clientX: pos.x,
|
|
clientY: pos.y
|
|
})
|
|
} else if (pos) {
|
|
node.pos = [pos.x, pos.y]
|
|
}
|
|
window.app!.graph.add(node, addOpts as GraphAddOptions)
|
|
return node.id
|
|
},
|
|
[type, options ?? {}, position ?? null] as const
|
|
)
|
|
return new NodeReference(id, this.comfyPage)
|
|
}
|
|
|
|
/** Remove all nodes from the graph and clean. */
|
|
async clearGraph() {
|
|
await this.comfyPage.settings.setSetting('Comfy.ConfirmClear', false)
|
|
await this.comfyPage.command.executeCommand('Comfy.ClearWorkflow')
|
|
}
|
|
|
|
/** Reads from `window.app.graph` (the root workflow graph). */
|
|
async getNodeCount(): Promise<number> {
|
|
return await this.page.evaluate(() => window.app!.graph.nodes.length)
|
|
}
|
|
|
|
async getNodes(): Promise<LGraphNode[]> {
|
|
return await this.page.evaluate(() => {
|
|
return window.app!.graph.nodes
|
|
})
|
|
}
|
|
|
|
async waitForGraphNodes(count: number): Promise<void> {
|
|
await this.page.waitForFunction((count) => {
|
|
return window.app?.canvas.graph?.nodes?.length === count
|
|
}, count)
|
|
}
|
|
|
|
async getFirstNodeRef(): Promise<NodeReference | null> {
|
|
const id = await this.page.evaluate(() => {
|
|
return window.app!.graph.nodes[0]?.id
|
|
})
|
|
if (!id) return null
|
|
return this.getNodeRefById(id)
|
|
}
|
|
|
|
async getNodeRefById(id: NodeId): Promise<NodeReference> {
|
|
return new NodeReference(id, this.comfyPage)
|
|
}
|
|
|
|
async getNodeRefsByType(
|
|
type: string,
|
|
includeSubgraph: boolean = false
|
|
): Promise<NodeReference[]> {
|
|
return Promise.all(
|
|
(
|
|
await this.page.evaluate(
|
|
({ type, includeSubgraph }) => {
|
|
const graph = (
|
|
includeSubgraph ? window.app!.canvas.graph : window.app!.graph
|
|
) as LGraph
|
|
const nodes = graph.nodes
|
|
return nodes
|
|
.filter((n: LGraphNode) => n.type === type)
|
|
.map((n: LGraphNode) => n.id)
|
|
},
|
|
{ type, includeSubgraph }
|
|
)
|
|
).map((id: NodeId) => this.getNodeRefById(id))
|
|
)
|
|
}
|
|
|
|
async getNodeRefsByTitle(title: string): Promise<NodeReference[]> {
|
|
return Promise.all(
|
|
(
|
|
await this.page.evaluate((title) => {
|
|
return window
|
|
.app!.graph.nodes.filter((n: LGraphNode) => n.title === title)
|
|
.map((n: LGraphNode) => n.id)
|
|
}, title)
|
|
).map((id: NodeId) => this.getNodeRefById(id))
|
|
)
|
|
}
|
|
|
|
async selectNodes(nodeTitles: string[]): Promise<void> {
|
|
await this.page.keyboard.down('Control')
|
|
try {
|
|
for (const nodeTitle of nodeTitles) {
|
|
const nodes = await this.getNodeRefsByTitle(nodeTitle)
|
|
for (const node of nodes) {
|
|
await node.click('title')
|
|
}
|
|
}
|
|
} finally {
|
|
await this.page.keyboard.up('Control')
|
|
await this.comfyPage.nextFrame()
|
|
}
|
|
}
|
|
|
|
async getSerializedGraph(): Promise<ComfyWorkflowJSON> {
|
|
return this.page.evaluate(
|
|
() => window.app!.graph.serialize() as ComfyWorkflowJSON
|
|
)
|
|
}
|
|
|
|
async loadGraph(data: ComfyWorkflowJSON): Promise<void> {
|
|
await this.page.evaluate(
|
|
(d) => window.app!.loadGraphData(d, true, true, null),
|
|
data
|
|
)
|
|
}
|
|
|
|
async repositionNodes(
|
|
positions: Record<string, [number, number]>
|
|
): Promise<void> {
|
|
const data = await this.getSerializedGraph()
|
|
applyNodePositions(data, positions)
|
|
await this.loadGraph(data)
|
|
}
|
|
|
|
async resizeNode(
|
|
nodePos: Position,
|
|
nodeSize: Size,
|
|
ratioX: number,
|
|
ratioY: number,
|
|
revertAfter: boolean = false
|
|
): Promise<void> {
|
|
const bottomRight = {
|
|
x: nodePos.x + nodeSize.width,
|
|
y: nodePos.y + nodeSize.height
|
|
}
|
|
const target = {
|
|
x: nodePos.x + nodeSize.width * ratioX,
|
|
y: nodePos.y + nodeSize.height * ratioY
|
|
}
|
|
// -1 to be inside the node. -2 because nodes currently get an arbitrary +1 to width.
|
|
await this.comfyPage.canvasOps.dragAndDrop(
|
|
{ x: bottomRight.x - 2, y: bottomRight.y - 1 },
|
|
target
|
|
)
|
|
if (revertAfter) {
|
|
await this.comfyPage.canvasOps.dragAndDrop(
|
|
{ x: target.x - 2, y: target.y - 1 },
|
|
bottomRight
|
|
)
|
|
}
|
|
}
|
|
|
|
async fillPromptDialog(value: string): Promise<void> {
|
|
await this.promptDialogInput.fill(value)
|
|
await this.page.keyboard.press('Enter')
|
|
await this.promptDialogInput.waitFor({ state: 'hidden' })
|
|
await this.comfyPage.nextFrame()
|
|
}
|
|
|
|
async panToNode(nodeRef: NodeReference): Promise<void> {
|
|
const nodePos = await nodeRef.getPosition()
|
|
await this.page.evaluate((pos) => {
|
|
const canvas = window.app!.canvas
|
|
canvas.ds.offset[0] = -pos.x + canvas.canvas.width / 2
|
|
canvas.ds.offset[1] = -pos.y + canvas.canvas.height / 2 + 100
|
|
canvas.setDirty(true, true)
|
|
}, nodePos)
|
|
await this.comfyPage.nextFrame()
|
|
}
|
|
|
|
async selectNodeWithPan(nodeRef: NodeReference): Promise<void> {
|
|
await this.panToNode(nodeRef)
|
|
await nodeRef.click('title')
|
|
}
|
|
|
|
async dragTextEncodeNode2(): Promise<void> {
|
|
await this.comfyPage.canvasOps.dragAndDrop(
|
|
DefaultGraphPositions.textEncodeNode2,
|
|
{
|
|
x: DefaultGraphPositions.textEncodeNode2.x,
|
|
y: 300
|
|
}
|
|
)
|
|
}
|
|
|
|
async adjustEmptyLatentWidth(): Promise<void> {
|
|
await this.page.locator('#graph-canvas').click({
|
|
position: DefaultGraphPositions.emptyLatentWidgetClick
|
|
})
|
|
const dialogInput = this.page.locator('.graphdialog input[type="text"]')
|
|
await dialogInput.click()
|
|
await dialogInput.fill('128')
|
|
await dialogInput.press('Enter')
|
|
await this.comfyPage.nextFrame()
|
|
}
|
|
}
|
|
|
|
function applyNodePositions(
|
|
data: ComfyWorkflowJSON,
|
|
positions: Record<string, [number, number]>
|
|
): void {
|
|
for (const node of data.nodes) {
|
|
const pos = positions[String(node.id)]
|
|
if (pos) node.pos = pos
|
|
}
|
|
}
|