From 9cea54686a6d0b7ca3bc1803196865da716601c0 Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Fri, 16 Aug 2024 13:22:17 -0400 Subject: [PATCH] Pin reroute on link release searchbox (#469) * Correctly handle wildcard type * Add test * nit * Pin reroute on link release search * Connect wildcard * nit --- browser_tests/ComfyPage.ts | 10 ++++++++-- browser_tests/nodeSearchBox.spec.ts | 10 ++++++++-- src/components/searchbox/NodeSearchBox.vue | 18 ++++++++++++------ .../searchbox/NodeSearchBoxPopover.vue | 4 ++++ src/services/nodeSearchService.ts | 8 +++++++- src/types/litegraphTypes.ts | 3 ++- tests-ui/tests/nodeSearchService.test.ts | 2 ++ 7 files changed, 43 insertions(+), 12 deletions(-) diff --git a/browser_tests/ComfyPage.ts b/browser_tests/ComfyPage.ts index f8f16071..caa8ae92 100644 --- a/browser_tests/ComfyPage.ts +++ b/browser_tests/ComfyPage.ts @@ -26,14 +26,20 @@ class ComfyNodeSearchBox { ) } - async fillAndSelectFirstNode(nodeName: string) { + async fillAndSelectFirstNode( + nodeName: string, + options?: { suggestionIndex: number } + ) { await this.input.waitFor({ state: 'visible' }) await this.input.fill(nodeName) await this.dropdown.waitFor({ state: 'visible' }) // Wait for some time for the auto complete list to update. // The auto complete list is debounced and may take some time to update. await this.page.waitForTimeout(500) - await this.dropdown.locator('li').nth(0).click() + await this.dropdown + .locator('li') + .nth(options?.suggestionIndex || 0) + .click() } } diff --git a/browser_tests/nodeSearchBox.spec.ts b/browser_tests/nodeSearchBox.spec.ts index 0805d532..673a0db9 100644 --- a/browser_tests/nodeSearchBox.spec.ts +++ b/browser_tests/nodeSearchBox.spec.ts @@ -35,7 +35,10 @@ test.describe('Node search box', () => { test('Can auto link node', async ({ comfyPage }) => { await comfyPage.disconnectEdge() - await comfyPage.searchBox.fillAndSelectFirstNode('CLIPTextEncode') + // Select the second item as the first item is always reroute + await comfyPage.searchBox.fillAndSelectFirstNode('CLIPTextEncode', { + suggestionIndex: 1 + }) await expect(comfyPage.canvas).toHaveScreenshot('auto-linked-node.png') }) @@ -54,7 +57,10 @@ test.describe('Node search box', () => { await comfyPage.dragAndDrop(outputSlot1Pos, emptySpacePos) await comfyPage.page.keyboard.up('Shift') - await comfyPage.searchBox.fillAndSelectFirstNode('Load Checkpoint') + // Select the second item as the first item is always reroute + await comfyPage.searchBox.fillAndSelectFirstNode('Load Checkpoint', { + suggestionIndex: 1 + }) await expect(comfyPage.canvas).toHaveScreenshot( 'auto-linked-node-batch.png' ) diff --git a/src/components/searchbox/NodeSearchBox.vue b/src/components/searchbox/NodeSearchBox.vue index 2877b94a..b918a0df 100644 --- a/src/components/searchbox/NodeSearchBox.vue +++ b/src/components/searchbox/NodeSearchBox.vue @@ -78,6 +78,11 @@ const props = defineProps({ searchLimit: { type: Number, default: 64 + }, + // TODO: Find a more flexible mechanism to add pinned nodes + includeReroute: { + type: Boolean, + default: false } }) @@ -91,13 +96,14 @@ const placeholder = computed(() => { const search = (query: string) => { currentQuery.value = query - suggestions.value = useNodeDefStore().nodeSearchService.searchNode( - query, - props.filters, - { + suggestions.value = [ + ...(props.includeReroute + ? [useNodeDefStore().nodeDefsByName['Reroute']] + : []), + ...useNodeDefStore().nodeSearchService.searchNode(query, props.filters, { limit: props.searchLimit - } - ) + }) + ] } const highlightQuery = (text: string, query: string) => { diff --git a/src/components/searchbox/NodeSearchBoxPopover.vue b/src/components/searchbox/NodeSearchBoxPopover.vue index 7ae1928a..5cc1ae7a 100644 --- a/src/components/searchbox/NodeSearchBoxPopover.vue +++ b/src/components/searchbox/NodeSearchBoxPopover.vue @@ -20,6 +20,7 @@