Files
pipelines/app/lib/features/graph/viewport/graph_expanded_view.dart
T
alan fde086cc4a feat(app): glass viewer bars, graph controls and immersive image viewer
Review findings F12, F13, F25 and F1 for viewers: the artifact viewer's
actions/pager and the Changes pager float as glass pills over content,
file facts move to the top bar, graph overlay controls are one glass pill
(duplicate fullscreen glyph removed), the image viewer is immersive, and
diff/artifact/graph views let content pass behind the bar. Implemented by
pipeline run #204 (Terra); its Review stopped after three rejections, the
last being an empty glass bar for a single unresolved artifact, which the
manager fixed here with a regression test.
2026-10-31 04:26:22 +00:00

170 lines
5.2 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../ui/adaptive/segmented_bar.dart';
import '../../../ui/adaptive/host.dart';
import '../../../ui/adaptive/floating_bar_layout.dart';
import 'graph_viewport.dart';
import 'graph_viewport_controller.dart';
/// The expanded presentation's close wording (`Close`).
const String graphExpandedClose = 'Close';
/// Builds the same canvas for another viewport, with the selection that
/// presentation is showing.
typedef GraphExpandedCanvasBuilder =
Widget Function(
BuildContext context,
String? selectedStage,
ValueChanged<String> onSelected,
);
/// A native full-screen presentation of one graph canvas.
///
/// It fits the graph into the larger box (as the web does when its panel
/// expands), keeps the selected node selected, and lets a tap in the larger
/// canvas update that selection through [onSelected]. Closing pops the route;
/// the inline canvas was never changed, so it returns to its previous state.
class GraphExpandedView extends StatefulWidget {
const GraphExpandedView({
super.key,
required this.contentSize,
required this.canvasBuilder,
required this.title,
required this.onSelected,
this.selectedStage,
this.header,
});
/// The measured graph extent, as in the inline canvas.
final Size contentSize;
final GraphExpandedCanvasBuilder canvasBuilder;
/// The presentation's native title, e.g. `Run graph`.
final String title;
/// Reports a node activated in the expanded canvas.
final ValueChanged<String> onSelected;
/// Optional fixed content above the canvas, e.g. a legend that explains the
/// graph's marks. It stays outside the pan/zoom transform.
final Widget? header;
final String? selectedStage;
@override
State<GraphExpandedView> createState() => _GraphExpandedViewState();
}
class _GraphExpandedViewState extends State<GraphExpandedView> {
final GraphViewportController _controller = GraphViewportController();
late String? _selected = widget.selectedStage;
@override
void didUpdateWidget(GraphExpandedView oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.selectedStage != oldWidget.selectedStage) {
_selected = widget.selectedStage;
}
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
void _select(String key) {
setState(() => _selected = key);
widget.onSelected(key);
}
void _close() => Navigator.of(context).maybePop();
@override
Widget build(BuildContext context) {
final viewport = GraphViewport(
key: const Key('graph-expanded-viewport'),
controller: _controller,
contentSize: widget.contentSize,
// The larger box fits the whole graph, as the web does when its panel
// expands; a later resize re-fits until the reader pans or zooms, then
// only clamps.
child: widget.canvasBuilder(context, _selected, _select),
);
final body = widget.header == null
? viewport
: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
widget.header!,
Expanded(child: viewport),
],
);
if (usesCupertinoHost(context)) {
return CupertinoPageScaffold(
navigationBar: SegmentedBar(
cupertino: true,
automaticallyImplyLeading: false,
title: widget.title,
actions: [
CupertinoButton(
key: const Key('graph-expanded-close'),
padding: const EdgeInsets.symmetric(horizontal: 16),
onPressed: _close,
child: const Text(graphExpandedClose),
),
],
),
child: BelowTopBar(child: body),
);
}
return Scaffold(
extendBodyBehindAppBar: true,
appBar: SegmentedBar(
cupertino: false,
title: widget.title,
automaticallyImplyLeading: false,
actions: [
TextButton(
key: const Key('graph-expanded-close'),
onPressed: _close,
child: const Text(graphExpandedClose),
),
],
),
body: BelowTopBar(child: body),
);
}
}
/// Pushes [GraphExpandedView] with the host's native full-screen transition.
///
/// This is the seam a Graph tab or run detail can call: pass the measured
/// content size and a builder that draws the same canvas for the supplied
/// selection. The expanded canvas fits that size; the inline canvas is
/// untouched.
Future<void> openGraphExpanded(
BuildContext context, {
required Size contentSize,
required GraphExpandedCanvasBuilder canvasBuilder,
required String title,
required ValueChanged<String> onSelected,
String? selectedStage,
Widget? header,
}) {
final page = GraphExpandedView(
contentSize: contentSize,
canvasBuilder: canvasBuilder,
title: title,
onSelected: onSelected,
selectedStage: selectedStage,
header: header,
);
final route = usesCupertinoHost(context)
? CupertinoPageRoute<void>(fullscreenDialog: true, builder: (_) => page)
: MaterialPageRoute<void>(fullscreenDialog: true, builder: (_) => page);
return Navigator.of(context).push(route);
}