-
Notifications
You must be signed in to change notification settings - Fork 433
Sync node help with selection and add watcher tests #7105
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import { storeToRefs } from 'pinia' | ||
| import { computed } from 'vue' | ||
| import { computed, watch } from 'vue' | ||
|
|
||
| import { useNodeLibrarySidebarTab } from '@/composables/sidebarTabs/useNodeLibrarySidebarTab' | ||
| import type { LGraphNode } from '@/lib/litegraph/src/litegraph' | ||
|
|
@@ -94,6 +94,19 @@ export function useSelectionState() { | |
| computeSelectionStatesFromNodes(selectedNodes.value) | ||
| ) | ||
|
|
||
| // Keep help panel in sync when it is open and the user changes selection. | ||
| watch( | ||
| () => nodeDef.value, | ||
| (def) => { | ||
| if (!nodeHelpStore.isHelpOpen || !def) return | ||
|
|
||
| const currentHelpNode = nodeHelpStore.currentHelpNode | ||
| if (currentHelpNode?.nodePath === def.nodePath) return | ||
|
|
||
| nodeHelpStore.openHelp(def) | ||
| } | ||
| ) | ||
|
Comment on lines
+98
to
+108
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this composable isn't |
||
|
|
||
| // On-demand computation (non-reactive) so callers can fetch fresh flags | ||
| const computeSelectionFlags = (): NodeSelectionState => | ||
| computeSelectionStatesFromNodes(selectedNodes.value) | ||
|
|
@@ -105,12 +118,11 @@ export function useSelectionState() { | |
|
|
||
| const isSidebarActive = | ||
| sidebarTabStore.activeSidebarTabId === nodeLibraryTabId | ||
| const currentHelpNode: any = nodeHelpStore.currentHelpNode | ||
| const currentHelpNode = nodeHelpStore.currentHelpNode | ||
| const isSameNodeHelpOpen = | ||
| isSidebarActive && | ||
| nodeHelpStore.isHelpOpen && | ||
| currentHelpNode && | ||
| currentHelpNode.nodePath === def.nodePath | ||
| currentHelpNode?.nodePath === def.nodePath | ||
|
|
||
| if (isSameNodeHelpOpen) { | ||
| nodeHelpStore.closeHelp() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import { createPinia, setActivePinia } from 'pinia' | ||
| import { beforeEach, describe, expect, test, vi } from 'vitest' | ||
| import { type Ref, ref } from 'vue' | ||
| import { nextTick, ref } from 'vue' | ||
| import type { Ref } from 'vue' | ||
|
|
||
| import { useSelectionState } from '@/composables/graph/useSelectionState' | ||
| import { useNodeLibrarySidebarTab } from '@/composables/sidebarTabs/useNodeLibrarySidebarTab' | ||
|
|
@@ -267,4 +268,57 @@ describe('useSelectionState', () => { | |
| expect(newIsPinned).toBe(false) | ||
| }) | ||
| }) | ||
|
|
||
| describe('Help Sync', () => { | ||
| test('opens help for newly selected node when help is open', async () => { | ||
| const nodeDefStore = useNodeDefStore() as any | ||
| nodeDefStore.fromLGraphNode.mockImplementation((node: TestNode) => ({ | ||
| nodePath: node.type | ||
| })) | ||
|
|
||
| const nodeHelpStore = useNodeHelpStore() as any | ||
| nodeHelpStore.isHelpOpen = true | ||
| nodeHelpStore.currentHelpNode = { nodePath: 'NodeA' } | ||
|
|
||
| const nodeA = createTestNode({ type: 'NodeA' }) | ||
| mockSelectedItems.value = [nodeA] | ||
|
|
||
| useSelectionState() | ||
|
|
||
| const nodeB = createTestNode({ type: 'NodeB' }) | ||
| mockSelectedItems.value = [nodeB] | ||
|
|
||
| await nextTick() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you use some of the test helpers to interact with this more like a user would? That way you wouldn't have to manually manage the DOM updates. |
||
|
|
||
| expect(nodeHelpStore.openHelp).toHaveBeenCalledWith({ | ||
| nodePath: 'NodeB' | ||
| }) | ||
| }) | ||
|
|
||
| test('does not reopen help when selection is unchanged or closed', async () => { | ||
| const nodeDefStore = useNodeDefStore() as any | ||
| nodeDefStore.fromLGraphNode.mockImplementation((node: TestNode) => ({ | ||
| nodePath: node.type | ||
| })) | ||
|
|
||
| const nodeHelpStore = useNodeHelpStore() as any | ||
| const nodeA = createTestNode({ type: 'NodeA' }) | ||
| mockSelectedItems.value = [nodeA] | ||
|
|
||
| useSelectionState() | ||
|
|
||
| // Help closed -> no call | ||
| nodeHelpStore.isHelpOpen = false | ||
| mockSelectedItems.value = [nodeA] | ||
| await nextTick() | ||
| expect(nodeHelpStore.openHelp).not.toHaveBeenCalled() | ||
|
|
||
| // Help open but same node -> no call | ||
| nodeHelpStore.isHelpOpen = true | ||
| nodeHelpStore.currentHelpNode = { nodePath: 'NodeA' } | ||
| mockSelectedItems.value = [nodeA] | ||
| await nextTick() | ||
| expect(nodeHelpStore.openHelp).not.toHaveBeenCalled() | ||
| }) | ||
| }) | ||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: Why a getter here if you're checking the value of the ref itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if you only want to fire it off if the value is defined, you could use whenever