Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
feat(webv2): render the graph preview's list mode with the shared list
Josh Corbettb8aab0d90831
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewDialog.browser.test.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewDialog.browser.test.tsxindex 9856bb82b1..1ac2718156 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewDialog.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewDialog.browser.test.tsx@@ -428,6 +428,10 @@ describe('GraphPreviewDialog', () => {await act(() => {tab?.click();});+ // List mode loads on demand; wait for its rows before acting on them.+ if (mode === 'list') {+ await vi.waitFor(() => expect(document.querySelector('[role="list"] [data-list-primary]')).not.toBeNull());+ }};const clickButtonWithText = async (text: string) => {@@ -622,6 +626,27 @@ describe('GraphPreviewDialog', () => {expect(fitViewMock).toHaveBeenCalledWith(expect.objectContaining({ nodes: [{ id: 'denoise_latents' }] }));});+ it('lists nodes as a named list and marks the selected node when returning to list mode', async () => {+ await renderDialog(FIXTURE_SOURCE);++ await switchToMode('list');+ const list = () => document.querySelector<HTMLElement>('[role="list"][aria-label="Nodes"]');++ expect(list()).not.toBeNull();+ expect(list()!.querySelectorAll('[role="listitem"]').length).toBeGreaterThan(1);+ expect(list()!.querySelector('[aria-current="true"]')).toBeNull();++ await clickButtonWithText('denoise_latents');+ await switchToMode('list');++ const current = list()!.querySelector<HTMLElement>('[data-list-primary][aria-current="true"]');++ expect(current?.textContent).toContain('denoise_latents');+ // The selected node is the list's single tab stop, so keyboard users land on it.+ expect(current?.tabIndex).toBe(0);+ expect(list()!.querySelectorAll('[data-list-primary][tabindex="0"]')).toHaveLength(1);+ });+it('show node selects the seed node and inspector shows the randomized override', async () => {await renderDialog(FIXTURE_SOURCE);diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewDialog.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewDialog.tsxindex 7bfc28d1e7..afcd3dfa1c 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewDialog.tsx+++ b/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewDialog.tsx@@ -2,16 +2,15 @@ import type { GraphPreviewSourceState, WorkflowInvocationSourceId } from '@featuimport type { ReactFlowInstance } from '@xyflow/react';import type { ReactNode } from 'react';-import { Box, Dialog, Icon, Portal, Stack, Text } from '@chakra-ui/react';+import { Box, Center, Dialog, Icon, Portal, Spinner, Stack, Text } from '@chakra-ui/react';import { localizeForLoopValidationReason } from '@features/workflow/core/forLoops';import { useWorkflowGraphPreview } from '@features/workflow/ui/WorkflowUiContext';import { Button, JsonPreview, SegmentTabs, segmentTabsPanelId, segmentTabsTabId, toaster } from '@platform/ui';import { CheckIcon, ChevronUpIcon, CopyIcon, TriangleAlertIcon } from 'lucide-react';-import { useCallback, useId, useMemo, useRef, useState } from 'react';+import { lazy, Suspense, useCallback, useId, useMemo, useRef, useState } from 'react';import { useTranslation } from 'react-i18next';import { GraphPreviewFlow } from './GraphPreviewFlow';-import { GraphPreviewList } from './GraphPreviewList';import { GraphPreviewOpenAsMenu } from './GraphPreviewOpenAsMenu';import { GraphPreviewSidePanel } from './GraphPreviewSidePanel';@@ -40,6 +39,21 @@ const modeItems = [const COPY_RESET_DELAY_MS = 1500;const SELECT_AND_REVEAL_FIT_VIEW_OPTIONS = { duration: 150, maxZoom: 1 } as const;+// List mode brings the virtualized list; load it when chosen so the workflow route's startup does not carry it.+const GraphPreviewList = lazy(() =>+ import('./GraphPreviewList').then((module) => ({ default: module.GraphPreviewList }))+);+const ListFallback = () => {+ const { t } = useTranslation();++ return (+ <Center aria-label={t('common.loading')} h="full" role="status">+ <Spinner color="fg.subtle" size="sm" />+ </Center>+ );+};+const LIST_FALLBACK = <ListFallback />;+const PreviewPane = ({ children }: { children: ReactNode }) => (<Box flex="1" h="full" minH="0" minW="0" w="full" rounded="md" borderWidth={1} overflow="hidden">{children}@@ -228,7 +242,12 @@ export const GraphPreviewDialog = ({) : mode === 'json' ? (<JsonPreview h="full" label={jsonLabel} maxH="100%" value={graph} />) : mode === 'list' ? (- <GraphPreviewList graph={graph} onSelect={selectAndReveal} />+ // The inset keeps the first row off the pane's rounded border.+ <Box display="flex" flexDirection="column" h="full" pt="2">+ <Suspense fallback={LIST_FALLBACK}>+ <GraphPreviewList graph={graph} selectedNodeId={selectedNodeId} onSelect={selectAndReveal} />+ </Suspense>+ </Box>) : (<GraphPreviewFlowgraph={graph}diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewList.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewList.tsxindex b17074b6fd..25b7e2d661 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewList.tsx+++ b/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewList.tsx@@ -1,71 +1,72 @@import type { WorkflowPreviewGraph } from '@features/workflow/ui/contracts';+import type { ListRowProps } from '@platform/ui/list/List';-import { Badge, Button, Stack, Text } from '@chakra-ui/react';import { getTopologicalOrder } from '@features/workflow/core/graphLayout';-import { useCallback, useMemo } from 'react';+import { List } from '@platform/ui/list/List';+import { ListItem } from '@platform/ui/list/ListItem';+import { listRowsFromItems } from '@platform/ui/list/listRows';+import { memo, useCallback, useMemo } from 'react';import { useTranslation } from 'react-i18next';import { getNodeSubtitle } from './nodeSummaries';type PreviewListNode = WorkflowPreviewGraph['nodes'][number];-const GraphPreviewListRow = ({ node, onSelect }: { node: PreviewListNode; onSelect: (nodeId: string) => void }) => {+const getNodeId = (node: PreviewListNode): string => node.id;++const GraphPreviewListRow = memo(function GraphPreviewListRow({+ node,+ onSelect,+ ...rowProps+}: ListRowProps & { node: PreviewListNode; onSelect: (nodeId: string) => void }) {const { t } = useTranslation();const subtitle =getNodeSubtitle(node, t) ??`${node.id} · ${t('graphPreview.inputCount', { count: Object.keys(node.inputs).length })}`;- const handleClick = useCallback(() => onSelect(node.id), [node.id, onSelect]);+ const handlePress = useCallback(() => onSelect(node.id), [node.id, onSelect]);- return (- <Button- fontWeight="normal"- h="auto"- justifyContent="flex-start"- px="3"- py="2"- variant="ghost"- w="full"- onClick={handleClick}- >- <Stack align="flex-start" gap="0.5" w="full">- <Badge fontFamily="mono" size="xs">- {node.type}- </Badge>- <Text color="fg.muted" fontSize="2xs" fontWeight="normal" truncate>- {subtitle}- </Text>- </Stack>- </Button>- );-};+ return <ListItem {...rowProps} description={subtitle} title={node.type} onPress={handlePress} />;+});-/**- * Expose all nodes in topological rows for keyboard/screen-reader access to the shared inspector; plain Chakra- * avoids unnecessary platform-barrel fan-in.- */+/** Every node in topological order, for keyboard and screen-reader access to the shared inspector. */export const GraphPreviewList = ({graph,+ selectedNodeId,onSelect,}: {graph: WorkflowPreviewGraph;+ selectedNodeId: string | null;onSelect: (nodeId: string) => void;}) => {+ const { t } = useTranslation();// Recompute sorted rows only when the graph changes, not on unrelated live-source renders.- const orderedNodes = useMemo(() => {+ const rows = useMemo(() => {const nodesById = new Map(graph.nodes.map((node) => [node.id, node]));const order = getTopologicalOrder(graph.nodes,graph.edges.map((edge) => ({ sourceNodeId: edge.sourceNodeId, targetNodeId: edge.targetNodeId })));+ const orderedNodes = order+ .map((nodeId) => nodesById.get(nodeId))+ .filter((node): node is PreviewListNode => node !== undefined);- return order.map((nodeId) => nodesById.get(nodeId)).filter((node): node is PreviewListNode => node !== undefined);+ return listRowsFromItems(orderedNodes, getNodeId);}, [graph]);+ const renderItem = useCallback(+ (node: PreviewListNode, rowProps: ListRowProps) => (+ <GraphPreviewListRow {...rowProps} node={node} onSelect={onSelect} />+ ),+ [onSelect]+ );return (- <Stack gap="1" h="full" overflowY="auto" p="2">- {orderedNodes.map((node) => (- <GraphPreviewListRow key={node.id} node={node} onSelect={onSelect} />- ))}- </Stack>+ <List+ activeKey={selectedNodeId}+ dividers+ label={t('graphPreview.nodes')}+ renderItem={renderItem}+ revealActiveOnMount+ rows={rows}+ />);};