Files
pipelines/app/lib/features/graph/viewport/graph_viewport.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

198 lines
6.6 KiB
Dart

import 'package:flutter/material.dart';
import '../../../ui/adaptive/glass_pill.dart';
import 'graph_viewport_controller.dart';
import 'graph_viewport_scope.dart';
/// The fit control's web wording (`Fit graph to view`).
const String graphFitLabel = 'Fit graph to view';
/// The expand control's web wording (`Expand graph`).
const String graphExpandLabel = 'Expand graph';
/// A bounded graph canvas with the host's own pan, pinch, wheel and trackpad
/// zoom, plus a fit control and an optional expanded presentation.
///
/// [controller] owns the transform, so a caller can read or restore a
/// [GraphViewportSnapshot]. Gestures are consumed only inside this widget's
/// box: an ancestor scroll view keeps scrolling everywhere else, and a tap
/// that does not move still reaches the native node under the pointer.
class GraphViewport extends StatefulWidget {
const GraphViewport({
super.key,
required this.controller,
required this.contentSize,
required this.child,
this.onExpand,
this.showControls = true,
});
final GraphViewportController controller;
/// The measured graph extent; the canvas never invents a fixed size.
final Size contentSize;
/// The measured, already-routed graph content.
final Widget child;
/// Opens the expanded presentation. Null hides the expand control.
final VoidCallback? onExpand;
/// Whether this canvas draws its own fit/expand pill. Full-screen graph
/// views place Fit in their top-bar actions instead.
final bool showControls;
@override
State<GraphViewport> createState() => _GraphViewportState();
}
class _GraphViewportState extends State<GraphViewport> {
final GlobalKey _viewportKey = GlobalKey(debugLabel: 'graph-viewport-box');
Size? _scheduledViewport;
Size? _scheduledContent;
@override
void didUpdateWidget(GraphViewport oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.controller != widget.controller) {
_scheduledViewport = null;
_scheduledContent = null;
}
}
/// Attaches the current extents after layout, never during build.
void _scheduleAttach(Size viewport) {
if (viewport == _scheduledViewport &&
widget.contentSize == _scheduledContent) {
return;
}
_scheduledViewport = viewport;
_scheduledContent = widget.contentSize;
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) return;
widget.controller.attach(viewport: viewport, content: widget.contentSize);
});
}
@override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (context, constraints) {
final viewport =
constraints.hasBoundedWidth && constraints.hasBoundedHeight
? constraints.biggest
: widget.contentSize;
if (!widget.controller.isAttached) {
// The very first layout has no `InteractiveViewer` listening yet, so
// fitting here applies before the first paint instead of flashing an
// identity transform for one frame.
widget.controller.attach(
viewport: viewport,
content: widget.contentSize,
);
_scheduledViewport = viewport;
_scheduledContent = widget.contentSize;
} else {
_scheduleAttach(viewport);
}
return Stack(
fit: StackFit.expand,
children: [
Positioned.fill(
key: _viewportKey,
child: GraphViewportScope(
transform: widget.controller.transformation,
viewportKey: _viewportKey,
viewportSize: viewport,
child: InteractiveViewer(
key: const Key('graph-viewport'),
transformationController: widget.controller.transformation,
constrained: false,
// The graph owns its own bounds (fit and the visible-pan clamp),
// so the viewer must not impose a second, cover-the-viewport
// boundary that would fight the fit scale.
boundaryMargin: const EdgeInsets.all(double.infinity),
minScale: widget.controller.minScale,
maxScale: widget.controller.maxScale,
clipBehavior: Clip.hardEdge,
child: SizedBox.fromSize(
size: widget.contentSize,
child: widget.child,
),
),
),
),
if (widget.showControls)
PositionedDirectional(
top: 8,
end: 8,
child: GlassPill(
child: Wrap(
spacing: 2,
children: [
_ViewportButton(
buttonKey: const Key('graph-fit'),
icon: Icons.fit_screen,
label: graphFitLabel,
onPressed: widget.controller.fitToViewport,
),
if (widget.onExpand != null)
_ViewportButton(
buttonKey: const Key('graph-expand'),
icon: Icons.fullscreen,
label: graphExpandLabel,
onPressed: widget.onExpand,
),
],
),
),
),
],
);
},
);
}
}
/// One native graph control inside the shared floating glass pill.
///
/// The label and the button's own tap action must reach the same semantics
/// node: the icon is the only excluded child, and [MergeSemantics] folds the
/// host button's action into the labelled node, so a screen reader can activate
/// Fit and Expand. A hand-written `Semantics` sibling around an
/// excluded button would announce the control with no action at all.
class _ViewportButton extends StatelessWidget {
const _ViewportButton({
required this.buttonKey,
required this.icon,
required this.label,
required this.onPressed,
});
final Key buttonKey;
final IconData icon;
final String label;
final VoidCallback? onPressed;
@override
Widget build(BuildContext context) {
return MergeSemantics(
child: Semantics(
button: true,
label: label,
child: Tooltip(
message: label,
// The merged node already carries the label; the tooltip is
// only the pointer affordance.
excludeFromSemantics: true,
child: IconButton(
key: buttonKey,
onPressed: onPressed,
icon: ExcludeSemantics(child: Icon(icon)),
),
),
),
);
}
}