Files
pipelines/app/lib/features/runs/ui/run_graph_preview.dart
T

123 lines
4.0 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
import '../../../ui/adaptive/host.dart';
import '../../graph/widgets/run_graph_view.dart';
const runGraphPreviewKey = ValueKey<String>('run-graph-preview');
/// The run graph as a still picture on top of Summary. Tapping it opens the
/// interactive graph full screen; picking a stage there closes it and hands
/// the stage to [onStageSelected].
class RunGraphPreview extends StatelessWidget {
const RunGraphPreview({
super.key,
required this.graph,
required this.run,
required this.onStageSelected,
this.selectedStage,
this.height = 200,
});
final JsonMap? graph;
final JsonMap run;
final ValueChanged<String> onStageSelected;
final String? selectedStage;
final double height;
@override
Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context);
final border = cupertino
? CupertinoColors.separator.resolveFrom(context)
: Theme.of(context).colorScheme.outlineVariant;
return Padding(
padding: const EdgeInsets.fromLTRB(16, 12, 16, 0),
child: Semantics(
button: true,
label: 'Run graph, open full screen',
excludeSemantics: true,
onTap: () => _open(context, cupertino),
child: GestureDetector(
key: runGraphPreviewKey,
behavior: HitTestBehavior.opaque,
onTap: () => _open(context, cupertino),
child: DecoratedBox(
decoration: BoxDecoration(
border: Border.all(color: border),
borderRadius: BorderRadius.circular(12),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(12),
child: SizedBox(
height: height,
child: Stack(
children: [
Positioned.fill(
// A picture, not a control: the full-screen view is
// where the graph pans, zooms and opens stages.
child: IgnorePointer(
child: RunGraphView(
graph: graph,
run: run,
selectedStage: selectedStage,
onStageSelected: (_) {},
showHeader: false,
),
),
),
PositionedDirectional(
end: 8,
bottom: 8,
child: Icon(
cupertino
? CupertinoIcons.fullscreen
: Icons.open_in_full,
size: 18,
color: border,
),
),
],
),
),
),
),
),
),
);
}
Future<void> _open(BuildContext context, bool cupertino) {
Widget graphView(BuildContext pageContext) => RunGraphView(
key: const Key('run-detail-graph'),
// Already full screen: no maximise button to open it again.
expandable: false,
graph: graph,
run: run,
selectedStage: selectedStage,
onStageSelected: (stage) {
Navigator.of(pageContext).pop();
onStageSelected(stage);
},
);
return Navigator.of(context).push<void>(
cupertino
? CupertinoPageRoute<void>(
builder: (page) => CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('Graph'),
),
child: SafeArea(child: graphView(page)),
),
)
: MaterialPageRoute<void>(
builder: (page) => Scaffold(
appBar: AppBar(title: const Text('Graph')),
body: SafeArea(top: false, child: graphView(page)),
),
),
);
}
}