137 lines
4.6 KiB
Dart
137 lines
4.6 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../ui/adaptive/segmented_bar.dart';
|
|
import '../../../core/api_gateway.dart';
|
|
import '../../../ui/adaptive/host.dart';
|
|
import '../../../ui/adaptive/floating_bar_layout.dart';
|
|
import '../../graph/domain/graph_definition.dart';
|
|
import '../../graph/widgets/run_graph_view.dart';
|
|
|
|
const runGraphPreviewKey = ValueKey<String>('run-graph-preview');
|
|
|
|
/// The muted line shown in place of the preview when the run has no graph.
|
|
const runGraphPreviewMissingKey = ValueKey<String>('run-graph-preview-missing');
|
|
|
|
/// 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);
|
|
// No graph to draw: one muted line, with no frame and nothing to open.
|
|
if (graphNodes(graph).isEmpty) {
|
|
return Padding(
|
|
key: runGraphPreviewMissingKey,
|
|
padding: const EdgeInsets.fromLTRB(16, 12, 16, 0),
|
|
child: Text(
|
|
runGraphMissing,
|
|
style: cupertino
|
|
? CupertinoTheme.of(context).textTheme.textStyle.copyWith(
|
|
color: CupertinoColors.secondaryLabel.resolveFrom(context),
|
|
)
|
|
: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
|
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
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,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
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 SegmentedBar(
|
|
cupertino: true,
|
|
title: 'Graph',
|
|
),
|
|
child: BelowTopBar(child: graphView(page)),
|
|
),
|
|
)
|
|
: MaterialPageRoute<void>(
|
|
builder: (page) => Scaffold(
|
|
extendBodyBehindAppBar: true,
|
|
appBar: const SegmentedBar(cupertino: false, title: 'Graph'),
|
|
body: BelowTopBar(child: graphView(page)),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|