Files
pipelines/app/lib/features/graph/widgets/run_graph_parts.dart
T
alan 413c923e77 Graph: stage popover with the prompt, tools, configs and run facts
Tapping or pressing Enter on a stage in the pipeline or run graph (inline
and full screen) opens a card anchored to the node: type, config chips,
tools, collapsed permissions, the prompt clamped with Show all (commands,
gate or operator instructions by type), limits and routes, and for runs
the status, visits, time, verdict, handoff and failure. Open definition
keeps the old tap target; Open visit the old run tap. It follows pan and
zoom, closes on outside tap, Escape or the same node, and opens as a
bottom sheet on a narrow viewport.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 23:19:18 +00:00

191 lines
5.6 KiB
Dart

import 'package:flutter/material.dart';
import '../domain/graph_definition.dart';
import '../domain/run_graph_state.dart';
import 'graph_stage_node.dart';
import 'measured_child.dart';
/// The run canvas's placed pieces: taken-route labels, run nodes and the
/// offstage measurement of exactly those widgets.
/// A taken route's label led by its place in the run (`2`, or `2, 5` for a
/// loop), so the path reads in order.
///
/// The canvas places this widget and [RunGraphMeasurements] measures the same
/// one, so the routed label box covers the order badge as well as the text.
class RunRouteLabel extends StatelessWidget {
const RunRouteLabel({
super.key,
required this.edgeId,
required this.label,
required this.order,
required this.style,
required this.color,
});
final int edgeId;
final String label;
final List<int> order;
final TextStyle style;
final Color color;
@override
Widget build(BuildContext context) {
final text = Text(label, style: style);
if (order.isEmpty) return text;
return Row(
mainAxisSize: MainAxisSize.min,
children: [
Container(
key: ValueKey('run-route-order:$edgeId'),
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 1),
decoration: BoxDecoration(
color: color,
borderRadius: BorderRadius.circular(8),
),
child: Text(
order.join(', '),
style: const TextStyle(
color: Color(0xFFFFFFFF),
fontSize: 10,
fontWeight: FontWeight.w700,
),
),
),
const SizedBox(width: 4),
text,
],
);
}
}
/// One placed run node. A stage is the native control with its recorded status
/// (none when unvisited) and opens its popover; a terminal is a label with no
/// tap target or button semantics, because it has no declaration. [active]
/// marks the run's recorded current stage while it executes; it only adds the
/// live halo, never a visit or a control.
class RunGraphNode extends StatelessWidget {
const RunGraphNode({
super.key,
required this.node,
required this.recordedStatus,
required this.interactive,
required this.onSelected,
this.selected = false,
this.active = false,
});
final GraphNode node;
final String? recordedStatus;
final bool interactive;
final bool selected;
final bool active;
final ValueChanged<String> onSelected;
@override
Widget build(BuildContext context) {
final status = recordedStatus;
if (interactive) {
return GraphStageNode(
node: node,
recordedStatus: status,
selected: selected,
active: active,
onSelected: onSelected,
);
}
return Semantics(
container: true,
label: graphNodeSemanticsLabel(node, status),
child: ExcludeSemantics(
child: IgnorePointer(
child: GraphStageNode(
node: node,
recordedStatus: status,
active: active,
onSelected: (_) {},
),
),
),
);
}
}
/// Measures the status-bearing run nodes and every route label offstage.
///
/// A visited node is taller than the same node without its recorded status, so
/// the measurement must use the exact widget the canvas places. Sizes are
/// reported after layout and callers schedule the placement frame.
class RunGraphMeasurements extends StatelessWidget {
const RunGraphMeasurements({
super.key,
required this.nodes,
required this.edges,
required this.maxNodeWidth,
required this.labelStyle,
required this.recordedStatuses,
required this.state,
required this.onNodeSize,
required this.onLabelSize,
});
final List<GraphNode> nodes;
final List<GraphEdge> edges;
final double maxNodeWidth;
final TextStyle labelStyle;
final Map<String, String?> recordedStatuses;
/// The run whose route order badges lead the taken labels.
final RunGraphState state;
final void Function(String, Size) onNodeSize;
/// Receives each edge's label size keyed by its edge id, because two edges
/// with the same outcome can carry different order badges.
final void Function(int, Size) onLabelSize;
@override
Widget build(BuildContext context) => Offstage(
child: OverflowBox(
alignment: Alignment.topLeft,
minWidth: 0,
maxWidth: double.infinity,
minHeight: 0,
maxHeight: double.infinity,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
for (final node in nodes)
MeasuredChild(
key: ValueKey(
'run-node:${node.key}:${node.label}:'
'${recordedStatuses[node.key] ?? ''}',
),
onSize: (size) => onNodeSize(node.key, size),
child: ConstrainedBox(
constraints: BoxConstraints(maxWidth: maxNodeWidth),
child: GraphStageNode(
node: node,
recordedStatus: recordedStatuses[node.key],
onSelected: (_) {},
),
),
),
for (final edge in edges)
MeasuredChild(
key: ValueKey('run-label:${edge.id}'),
onSize: (size) => onLabelSize(edge.id, size),
child: RunRouteLabel(
edgeId: edge.id,
label: edge.label,
order: state.routeOrder(edge.source, edge.outcome, edge.target),
style: labelStyle,
color: const Color(0x00000000),
),
),
],
),
),
);
}