🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
💄 style(acceptance): make the flow tab readable and stop it moving under the pointer (#19471)
Arvin Xudd6bf4fc9206
diff --git a/locales/en-US/verify.json b/locales/en-US/verify.jsonindex d13e4c6bb0e..f6777bd42ca 100644--- a/locales/en-US/verify.json+++ b/locales/en-US/verify.json@@ -573,7 +573,6 @@"flow.planned": "Plan published · verification has not started","flow.rerunVersion": "Rerun this version","flow.resultHistory": "{{count}} verification records",- "flow.results": "Verification results","flow.review.accepted": "Confirmed","flow.review.rejected": "Needs work","flow.reviewResult": "Review this result",@@ -590,8 +589,6 @@"flow.state.uncertain": "Uncertain","flow.title": "User flow","flow.unvisited": "This state has not been verified on this path.",- "flow.viewPlan": "View steps",- "flow.viewResults": "View results","list.failedCount": "{{count}} failed","list.running": "Verifying…","meta.description": "Verification runs, delivery reports, and acceptance reviews.",diff --git a/locales/zh-CN/verify.json b/locales/zh-CN/verify.jsonindex 5f799ae81a5..e9f9b0191e5 100644--- a/locales/zh-CN/verify.json+++ b/locales/zh-CN/verify.json@@ -573,7 +573,6 @@"flow.planned": "流程已发布 · 尚未开始验证","flow.rerunVersion": "复跑此版本","flow.resultHistory": "{{count}} 条验证记录",- "flow.results": "验证结果","flow.review.accepted": "确认通过","flow.review.rejected": "需要处理","flow.reviewResult": "复核此结果",@@ -590,8 +589,6 @@"flow.state.uncertain": "不确定","flow.title": "验收流程","flow.unvisited": "此路径下的状态尚未验证。",- "flow.viewPlan": "查看步骤",- "flow.viewResults": "查看结果","list.failedCount": "{{count}} 项未通过","list.running": "验证中…","meta.description": "验证运行、交付报告与验收评审。",diff --git a/packages/locales/src/default/verify.ts b/packages/locales/src/default/verify.tsindex 024165d0847..71612c639d9 100644--- a/packages/locales/src/default/verify.ts+++ b/packages/locales/src/default/verify.ts@@ -72,9 +72,6 @@ export default {'flow.diff.fields.condition': 'Condition','flow.diff.fields.required': 'Required',- 'flow.viewResults': 'View results',- 'flow.viewPlan': 'View steps',- 'flow.results': 'Verification results','flow.closeResults': 'Close results','flow.resultHistory': '{{count}} verification records','flow.latestResult': 'Latest result',diff --git a/src/features/Acceptance/Viewer/Comments/styles.ts b/src/features/Acceptance/Viewer/Comments/styles.tsindex 90f3b7f57b0..556f4e4bd69 100644--- a/src/features/Acceptance/Viewer/Comments/styles.ts+++ b/src/features/Acceptance/Viewer/Comments/styles.ts@@ -122,6 +122,11 @@ export const styles = createStaticStyles(({ css }) => ({* the dot, which read as a smudge rather than as a node on the line.*/eventDot: css`+ /* Same reason as the message box: the rail is the entry's absolutely+ positioned pseudo-element, so an unpositioned dot paints under it and the+ line cuts straight across the circle. */+ position: relative;+display: inline-flex;flex: none;align-items: center;diff --git a/src/features/Acceptance/Viewer/Flow/AcceptanceFlow.tsx b/src/features/Acceptance/Viewer/Flow/AcceptanceFlow.tsxindex a1d6ebf00dc..749b85fae03 100644--- a/src/features/Acceptance/Viewer/Flow/AcceptanceFlow.tsx+++ b/src/features/Acceptance/Viewer/Flow/AcceptanceFlow.tsx@@ -25,19 +25,30 @@ import { FlowPanelHostContext } from './FlowPanelHost';import { FlowResults } from './FlowResults';const styles = createStaticStyles(({ css }) => ({+ // Fullscreen is a two-column shell, the same shape the page uses: the details+ // rail owns the full height of the right edge and the toolbar belongs to the+ // canvas beside it, not to a band stretched across both.fullscreen: css`position: fixed;z-index: ${cssVar.zIndexPopupBase};inset: 0;+ background: ${cssVar.colorBgContainer};+ @media (width <= 640px) {+ flex-direction: column;+ }+ `,+ stage: css`+ min-width: 0;+ min-height: 0;padding: 16px;-- background: ${cssVar.colorBgContainer};`,details: css`- overflow: auto;+ overflow: hidden;flex: none;- width: min(400px, 45vw);++ width: min(440px, 42%);+ height: 100%;min-height: 0;@media (width <= 640px) {@@ -129,7 +140,6 @@ export function AcceptanceFlow() {});},setFocus,- setSelected,focus,);if (!views.length) return <Empty description={t('flow.empty')} />;@@ -177,8 +187,12 @@ export function AcceptanceFlow() {onSaved={mutate}/>) : null;- const content = (- <Flexbox className={fullscreen ? styles.fullscreen : undefined} gap={16}>+ const stage = (+ <Flexbox+ className={fullscreen ? styles.stage : undefined}+ flex={fullscreen ? 1 : undefined}+ gap={16}+ ><Flexboxhorizontalalign="center"@@ -252,14 +266,16 @@ export function AcceptanceFlow() {/></ReactFlowProvider>)}- {results &&- (fullscreen ? (- <Flexbox className={styles.details}>{results}</Flexbox>- ) : (- panelHost && createPortal(results, panelHost)- ))}+ {!fullscreen && results && panelHost && createPortal(results, panelHost)}</Flexbox></Flexbox>);- return fullscreen ? createPortal(content, appElement ?? document.body) : content;+ if (!fullscreen) return stage;+ return createPortal(+ <Flexbox horizontal className={styles.fullscreen}>+ {stage}+ {results && <Flexbox className={styles.details}>{results}</Flexbox>}+ </Flexbox>,+ appElement ?? document.body,+ );}diff --git a/src/features/Acceptance/Viewer/Flow/FlowCanvas.tsx b/src/features/Acceptance/Viewer/Flow/FlowCanvas.tsxindex 895003ed4ea..0833115b6b8 100644--- a/src/features/Acceptance/Viewer/Flow/FlowCanvas.tsx+++ b/src/features/Acceptance/Viewer/Flow/FlowCanvas.tsx@@ -15,9 +15,10 @@ import { useEffect, useRef } from 'react';import { observeWidth } from '@/features/AgentGoals/ProcessControl/Graph/useFitViewOnResize';import { useSingleton } from '@/hooks/useSingleton';+import { FlowAnchorContext } from './flowAnchor';import { FlowEdge } from './FlowEdge';import type { FlowGraphData } from './flowGraph';-import { getSelectedFlowNodeId, revealSelectionAfterResize } from './flowViewport';+import { getSelectedFlowNodeId, panNodeIntoView } from './flowViewport';const edgeTypes = { transition: FlowEdge };@@ -63,6 +64,20 @@ export function FlowCanvas({}) {const ref = useRef<HTMLDivElement>(null);const { fitView, getNodesBounds, getViewport, setViewport } = useReactFlow();+ const anchor = useSingleton(() => ({ current: null as string | null }));+ // The toggled group has just changed height, so follow it rather than leaving+ // the user staring at whatever slid into its place.+ useEffect(() => {+ const toggled = anchor.current;+ anchor.current = null;+ const container = ref.current;+ if (!toggled || !container) return;+ panNodeIntoView(+ { getNodesBounds, getViewport, setViewport },+ { height: container.clientHeight, width: container.clientWidth },+ toggled,+ );+ }, [nodes, anchor, getNodesBounds, getViewport, setViewport]);const viewports = useSingleton(() => new Map<string, { viewport: Viewport; width: number; height: number }>(),);@@ -78,13 +93,13 @@ export function FlowCanvas({const container = ref.current;if (!container || typeof ResizeObserver === 'undefined') return;return observeWidth(container, () =>- revealSelectionAfterResize(- { fitView, getNodesBounds, getViewport },+ panNodeIntoView(+ { getNodesBounds, getViewport, setViewport },{ height: container.clientHeight, width: container.clientWidth },selectedRef.current,),);- }, [fitView, getNodesBounds, getViewport]);+ }, [getNodesBounds, getViewport, setViewport]);useEffect(() => {const container = ref.current;const frame = requestAnimationFrame(() => {@@ -107,37 +122,45 @@ export function FlowCanvas({};}, [viewKey, fullscreen, fitView, getViewport, setViewport, viewports]);return (- <Flexbox- className={styles.canvas}- ref={ref}- style={fullscreen ? { flex: 1, height: '100%', minHeight: 0 } : undefined}- >- <ReactFlow- fitView- panOnDrag- panOnScroll- preventScrolling- zoomOnDoubleClick- zoomOnPinch- colorMode="system"- edgeTypes={edgeTypes}- edges={edges}- fitViewOptions={fitOptions}- maxZoom={1.5}- minZoom={0.08}- nodeTypes={nodeTypes}- nodes={nodes}- nodesConnectable={false}- nodesDraggable={false}- proOptions={{ hideAttribution: true }}- style={{ background: 'transparent' }}- zoomOnScroll={false}- onEdgeClick={(_, e) => onSelect(e.id)}- onNodeClick={(_, n) => onSelect(n.id)}+ // Custom nodes render inside React Flow, not under its `children`, so the+ // anchor channel has to sit above the canvas to reach a group's toggle.+ <FlowAnchorContext value={anchor}>+ <Flexbox+ className={styles.canvas}+ ref={ref}+ style={fullscreen ? { flex: 1, height: '100%', minHeight: 0 } : undefined}>- <Background bgColor="transparent" color={cssVar.colorBorderSecondary} gap={18} size={1} />- <Controls position="bottom-right" showInteractive={false} />- </ReactFlow>- </Flexbox>+ <ReactFlow+ fitView+ panOnDrag+ panOnScroll+ preventScrolling+ zoomOnDoubleClick+ zoomOnPinch+ colorMode="system"+ edgeTypes={edgeTypes}+ edges={edges}+ fitViewOptions={fitOptions}+ maxZoom={1.5}+ minZoom={0.08}+ nodeTypes={nodeTypes}+ nodes={nodes}+ nodesConnectable={false}+ nodesDraggable={false}+ proOptions={{ hideAttribution: true }}+ style={{ background: 'transparent' }}+ zoomOnScroll={false}+ // No onEdgeClick: the edge runs behind its own caption, so clicking+ // the caption selected the branch, opened the panel and shifted the+ // canvas out from under the pointer. Branches stay pickable in the+ // outline view; on the canvas the state card is the way in.+ onNodeClick={(_, n) => onSelect(n.id)}+ onPaneClick={() => onSelect('')}+ >+ <Background bgColor="transparent" color={cssVar.colorBorderSecondary} gap={18} size={1} />+ <Controls position="bottom-right" showInteractive={false} />+ </ReactFlow>+ </Flexbox>+ </FlowAnchorContext>);}diff --git a/src/features/Acceptance/Viewer/Flow/FlowEdge.tsx b/src/features/Acceptance/Viewer/Flow/FlowEdge.tsxindex 3ba62a0d26d..51bb410612e 100644--- a/src/features/Acceptance/Viewer/Flow/FlowEdge.tsx+++ b/src/features/Acceptance/Viewer/Flow/FlowEdge.tsx@@ -1,28 +1,29 @@-import { Button } from '@lobehub/ui/base-ui';import type { Edge, EdgeProps } from '@xyflow/react';import { BaseEdge, EdgeLabelRenderer, getSmoothStepPath } from '@xyflow/react';-import { createStaticStyles, cssVar, cx } from 'antd-style';+import { createStaticStyles, cssVar } from 'antd-style';import { getFlowEdgeLabelLayout } from './flowEdgeLabel';const styles = createStaticStyles(({ css }) => ({+ // The caption reads the branch condition out; it is not a control. Clicking it+ // used to open the details panel, which narrows the canvas and shifts the page+ // column, so the caption moved out from under the pointer as if it had gone.+ // Clicks fall through to the canvas instead; the state card is the way in.label: css`- pointer-events: all;+ pointer-events: none;position: absolute;overflow: hidden;display: -webkit-box;-webkit-box-orient: vertical;- -webkit-line-clamp: 2;+ -webkit-line-clamp: 5;- max-width: 180px;- height: auto;- min-height: 0;- max-height: 42px;- padding-block: 3px;- padding-inline: 2px;- border-radius: 4px;+ max-width: 200px;+ max-height: 94px;+ padding-block: 5px;+ padding-inline: 10px;+ border-radius: 8px;font-size: 12px;line-height: 18px;@@ -30,11 +31,15 @@ const styles = createStaticStyles(({ css }) => ({overflow-wrap: anywhere;white-space: normal;- background: ${cssVar.colorBgContainer};+ /* Filled, and opaque in both themes: the fill token is translucent, so it+ is layered over a solid surface rather than over the edge running+ underneath, which would otherwise strike the text through. */+ background-color: ${cssVar.colorBgContainer};+ background-image: linear-gradient(${cssVar.colorFillQuaternary}, ${cssVar.colorFillQuaternary});`,}));-type TransitionEdge = Edge<{ onSelect: (id: string) => void; laneOffset?: number }>;+type TransitionEdge = Edge<{ laneOffset?: number }>;/** Labels share the graph scale so zooming out preserves their spacing. */export function FlowEdge(props: EdgeProps<TransitionEdge>) {@@ -51,19 +56,15 @@ export function FlowEdge(props: EdgeProps<TransitionEdge>) {<><BaseEdge id={props.id} markerEnd={props.markerEnd} path={path} style={props.style} /><EdgeLabelRenderer>- <Button- className={cx(styles.label, 'nodrag', 'nopan')}- size="small"- title={typeof props.label === 'string' ? props.label : undefined}- type="text"+ <div+ className={styles.label}style={{maxWidth: label.maxWidth,transform: `translate(-50%, -50%) translate(${label.x}px, ${label.y}px)`,}}- onClick={() => props.data?.onSelect(props.id)}>{props.label}- </Button>+ </div></EdgeLabelRenderer></>);diff --git a/src/features/Acceptance/Viewer/Flow/FlowGroup.tsx b/src/features/Acceptance/Viewer/Flow/FlowGroup.tsxindex 7f830b8d598..4d54edf36d5 100644--- a/src/features/Acceptance/Viewer/Flow/FlowGroup.tsx+++ b/src/features/Acceptance/Viewer/Flow/FlowGroup.tsx@@ -1,6 +1,6 @@import { Flexbox, Icon } from '@lobehub/ui';import { Button, Text } from '@lobehub/ui/base-ui';-import { Handle, Position } from '@xyflow/react';+import { Handle, Position, useNodeId } from '@xyflow/react';import { createStaticStyles, cssVar } from 'antd-style';import {CheckCircle2,@@ -13,8 +13,10 @@ import {CircleX,Maximize2,} from 'lucide-react';+import { use } from 'react';import { useTranslation } from 'react-i18next';+import { FlowAnchorContext } from './flowAnchor';import type { FlowGraphData } from './flowGraph';import { flowStateBackground, flowStateColor } from './FlowNode';@@ -35,6 +37,7 @@ const styles = createStaticStyles(({ css }) => ({background: transparent;`,collapsed: css`+ cursor: pointer;height: 100%;padding-block: 12px;padding-inline: 12px;@@ -77,6 +80,14 @@ const styles = createStaticStyles(({ css }) => ({export function FlowGroup({ data }: { data: FlowGraphData }) {const { t } = useTranslation('verify');+ const anchor = use(FlowAnchorContext);+ const nodeId = useNodeId();+ // Name this group as the one to follow once the new layout lands.+ const toggle = (event: { stopPropagation: () => void }) => {+ event.stopPropagation();+ anchor.current = nodeId;+ data.onToggle?.();+ };const statusIcon =data.state === 'passed'? CheckCircle2@@ -94,7 +105,14 @@ export function FlowGroup({ data }: { data: FlowGraphData }) {<Handle className={styles.handle} id="in" position={Position.Left} type="target" /><div className={styles.group}>{data.collapsed ? (- <Flexbox horizontal align="flex-start" className={styles.collapsed} gap={10}>+ <Flexbox+ horizontal+ align="flex-start"+ className={styles.collapsed}+ gap={10}+ role="button"+ onClick={toggle}+ ><divaria-label={t(`flow.state.${data.state ?? 'pending'}`)}className={styles.glyph}@@ -121,10 +139,7 @@ export function FlowGroup({ data }: { data: FlowGraphData }) {className="nodrag nopan"size="small"type="text"- onClick={(e) => {- e.stopPropagation();- data.onToggle?.();- }}+ onClick={toggle}><Icon icon={ChevronRight} size={16} /></Button>@@ -153,10 +168,7 @@ export function FlowGroup({ data }: { data: FlowGraphData }) {className="nodrag nopan"size="small"type="text"- onClick={(e) => {- e.stopPropagation();- data.onToggle?.();- }}+ onClick={toggle}><Icon icon={ChevronDown} size={16} /></Button>diff --git a/src/features/Acceptance/Viewer/Flow/FlowNode.tsx b/src/features/Acceptance/Viewer/Flow/FlowNode.tsxindex c4ea3045798..416ba5af6d8 100644--- a/src/features/Acceptance/Viewer/Flow/FlowNode.tsx+++ b/src/features/Acceptance/Viewer/Flow/FlowNode.tsx@@ -10,7 +10,6 @@ import {CircleHelp,CirclePause,CircleX,- FileCheck2,Paperclip,Repeat2,} from 'lucide-react';@@ -171,10 +170,6 @@ export function FlowNode({ data }: { data: FlowNodeData }) {<Icon icon={Paperclip} size={12} />{data.evidence}</Flexbox>- <Flexbox horizontal align="center" gap={4} style={{ marginInlineStart: 'auto' }}>- <Icon icon={FileCheck2} size={12} />- {t(data.attempts ? 'flow.viewResults' : 'flow.viewPlan')}- </Flexbox></Flexbox></div><Handle className={styles.handle} id="out" position={Position.Right} type="source" />diff --git a/src/features/Acceptance/Viewer/Flow/FlowOutline.tsx b/src/features/Acceptance/Viewer/Flow/FlowOutline.tsxindex 60c44ebce3d..ee159d5021c 100644--- a/src/features/Acceptance/Viewer/Flow/FlowOutline.tsx+++ b/src/features/Acceptance/Viewer/Flow/FlowOutline.tsx@@ -31,19 +31,32 @@ const styles = createStaticStyles(({ css }) => ({text-align: start;white-space: normal;`,+ // A branch is the condition for reaching the next step, not a step of its own.+ // Row-width and body-size type made it read as one more item in the list, so+ // it shrinks to caption scale and hugs its own text.branch: css`justify-content: flex-start;- width: 100%;+ width: fit-content;+ max-width: 100%;height: auto;- min-height: 32px;- padding-block: 4px;+ min-height: 24px;++ /* Same inline padding as a step row, so the branch glyph sits on the same+ axis as the status glyphs above and below it. */+ padding-block: 2px;padding-inline: 12px;- color: ${cssVar.colorTextSecondary};+ font-size: 12px;+ line-height: 18px;text-align: start;white-space: normal;`,+ // The button carries its own colour rule, so the caption tone has to sit on+ // the content it wraps.+ branchContent: css`+ color: ${cssVar.colorTextTertiary};+ `,nested: css`margin-inline-start: 18px;padding-inline-start: 8px;@@ -117,11 +130,13 @@ export function FlowOutline({type="text"onClick={() => onSelect(branch.edge.id)}>- <Flexbox horizontal align="center" gap={8}>+ {/* Top-aligned: a caption that wraps keeps its glyph on the first line and+ its later lines under the text, not under the glyph. */}+ <Flexbox horizontal align="flex-start" className={styles.branchContent} gap={6}><Iconicon={reference ? ArrowRight : CornerDownRight}- size={14}- style={{ flex: 'none' }}+ size={12}+ style={{ flex: 'none', marginBlockStart: 3 }}/><span>{reference ? `${label} → ${branch.target.data.title}` : label}</span></Flexbox>diff --git a/src/features/Acceptance/Viewer/Flow/FlowResults.tsx b/src/features/Acceptance/Viewer/Flow/FlowResults.tsxindex 7d73313a800..2f0d1028bed 100644--- a/src/features/Acceptance/Viewer/Flow/FlowResults.tsx+++ b/src/features/Acceptance/Viewer/Flow/FlowResults.tsx@@ -202,23 +202,18 @@ export function FlowResults({return (<Flexbox className={styles.panel}><Flexbox horizontal align="center" className={styles.header} gap={12} justify="space-between">- <Flexbox gap={4}>- <Text fontSize={12} type="secondary">- {t(attempt ? 'flow.results' : 'flow.viewPlan')}+ <Flexbox horizontal align="center" gap={10} wrap="wrap">+ <Text strong fontSize={16}>+ {node.title}</Text>- <Flexbox horizontal align="center" gap={10} wrap="wrap">- <Text strong fontSize={16}>- {node.title}- </Text>- {attempt && (- <Flexbox horizontal align="center" gap={4} style={{ flex: 'none' }}>- <Icon color={flowStateColor(attempt.verdict)} icon={ClipboardCheck} size={14} />- <Text fontSize={12} style={{ color: flowStateColor(attempt.verdict) }}>- {t(`flow.state.${attempt.verdict}`)}- </Text>- </Flexbox>- )}- </Flexbox>+ {attempt && (+ <Flexbox horizontal align="center" gap={4} style={{ flex: 'none' }}>+ <Icon color={flowStateColor(attempt.verdict)} icon={ClipboardCheck} size={14} />+ <Text fontSize={12} style={{ color: flowStateColor(attempt.verdict) }}>+ {t(`flow.state.${attempt.verdict}`)}+ </Text>+ </Flexbox>+ )}</Flexbox><ActionIconaria-label={t('flow.closeResults')}diff --git a/src/features/Acceptance/Viewer/Flow/flowAnchor.ts b/src/features/Acceptance/Viewer/Flow/flowAnchor.tsnew file mode 100644index 00000000000..b2ce47fd377--- /dev/null+++ b/src/features/Acceptance/Viewer/Flow/flowAnchor.ts@@ -0,0 +1,8 @@+import { createContext } from 'react';++/**+ * Collapsing or expanding a group re-lays out the whole stack around it. The id+ * of the group the user just toggled is handed to the canvas here, so it can+ * bring that group back into view once the new layout lands.+ */+export const FlowAnchorContext = createContext<{ current: string | null }>({ current: null });diff --git a/src/features/Acceptance/Viewer/Flow/flowEdgeLabel.test.ts b/src/features/Acceptance/Viewer/Flow/flowEdgeLabel.test.tsindex 96e5a3c488e..125be035964 100644--- a/src/features/Acceptance/Viewer/Flow/flowEdgeLabel.test.ts+++ b/src/features/Acceptance/Viewer/Flow/flowEdgeLabel.test.ts@@ -22,6 +22,13 @@ describe('forward branch labels', () => {expect(label.x + label.maxWidth / 2).toBeLessThan(branch.targetX);});+ it('spends the gutter on the caption but keeps it clear of the cards beside it', () => {+ expect(getFlowEdgeLabelLayout({ ...branch, targetX: 508 }).maxWidth).toBe(200);+ const tight = getFlowEdgeLabelLayout({ ...branch, targetX: 468 });+ expect(tight.maxWidth).toBe(160);+ expect(tight.x - tight.maxWidth / 2 - branch.sourceX).toBe(24);+ });+it('separates captions for branches with different destinations', () => {const first = getFlowEdgeLabelLayout(branch);const second = getFlowEdgeLabelLayout({ ...branch, targetY: 420 });@@ -36,7 +43,7 @@ describe('forward branch labels', () => {expect(getFlowEdgeLabelLayout({ ...branch, ...overrides })).toEqual({x: branch.labelX,y: branch.labelY,- maxWidth: 180,+ maxWidth: 200,});});});diff --git a/src/features/Acceptance/Viewer/Flow/flowEdgeLabel.ts b/src/features/Acceptance/Viewer/Flow/flowEdgeLabel.tsindex efee9f0bbce..e6c112e50d7 100644--- a/src/features/Acceptance/Viewer/Flow/flowEdgeLabel.ts+++ b/src/features/Acceptance/Viewer/Flow/flowEdgeLabel.ts@@ -1,5 +1,10 @@import { Position } from '@xyflow/react';+/** The caption is the only place the branch condition is readable, so it claims the gutter. */+const MAX_LABEL_WIDTH = 200;+/** Clear space kept between the caption and the card on each side of the gutter. */+const SIDE_CLEARANCE = 48;+/** Keep ordinary forward-branch captions in the gutter beside their destination. */export function getFlowEdgeLabelLayout({sourceX,@@ -25,7 +30,7 @@ export function getFlowEdgeLabelLayout({return {x: (sourceX + targetX) / 2,y: targetY,- maxWidth: Math.min(180, gap - 16),+ maxWidth: Math.min(MAX_LABEL_WIDTH, gap - SIDE_CLEARANCE),};- return { x: labelX, y: labelY, maxWidth: 180 };+ return { x: labelX, y: labelY, maxWidth: MAX_LABEL_WIDTH };}diff --git a/src/features/Acceptance/Viewer/Flow/flowGraph.test.ts b/src/features/Acceptance/Viewer/Flow/flowGraph.test.tsindex 7d4884094d6..487a5f1a212 100644--- a/src/features/Acceptance/Viewer/Flow/flowGraph.test.ts+++ b/src/features/Acceptance/Viewer/Flow/flowGraph.test.ts@@ -69,7 +69,6 @@ const build = (views: FlowGraphView[], collapsed = new Set<string>(), focus?: stundefined,() => {},() => {},- () => {},focus,);@@ -110,6 +109,23 @@ describe('grouped acceptance canvas', () => {expect(build([flow]).nodes.every((node) => Number.isFinite(node.position.x))).toBe(true);});+ it('drops the group box around a business flow that holds a single state', () => {+ const solo = view('solo');+ solo.version.nodes = [solo.version.nodes[0]];+ solo.version.edges = [];+ const graph = build([solo, view('send')]);+ expect(graph.nodes.filter((node) => node.type === 'flowGroup').map((node) => node.id)).toEqual([+ 'send',+ ]);+ const [bare] = graph.nodes;+ expect(bare).toMatchObject({ id: 'solo/a', parentId: undefined, type: 'state' });+ expect(bare.position).toEqual({ x: 0, y: 0 });+ expect(graph.checks.has('solo/a')).toBe(true);+ expect(graph.nodes.find((node) => node.id === 'send')!.position.y).toBeGreaterThan(+ bare.position.y + bare.height!,+ );+ });+it('collapses groups without losing their definitions and drills into one group', () => {const views = [view('send'), view('switch')];const collapsed = build(views, new Set(['send']));diff --git a/src/features/Acceptance/Viewer/Flow/flowGraph.ts b/src/features/Acceptance/Viewer/Flow/flowGraph.tsindex 2f4306859b5..e02b7eef97d 100644--- a/src/features/Acceptance/Viewer/Flow/flowGraph.ts+++ b/src/features/Acceptance/Viewer/Flow/flowGraph.ts@@ -21,13 +21,22 @@ export interface FlowGraphView {version: FlowVersion;}+/**+ * The gutter between two columns. A branch caption sits in the middle of it, so+ * it has to fit prose AND leave the caption clear of the cards on either side.+ */+const COLUMN_GAP = 248;+const ROW_GAP = 64;+/** A business flow with a single state is its own header — a group box around it says nothing. */+const isSoloState = (view: FlowGraphView) =>+ view.version.nodes.length === 1 && !view.version.nodes[0].subFlowId;+export function buildFlowGraph(views: FlowGraphView[],collapsed: Set<string>,selected: string | undefined,onToggle: (id: string) => void,onEnter: (id: string) => void,- onSelect: (id: string) => void,focus?: string,) {const nodes: Node<FlowGraphData>[] = [];@@ -142,7 +151,7 @@ export function buildFlowGraph(let x = 24;for (const depth of [...columnWidths.keys()].sort((a, b) => a - b)) {columnX.set(depth, x);- x += columnWidths.get(depth)! + 112;+ x += columnWidths.get(depth)! + COLUMN_GAP;}const columnY = new Map<number, number>();const resultNodes: Node<FlowGraphData>[] = [];@@ -151,7 +160,7 @@ export function buildFlowGraph(const { node, id } = part;const depth = depths.get(node.id) ?? 0;const y = columnY.get(depth) ?? 64;- columnY.set(depth, y + part.height + 64);+ columnY.set(depth, y + part.height + ROW_GAP);bottom = Math.max(bottom, y + part.height);const visits = (view.run?.attempts ?? []).filter((v) => v.nodeId === node.id);const data: FlowGraphData = node.subFlowId@@ -206,14 +215,14 @@ export function buildFlowGraph(label: edge.trigger,sourceHandle: stacked ? 'stack-out' : returning ? 'return-out' : 'out',targetHandle: stacked ? 'stack-in' : returning ? 'return-in' : 'in',- data: { onSelect, laneOffset: (peers.indexOf(edge) - (peers.length - 1) / 2) * 64 },+ data: { laneOffset: (peers.indexOf(edge) - (peers.length - 1) / 2) * 64 },};});for (const part of parts) if (part.child) resultEdges.push(...part.child.edges);return {nodes: resultNodes,edges: resultEdges,- width: Math.max(360, x - 112 + 24),+ width: Math.max(360, x - COLUMN_GAP + 24),height: bottom + 56,};}@@ -234,6 +243,12 @@ export function buildFlowGraph(edges.push(...focused.edges);continue;}+ if (isSoloState(view)) {+ const [solo] = layout(view, undefined, id).nodes;+ nodes.push({ ...solo, parentId: undefined, position: { x: 0, y: top } });+ top += solo.height! + 48;+ continue;+ }const child = collapsed.has(id) ? undefined : layout(view, undefined, id);const leafNodes = view.version.nodes.filter((node) => !node.subFlowId);const summary = aggregate(diff --git a/src/features/Acceptance/Viewer/Flow/flowViewport.test.ts b/src/features/Acceptance/Viewer/Flow/flowViewport.test.tsindex ea731c07b33..2aa8d6c3dc8 100644--- a/src/features/Acceptance/Viewer/Flow/flowViewport.test.ts+++ b/src/features/Acceptance/Viewer/Flow/flowViewport.test.ts@@ -1,57 +1,81 @@import { describe, expect, it, vi } from 'vitest';-import { getSelectedFlowNodeId, isRectInView, revealSelectionAfterResize } from './flowViewport';+import { getSelectedFlowNodeId, isRectVisible, panNodeIntoView } from './flowViewport';const size = { height: 600, width: 1000 };-describe('isRectInView', () => {+describe('isRectVisible', () => {it('accepts a rect inside the canvas at the current zoom', () => {expect(- isRectInView({ height: 100, width: 200, x: 100, y: 50 }, { x: 0, y: 0, zoom: 1 }, size),+ isRectVisible({ height: 100, width: 200, x: 100, y: 50 }, { x: 0, y: 0, zoom: 1 }, size),).toBe(true);});- it('rejects a rect crossing the right edge after zooming in', () => {+ it('accepts a rect the canvas edge merely clips', () => {expect(- isRectInView({ height: 100, width: 200, x: 500, y: 50 }, { x: -100, y: 0, zoom: 2 }, size),+ isRectVisible({ height: 100, width: 200, x: 900, y: 50 }, { x: 0, y: 0, zoom: 1 }, size),+ ).toBe(true);+ });++ it('rejects a rect pushed past the edge entirely', () => {+ expect(+ isRectVisible({ height: 100, width: 200, x: 1100, y: 50 }, { x: 0, y: 0, zoom: 1 }, size),+ ).toBe(false);+ expect(+ isRectVisible({ height: 100, width: 200, x: 500, y: 50 }, { x: -800, y: 0, zoom: 1 }, size),).toBe(false);});});-describe('revealSelectionAfterResize', () => {+describe('panNodeIntoView', () => {const flow = (- viewport = { x: 0, y: 0, zoom: 1.4 },- bounds = { height: 80, width: 200, x: 100, y: 100 },+ viewport = { x: 0, y: 0, zoom: 1 },+ bounds = { height: 100, width: 200, x: 100, y: 50 },) => ({- fitView: vi.fn().mockResolvedValue(true),getNodesBounds: vi.fn().mockReturnValue(bounds),getViewport: vi.fn().mockReturnValue(viewport),+ setViewport: vi.fn(),+ });++ it('does nothing without a node, without a layout, or when it is fully visible', () => {+ const idle = flow();+ panNodeIntoView(idle, size, undefined);+ panNodeIntoView(idle, size, 'node-1');+ const unlaid = flow({ x: 0, y: 0, zoom: 1 }, { height: 0, width: 0, x: 0, y: 0 });+ panNodeIntoView(unlaid, size, 'node-1');+ expect(idle.setViewport).not.toHaveBeenCalled();+ expect(unlaid.setViewport).not.toHaveBeenCalled();+ });++ it('holds the canvas still for a node the narrower panel only clipped', () => {+ const api = flow({ x: 0, y: 0, zoom: 1 }, { height: 100, width: 200, x: 900, y: 50 });+ panNodeIntoView(api, size, 'node-1');+ expect(api.setViewport).not.toHaveBeenCalled();});- it('keeps the zoomed viewport untouched when nothing is selected', () => {- const api = flow();- revealSelectionAfterResize(api, size, undefined);- expect(api.fitView).not.toHaveBeenCalled();+ it('rescues a node pushed off screen entirely, by the least distance', () => {+ // 1100..1300 against a 1000 canvas: 324px back, not a centring jump.+ const api = flow({ x: 0, y: 0, zoom: 1 }, { height: 100, width: 200, x: 1100, y: 50 });+ panNodeIntoView(api, size, 'node-1');+ expect(api.setViewport).toHaveBeenCalledWith({ x: -324, y: 0, zoom: 1 });});- it('keeps the zoomed viewport untouched when the selected node is still visible', () => {- const api = flow();- revealSelectionAfterResize(api, size, 'node-1');- expect(api.fitView).not.toHaveBeenCalled();+ it('leaves the axis that still fits completely alone', () => {+ const api = flow({ x: 0, y: 0, zoom: 1 }, { height: 100, width: 200, x: -300, y: 200 });+ panNodeIntoView(api, size, 'node-1');+ expect(api.setViewport).toHaveBeenCalledWith({ x: 324, y: 0, zoom: 1 });});- it('pans at the same zoom when the panel pushes the selected node out of view', () => {- const api = flow({ x: 0, y: 0, zoom: 1.4 }, { height: 80, width: 200, x: 620, y: 100 });- revealSelectionAfterResize(api, size, 'node-1');- expect(api.fitView).toHaveBeenCalledWith(- expect.objectContaining({ maxZoom: 1.4, minZoom: 1.4, nodes: [{ id: 'node-1' }] }),- );+ it('aligns the leading edge of a node too tall to fit', () => {+ const api = flow({ x: 0, y: 0, zoom: 1 }, { height: 900, width: 200, x: 100, y: 700 });+ panNodeIntoView(api, size, 'node-1');+ expect(api.setViewport).toHaveBeenCalledWith({ x: 0, y: -676, zoom: 1 });});- it('ignores a selection whose node is not laid out yet', () => {- const api = flow(undefined, { height: 0, width: 0, x: 0, y: 0 });- revealSelectionAfterResize(api, size, 'node-1');- expect(api.fitView).not.toHaveBeenCalled();+ it('scales the shift with the zoom', () => {+ const api = flow({ x: 0, y: 0, zoom: 0.5 }, { height: 100, width: 200, x: 2200, y: 50 });+ panNodeIntoView(api, size, 'node-1');+ expect(api.setViewport).toHaveBeenCalledWith({ x: -224, y: 0, zoom: 0.5 });});});diff --git a/src/features/Acceptance/Viewer/Flow/flowViewport.ts b/src/features/Acceptance/Viewer/Flow/flowViewport.tsindex e3276dba8ba..c42cc31d294 100644--- a/src/features/Acceptance/Viewer/Flow/flowViewport.ts+++ b/src/features/Acceptance/Viewer/Flow/flowViewport.ts@@ -1,19 +1,22 @@-import type { FitViewOptions, Rect, Viewport } from '@xyflow/react';+import type { Rect, Viewport } from '@xyflow/react';++/** Breathing room between a revealed node and the canvas edge. */+const INSET = 24;export interface CanvasSize {height: number;width: number;}-/** Whether a flow-space rect sits fully inside the visible canvas. */-export const isRectInView = (rect: Rect, viewport: Viewport, size: CanvasSize) => {+/** Whether any part of a flow-space rect is on screen. */+export const isRectVisible = (rect: Rect, viewport: Viewport, size: CanvasSize) => {const left = rect.x * viewport.zoom + viewport.x;const top = rect.y * viewport.zoom + viewport.y;return (- left >= 0 &&- top >= 0 &&- left + rect.width * viewport.zoom <= size.width &&- top + rect.height * viewport.zoom <= size.height+ left < size.width &&+ top < size.height &&+ left + rect.width * viewport.zoom > 0 &&+ top + rect.height * viewport.zoom > 0);};@@ -25,30 +28,46 @@ export const getSelectedFlowNodeId = (nodes: { data: Record<string, unknown>; idnodes.find((node) => Boolean(node.data.selected))?.id;export interface FlowViewportApi {- fitView: (options?: FitViewOptions) => Promise<boolean>;getNodesBounds: (nodes: string[]) => Rect;getViewport: () => Viewport;+ setViewport: (viewport: Viewport) => unknown;}/**- * A side panel opening or closing changes the canvas width around the graph.- * Keep the user's zoom and position untouched; only pan, at the same zoom,- * when the selected node would otherwise be pushed out of view.+ * The least shift that brings a span inside the visible extent. A span longer+ * than the extent cannot fit, so its leading edge wins: reading starts there.*/-export const revealSelectionAfterResize = (+const axisShift = (start: number, length: number, extent: number) => {+ if (length >= extent - INSET * 2 || start < INSET) return INSET - start;+ const overflow = start + length - (extent - INSET);+ return overflow > 0 ? -overflow : 0;+};++/**+ * Rescue a node that the narrower canvas pushed off screen entirely, by panning+ * the least possible distance and never by zooming.+ *+ * A node the user can still see, even partly, is left exactly where it is. The+ * canvas moving under a click is far more disorienting than a clipped card:+ * whatever was clicked ends up somewhere else, which reads as it vanishing. The+ * details panel spells the node out anyway, so a clipped edge costs nothing.+ */+export const panNodeIntoView = (flow: FlowViewportApi,size: CanvasSize,- selectedId: string | undefined,+ id: string | undefined,) => {- if (!selectedId) return;- const viewport = flow.getViewport();- const bounds = flow.getNodesBounds([selectedId]);+ if (!id) return;+ const bounds = flow.getNodesBounds([id]);if (!bounds.width || !bounds.height) return;- if (isRectInView(bounds, viewport, size)) return;- void flow.fitView({- duration: 200,- maxZoom: viewport.zoom,- minZoom: viewport.zoom,- nodes: [{ id: selectedId }],- });+ const viewport = flow.getViewport();+ if (isRectVisible(bounds, viewport, size)) return;+ const x =+ viewport.x ++ axisShift(bounds.x * viewport.zoom + viewport.x, bounds.width * viewport.zoom, size.width);+ const y =+ viewport.y ++ axisShift(bounds.y * viewport.zoom + viewport.y, bounds.height * viewport.zoom, size.height);+ if (x === viewport.x && y === viewport.y) return;+ flow.setViewport({ ...viewport, x, y });};