Skip to content

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.

fix(webv2): refine graph preview layout

joshistoastd37d77f9bd66
diff --git a/invokeai/frontend/webv2/src/workbench/components/GraphPreviewDialog.tsx b/invokeai/frontend/webv2/src/workbench/components/GraphPreviewDialog.tsx
index dd3826e9e9..10c4c3d124 100644
--- a/invokeai/frontend/webv2/src/workbench/components/GraphPreviewDialog.tsx
+++ b/invokeai/frontend/webv2/src/workbench/components/GraphPreviewDialog.tsx
@@ -1,5 +1,5 @@
import { Box, Dialog, Portal, SegmentGroup, Text } from '@chakra-ui/react';
-import { useState } from 'react';
+import { useState, type ReactNode } from 'react';
import { formatRoute, isInvocationRouteValid, resolveInvocationRoute } from '../invocation';
import type { GraphContract, GraphId, InvocationSourceId } from '../types';
@@ -22,6 +22,12 @@ interface GraphPreviewDialogProps {
type PreviewMode = 'nodes' | 'json';
+const PreviewPane = ({ children }: { children: ReactNode }) => (
+ <Box flex="1" h="full" minH="0" minW="0" w="full">
+ {children}
+ </Box>
+);
+
export const GraphPreviewDialog = ({
graph,
graphId,
@@ -44,7 +50,7 @@ export const GraphPreviewDialog = ({
<Portal>
<Dialog.Backdrop />
<Dialog.Positioner>
- <Dialog.Content h="75vh" maxH="75vh">
+ <Dialog.Content h="62vh" maxH="62vh">
<Dialog.Header alignItems="center" flexDirection="row" justifyContent="space-between">
<Dialog.Title>{title} Graph Preview</Dialog.Title>
<SegmentGroup.Root
@@ -61,17 +67,19 @@ export const GraphPreviewDialog = ({
/>
</SegmentGroup.Root>
</Dialog.Header>
- <Dialog.Body display="flex" flexDirection="column" minH="0">
+ <Dialog.Body display="flex" flex="1" flexDirection="column" minH="0">
{!graph ? (
<Text color="fg.muted" fontSize="sm">
No compiled graph is available for "{graphId}" yet.
</Text>
) : mode === 'nodes' ? (
- <Box flex="1" minH="0">
+ <PreviewPane>
<GraphPreviewFlow graph={graph} positionHints={positionHints} />
- </Box>
+ </PreviewPane>
) : (
- <JsonPreview label={`${title} graph JSON`} value={graph} />
+ <PreviewPane>
+ <JsonPreview h="full" label={`${title} graph JSON`} maxH="100%" value={graph} />
+ </PreviewPane>
)}
</Dialog.Body>
<Dialog.Footer>
diff --git a/invokeai/frontend/webv2/src/workbench/components/GraphPreviewFlow.tsx b/invokeai/frontend/webv2/src/workbench/components/GraphPreviewFlow.tsx
index 396148e799..fc47ab8c99 100644
--- a/invokeai/frontend/webv2/src/workbench/components/GraphPreviewFlow.tsx
+++ b/invokeai/frontend/webv2/src/workbench/components/GraphPreviewFlow.tsx
@@ -10,12 +10,13 @@ import {
type NodeProps,
type NodeTypes,
} from '@xyflow/react';
-import { useMemo } from 'react';
+import { useId, useMemo } from 'react';
import '@xyflow/react/dist/style.css';
import { useWorkbenchPreferences } from '../settings/store';
import type { GraphContract } from '../types';
+import { getResolvedWorkflowEdges } from '../workflows/connectors';
import { isInvocationNode, type ProjectGraphState, type XYPosition } from '../workflows/types';
import { flowThemeCss, getFlowColorMode } from './flowTheme';
@@ -35,27 +36,34 @@ type PreviewFlowNode = FlowNode<{ inputCount: number; nodeId: string; nodeType:
*/
export const documentToPreviewGraph = (
document: ProjectGraphState
-): { graph: GraphContract; positionHints: Record<string, XYPosition> } => ({
- graph: {
- edges: document.edges.map((edge) => ({
- id: edge.id,
- sourceField: edge.sourceHandle,
- sourceNodeId: edge.source,
- targetField: edge.targetHandle,
- targetNodeId: edge.target,
- })),
- id: document.id,
- label: document.name || 'Workflow',
- nodes: document.nodes.filter(isInvocationNode).map((node) => ({
- id: node.id,
- inputs: Object.fromEntries(Object.values(node.data.inputs).map((instance) => [instance.name, instance.value])),
- type: node.data.type,
- })),
- updatedAt: document.updatedAt,
- version: 1,
- },
- positionHints: Object.fromEntries(document.nodes.map((node) => [node.id, node.position])),
-});
+): { graph: GraphContract; positionHints: Record<string, XYPosition> } => {
+ const invocationNodes = document.nodes.filter(isInvocationNode);
+ const invocationNodeIds = new Set(invocationNodes.map((node) => node.id));
+
+ return {
+ graph: {
+ edges: getResolvedWorkflowEdges(document.nodes, document.edges)
+ .filter((edge) => invocationNodeIds.has(edge.source) && invocationNodeIds.has(edge.target))
+ .map((edge) => ({
+ id: edge.id,
+ sourceField: edge.sourceHandle,
+ sourceNodeId: edge.source,
+ targetField: edge.targetHandle,
+ targetNodeId: edge.target,
+ })),
+ id: document.id,
+ label: document.name || 'Workflow',
+ nodes: invocationNodes.map((node) => ({
+ id: node.id,
+ inputs: Object.fromEntries(Object.values(node.data.inputs).map((instance) => [instance.name, instance.value])),
+ type: node.data.type,
+ })),
+ updatedAt: document.updatedAt,
+ version: 1,
+ },
+ positionHints: Object.fromEntries(document.nodes.map((node) => [node.id, node.position])),
+ };
+};
const LAYER_WIDTH = 300;
const ROW_HEIGHT = 100;
@@ -160,6 +168,7 @@ export const GraphPreviewFlow = ({
positionHints?: Record<string, XYPosition>;
}) => {
const { themeId } = useWorkbenchPreferences();
+ const backgroundId = useId().replace(/:/g, '');
const nodes = useMemo(() => toPreviewNodes(graph, positionHints), [graph, positionHints]);
const edges = useMemo(() => toPreviewEdges(graph), [graph]);
@@ -181,7 +190,14 @@ export const GraphPreviewFlow = ({
proOptions={{ hideAttribution: true }}
style={{ background: 'transparent' }}
>
- <Background color="var(--wb-flow-grid)" gap={24} size={1.5} variant={BackgroundVariant.Dots} />
+ <Background
+ bgColor="var(--xy-background-color)"
+ color="var(--wb-flow-grid)"
+ gap={24}
+ id={`preview-grid-${backgroundId}`}
+ size={1.5}
+ variant={BackgroundVariant.Dots}
+ />
</ReactFlow>
</Box>
);
diff --git a/invokeai/frontend/webv2/src/workbench/components/flowTheme.ts b/invokeai/frontend/webv2/src/workbench/components/flowTheme.ts
index 2b846f253a..95a5644d1a 100644
--- a/invokeai/frontend/webv2/src/workbench/components/flowTheme.ts
+++ b/invokeai/frontend/webv2/src/workbench/components/flowTheme.ts
@@ -13,6 +13,7 @@ import type { WorkbenchThemeId } from '../types';
export const flowThemeCss: SystemStyleObject = {
'--wb-flow-grid': '{colors.fg.grid}',
'--xy-attribution-background-color': 'transparent',
+ '--xy-background-color': '{colors.bg.inset}',
'--xy-connectionline-stroke': '{colors.accent.solid}',
'--xy-edge-stroke': '{colors.border.emphasized}',
'--xy-edge-stroke-selected': '{colors.accent.solid}',
diff --git a/invokeai/frontend/webv2/src/workbench/components/ui/JsonPreview.tsx b/invokeai/frontend/webv2/src/workbench/components/ui/JsonPreview.tsx
index 47fbadb0a9..b4487da0e2 100644
--- a/invokeai/frontend/webv2/src/workbench/components/ui/JsonPreview.tsx
+++ b/invokeai/frontend/webv2/src/workbench/components/ui/JsonPreview.tsx
@@ -14,11 +14,13 @@ import { IconButton } from './Button';
* a flex parent and pass `maxH="100%"`) to control it.
*/
export const JsonPreview = ({
+ h,
label = 'JSON preview',
maxH = '24rem',
text,
value,
}: {
+ h?: string;
/** Accessible name for the scroll viewport. */
label?: string;
maxH?: string;
@@ -61,6 +63,7 @@ export const JsonPreview = ({
borderWidth="1px"
display="flex"
flexDirection="column"
+ h={h}
maxH={maxH}
maxW="full"
minH="0"
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/workflow/library/WorkflowLibraryDialog.tsx b/invokeai/frontend/webv2/src/workbench/widgets/workflow/library/WorkflowLibraryDialog.tsx
index 7ab6d100ec..16dfebcd35 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/workflow/library/WorkflowLibraryDialog.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/workflow/library/WorkflowLibraryDialog.tsx
@@ -296,15 +296,23 @@ export const WorkflowLibraryDialog = ({
/>
</HStack>
<Scrollable label="Workflow library results" maxH="20rem" minH="8rem">
- <Stack gap="1">
+ <Stack gap="1" minW="0" w="full">
{items.map((item) => (
- <HStack
+ <Box
key={item.workflow_id}
_hover={{ bg: 'bg.emphasized' }}
+ alignItems="center"
+ display="grid"
gap="2"
+ gridTemplateColumns={
+ category === 'user' ? 'minmax(0, 1fr) auto auto auto' : 'minmax(0, 1fr) auto auto'
+ }
+ minW="0"
+ overflow="hidden"
px="1"
rounded="md"
transition="background 0.12s ease"
+ w="full"
>
<Box
as="button"
@@ -364,7 +372,7 @@ export const WorkflowLibraryDialog = ({
Delete
</Button>
) : null}
- </HStack>
+ </Box>
))}
{!isLoading && items.length === 0 ? (
<Text color="fg.subtle" fontSize="2xs" px="2" py="4" textAlign="center">