4.0 KiB
4.0 KiB
Edge Waypoints & Label Dragging for Workflow Builder
Date: 2026-02-05
Summary
Added interactive edge waypoints and label dragging to the workflow builder, allowing users to manually route transition arrows through intermediate control points and reposition transition labels for better visual clarity in complex workflows.
Changes
Types (web/src/types/workflow.ts)
TaskTransition: Addededge_waypoints?: Record<string, NodePosition[]>andlabel_positions?: Record<string, NodePosition>fields, keyed by target task name, for per-edge routing dataWorkflowEdge: AddedtoName(stable target task name key),waypoints?: NodePosition[], andlabelPosition?: NodePositionfieldsTransitionChartMeta: Addededge_waypointsandlabel_positionsfor YAML serialization via__chart_meta__EdgeHoverInfo: AddedtargetTaskIdfield to uniquely identify clicked edgesderiveEdges(): Extracts per-edge waypoints and label positions from transition chart metabuilderStateToDefinition(): Serializes waypoints and label positions into__chart_meta__definitionToBuilderState(): Deserializes them on loadremoveTaskFromTransitions(): Cleans up waypoint/label entries when a target task is removedrenameTaskInTransitions(): Renames keys inedge_waypointsandlabel_positionswhen a task is renamed
Edge Rendering (web/src/components/workflows/WorkflowEdges.tsx)
SelectedEdgeInfointerface: Tracks which edge is selected for waypoint editingbuildSmoothPath(): New function that draws smooth multi-segment SVG paths through waypoints using Catmull-Rom → cubic Bezier conversioncomputeDefaultLabelPosition(): Computes a default label position from path points- Waypoint handles: Small colored circles at each waypoint, draggable when edge is selected; double-click to remove
- Midpoint add handles: "+" indicators appear on hover at segment midpoints of the selected edge; click to insert a new waypoint, or drag to insert and immediately reposition
- Label dragging: Transition labels are draggable when the edge is selected; double-click to reset to default position
- Edge selection glow: Selected edges render with a subtle glow effect and slightly thicker stroke
- Effect-based drag handling: Uses
useEffectwithisDraggingstate to manage document-level mouse listeners, with refs for latest callback values to avoid stale closures
Canvas Integration (web/src/components/workflows/WorkflowCanvas.tsx)
selectedEdgestate: Tracks which edge is selected for waypoint manipulationhandleEdgeClick(): Sets both edge selection and propagates to parent for task inspector highlightinghandleSelectTask(): Clears edge selection when a different task is clickedhandleWaypointUpdate(): Updates a task's transitionedge_waypointsfor a specific targethandleLabelPositionUpdate(): Updates a task's transitionlabel_positionsfor a specific target- All new props passed through to
WorkflowEdges
User Interaction
- Click an edge to select it — the edge highlights with a glow and shows waypoint handles
- Hover the midpoint of any segment on the selected edge to reveal a "+" indicator
- Click or drag the "+" to insert a new waypoint at that position
- Drag waypoint handles to reposition the edge path
- Drag the label to move it independently of the path
- Double-click a waypoint to remove it
- Double-click a label to reset it to default position
- Click canvas background or another task to deselect the edge
Data Persistence
Waypoints and label positions are stored in the workflow YAML via __chart_meta__ on transitions, keyed by target task name. This ensures:
- Data survives save/reload cycles
- Per-edge granularity (a transition with
do: [taskA, taskB]has independent waypoints for each target) - Task renames and deletions properly update the keys
- Backend ignores
__chart_meta__— it's purely visual metadata