feat(app): a run's stage visit opens as its own page, from the graph, the timeline or a link
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
@@ -90,6 +91,11 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
|
||||
String? _selectedStage;
|
||||
int? _selectedVisit;
|
||||
|
||||
/// The visit whose page is open, and the live run that page follows.
|
||||
int? _shownVisit;
|
||||
Route<void>? _visitRoute;
|
||||
late final ValueNotifier<JsonMap> _liveRun = ValueNotifier(widget.run);
|
||||
|
||||
/// The Summary's collapsible Input and Output sections. A search text hit
|
||||
/// expands the one its recorded field names, exactly as the browser opens the
|
||||
/// matching Summary section. The detail owns them so the tab body stays a
|
||||
@@ -117,12 +123,14 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
|
||||
void dispose() {
|
||||
_inputSection.dispose();
|
||||
_outputSection.dispose();
|
||||
_liveRun.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant RunDetailTabs oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
_liveRun.value = widget.run;
|
||||
final sameRun = '${widget.run['id']}' == '${oldWidget.run['id']}';
|
||||
final sameTarget =
|
||||
widget.initialStageKey == oldWidget.initialStageKey &&
|
||||
@@ -250,7 +258,74 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
|
||||
setState(() => _selectedVisit = index);
|
||||
}
|
||||
|
||||
void _closeVisit() => setState(() => _selectedVisit = null);
|
||||
/// Brings the open visit page in line with the selection after this frame:
|
||||
/// a cleared selection closes it, another visit replaces it.
|
||||
void _syncVisitPage() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted || _selectedVisit == _shownVisit) return;
|
||||
final open = _visitRoute;
|
||||
if (open != null) {
|
||||
_shownVisit = null;
|
||||
_visitRoute = null;
|
||||
if (open.isActive) Navigator.of(context).removeRoute(open);
|
||||
}
|
||||
final index = _selectedVisit;
|
||||
if (index != null) _pushVisit(index);
|
||||
});
|
||||
}
|
||||
|
||||
/// Opens [index]'s visit as its own page. The page follows the live run, so
|
||||
/// a visit still running keeps updating; leaving it returns to the timeline.
|
||||
Future<void> _pushVisit(int index) async {
|
||||
_shownVisit = index;
|
||||
final cupertino = widget.cupertino;
|
||||
Widget page(BuildContext pageContext) => ValueListenableBuilder<JsonMap>(
|
||||
valueListenable: _liveRun,
|
||||
builder: (context, run, _) {
|
||||
final visits = detailTimeline(run['steps']);
|
||||
final step = detailVisitStepAt(run, index);
|
||||
final pane = index < visits.length && step != null
|
||||
? RunVisitPane(
|
||||
run: run,
|
||||
visit: visits[index],
|
||||
visitIndex: index,
|
||||
step: step,
|
||||
runSteps: detailRunSteps(run),
|
||||
gateway: widget.gateway,
|
||||
onRunChanged: widget.onRunChanged,
|
||||
configuredEndpoint: widget.configuredEndpoint,
|
||||
cupertino: cupertino,
|
||||
onClose: () => Navigator.of(pageContext).pop(),
|
||||
)
|
||||
: const Center(child: Text('This visit is no longer recorded.'));
|
||||
// The pane names the visit; the bar names the run it belongs to.
|
||||
final title = detailTitle(run);
|
||||
if (cupertino) {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(middle: Text(title)),
|
||||
child: SafeArea(child: pane),
|
||||
);
|
||||
}
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(title)),
|
||||
body: SafeArea(top: false, child: pane),
|
||||
);
|
||||
},
|
||||
);
|
||||
final route = cupertino
|
||||
? CupertinoPageRoute<void>(builder: page)
|
||||
: MaterialPageRoute<void>(builder: page);
|
||||
_visitRoute = route;
|
||||
await Navigator.of(context).push<void>(route);
|
||||
// Only the page the operator left clears the selection; one replaced by
|
||||
// another selection has already handed over.
|
||||
if (!mounted || _visitRoute != route) return;
|
||||
setState(() {
|
||||
_visitRoute = null;
|
||||
_shownVisit = null;
|
||||
_selectedVisit = null;
|
||||
});
|
||||
}
|
||||
|
||||
/// Artifacts once the run has recorded steps; Changes once it has stopped
|
||||
/// executing, since a snapshot would not follow live captures.
|
||||
@@ -266,6 +341,8 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// A selected visit opens on its own page; the tab keeps the list.
|
||||
if (_selectedVisit != _shownVisit) _syncVisitPage();
|
||||
final tabs = _tabsFor(widget.run);
|
||||
// A tab the run no longer offers falls back to Summary.
|
||||
final shown = tabs.contains(_tab) || !renderedRunDetailTabs.contains(_tab)
|
||||
@@ -375,26 +452,6 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
|
||||
case RunDetailTab.timeline:
|
||||
final visits = detailTimeline(widget.run['steps']);
|
||||
final index = _selectedVisit;
|
||||
if (index != null && index >= 0 && index < visits.length) {
|
||||
final step = detailVisitStepAt(widget.run, index);
|
||||
if (step != null) {
|
||||
return KeyedSubtree(
|
||||
key: const Key('run-detail-tab-body-timeline'),
|
||||
child: RunVisitPane(
|
||||
run: widget.run,
|
||||
visit: visits[index],
|
||||
visitIndex: index,
|
||||
step: step,
|
||||
runSteps: detailRunSteps(widget.run),
|
||||
gateway: widget.gateway,
|
||||
onRunChanged: widget.onRunChanged,
|
||||
configuredEndpoint: widget.configuredEndpoint,
|
||||
cupertino: widget.cupertino,
|
||||
onClose: _closeVisit,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
return RunTimelineList(
|
||||
visits: visits,
|
||||
selectedSequence: index != null && index >= 0 && index < visits.length
|
||||
|
||||
Reference in New Issue
Block a user