From 925f04e3001f137b82203556b72f9e2ef4904d72 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Fri, 23 Oct 2026 17:35:33 +0100 Subject: [PATCH] feat(app): a run's stage visit opens as its own page, from the graph, the timeline or a link --- app/lib/features/runs/ui/run_detail_tabs.dart | 99 +++++++++++++++---- app/test/application/pipelines_app_test.dart | 6 ++ app/test/application/search_wiring_test.dart | 23 ++++- .../runs/ui/run_detail_deep_link_test.dart | 6 +- .../runs/ui/run_detail_graph_tab_test.dart | 20 +++- 5 files changed, 124 insertions(+), 30 deletions(-) diff --git a/app/lib/features/runs/ui/run_detail_tabs.dart b/app/lib/features/runs/ui/run_detail_tabs.dart index e7be2268..4f5e2f68 100644 --- a/app/lib/features/runs/ui/run_detail_tabs.dart +++ b/app/lib/features/runs/ui/run_detail_tabs.dart @@ -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 { String? _selectedStage; int? _selectedVisit; + /// The visit whose page is open, and the live run that page follows. + int? _shownVisit; + Route? _visitRoute; + late final ValueNotifier _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 { 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 { 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 _pushVisit(int index) async { + _shownVisit = index; + final cupertino = widget.cupertino; + Widget page(BuildContext pageContext) => ValueListenableBuilder( + 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(builder: page) + : MaterialPageRoute(builder: page); + _visitRoute = route; + await Navigator.of(context).push(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 { @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 { 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 diff --git a/app/test/application/pipelines_app_test.dart b/app/test/application/pipelines_app_test.dart index a9812d67..16e0d948 100644 --- a/app/test/application/pipelines_app_test.dart +++ b/app/test/application/pipelines_app_test.dart @@ -270,6 +270,10 @@ void main() { ], ); await replyVisitDetail(tester, channel, 77); + // The visit opens as its own page once the detail has drawn. + await tester.pump(); + await tester.pump(const Duration(milliseconds: 400)); + await tester.pump(const Duration(milliseconds: 400)); // The query reached the detail: visit 0 is the earlier plan visit (seq 1), // not the latest one the pane would show without a visit. @@ -287,6 +291,8 @@ void main() { await provider.didPushRouteInformation(RouteInformation(uri: restored)); await tester.pump(); await tester.pump(); + await tester.pump(const Duration(milliseconds: 400)); + await tester.pump(const Duration(milliseconds: 400)); expect(find.text('plan · visit 5'), findsOneWidget); expect(provider.value.uri.path, '/runs/77/stage/plan'); expect(provider.value.uri.query, 'visit=1'); diff --git a/app/test/application/search_wiring_test.dart b/app/test/application/search_wiring_test.dart index 0ab90a5c..a4ff540a 100644 --- a/app/test/application/search_wiring_test.dart +++ b/app/test/application/search_wiring_test.dart @@ -494,9 +494,18 @@ void main() { expect(provider.value.uri.path, '/runs/7'); expect(find.byType(SearchScreen), findsNothing); expect(find.byKey(const Key('run-visit-pane')), findsOneWidget); - expect(find.text('build · visit 2'), findsOneWidget); + expect( + find.descendant( + of: find.byKey(const Key('run-visit-pane')), + matching: find.text('build · visit 2'), + ), + findsOneWidget, + ); - // A retired field hit replaces that open visit with the plain Summary. + // Leave the visit page (it covers the shell), then a retired field hit + // opens the plain Summary with no visit. + await tester.tap(find.byKey(const Key('run-visit-back'))); + await tester.pumpAndSettle(); await sendSearch(query: 'retired', index: 1, hit: retiredFieldHit()); await tester.tap( find.byKey(const ValueKey('search.result.run:7:5:evidence')), @@ -602,7 +611,13 @@ void main() { await tester.pumpAndSettle(); expect(find.byKey(const Key('run-visit-pane')), findsOneWidget); - expect(find.text('build · visit 2'), findsOneWidget); + expect( + find.descendant( + of: find.byKey(const Key('run-visit-pane')), + matching: find.text('build · visit 2'), + ), + findsOneWidget, + ); await tester.pumpWidget(const SizedBox.shrink()); await tester.pump(); @@ -694,6 +709,8 @@ void main() { await tester.pumpAndSettle(); expect(find.byKey(const Key('run-visit-pane')), findsOneWidget); + await tester.tap(find.byKey(const Key('run-visit-back'))); + await tester.pumpAndSettle(); await tester.tap(find.text('Back to list')); await tester.pump(); await tester.pump(); diff --git a/app/test/features/runs/ui/run_detail_deep_link_test.dart b/app/test/features/runs/ui/run_detail_deep_link_test.dart index b45ded91..00367547 100644 --- a/app/test/features/runs/ui/run_detail_deep_link_test.dart +++ b/app/test/features/runs/ui/run_detail_deep_link_test.dart @@ -138,8 +138,12 @@ void main() { expect(find.byKey(const Key('run-visit-pane')), findsOneWidget); expect(find.text('plan · visit 1'), findsOneWidget); expect(find.text('plan · visit 5'), findsNothing); + // The visit is its own page over the Timeline tab. expect( - find.byKey(const Key('run-detail-tab-body-timeline')), + find.byKey( + const Key('run-detail-tab-body-timeline'), + skipOffstage: false, + ), findsWidgets, ); }); diff --git a/app/test/features/runs/ui/run_detail_graph_tab_test.dart b/app/test/features/runs/ui/run_detail_graph_tab_test.dart index ac140906..d1a4cbbb 100644 --- a/app/test/features/runs/ui/run_detail_graph_tab_test.dart +++ b/app/test/features/runs/ui/run_detail_graph_tab_test.dart @@ -48,14 +48,22 @@ void main() { await tapGraphNode(tester, 'plan'); await tester.pumpAndSettle(); - // The Graph reports the stage and the detail moves to Timeline, where the - // exact recorded visit is open. + // The Graph reports the stage; the exact recorded visit opens as its + // own page over the Timeline tab. expect(find.byType(RunGraphView), findsNothing); expect( - find.byKey(const Key('run-detail-tab-body-timeline')), + find.byKey( + const Key('run-detail-tab-body-timeline'), + skipOffstage: false, + ), findsOneWidget, ); expect(find.byKey(const Key('run-visit-pane')), findsOneWidget); + // On its own page: the timeline list is covered, not swapped in place. + expect( + find.byKey(const Key('run-detail-tab-body-timeline')), + findsNothing, + ); expect(find.byKey(const Key('run-visit-title')), findsOneWidget); expect(find.text('plan · visit 1'), findsOneWidget); expect(find.textContaining('Status:'), findsOneWidget); @@ -90,8 +98,10 @@ void main() { await tapGraphNode(tester, 'plan'); await tester.pumpAndSettle(); - // At 320/2x the strip scrolls. A Graph-driven switch must scroll the - // selected Timeline segment into view, not leave Summary/Graph showing. + // Leaving the visit page lands on Timeline. At 320/2x the strip + // scrolls; the selected Timeline segment must be in view. + await tester.tap(find.byKey(const Key('run-visit-back'))); + await tester.pumpAndSettle(); final timeline = tester.getRect(runDetailTab(RunDetailTab.timeline)); expect(timeline.left, greaterThanOrEqualTo(0)); expect(timeline.right, lessThanOrEqualTo(320));