diff --git a/app/lib/application/app_router.dart b/app/lib/application/app_router.dart index ba7c5aa8..b7f726c8 100644 --- a/app/lib/application/app_router.dart +++ b/app/lib/application/app_router.dart @@ -213,8 +213,13 @@ class AppRouterDelegate extends RouterDelegate with ChangeNotifier { notifyListeners(); } + /// Back (Android's button, the browser's): close whatever page sits on top + /// first, then step up one level — a stage to its run or pipeline, a run, + /// pipeline or chat to its list — and only leave the app from a list. @override Future popRoute() async { + final navigator = _navigatorKey.currentState; + if (navigator != null && await navigator.maybePop()) return true; if (searchOpen) { closeSearch(); return true; @@ -227,10 +232,24 @@ class AppRouterDelegate extends RouterDelegate with ChangeNotifier { closeTemplates(); return true; } - if (_route.runId != null) { + final runId = _route.runId; + if (runId != null && _route.stageKey != null) { + goTo(AppRoute.run(runId)); + return true; + } + if (runId != null) { onPopToRuns(); return true; } + final pipelineId = _route.pipelineId; + if (_route.kind == AppRouteKind.pipelines && pipelineId != null) { + goTo( + _route.stageKey != null + ? AppRoute.pipeline(pipelineId, version: _route.version) + : AppRoute.pipelines, + ); + return true; + } if (_route.chatSessionId != null) { onPopToChat(); return true; diff --git a/app/lib/application/pipelines_app.dart b/app/lib/application/pipelines_app.dart index 40bb013b..26cc6e3f 100644 --- a/app/lib/application/pipelines_app.dart +++ b/app/lib/application/pipelines_app.dart @@ -410,6 +410,10 @@ class _PipelinesAppState extends State final chatRoute = tab(AppDestination.chat); return AdaptiveShell( attentionCount: attentionCount, + detailOpen: + route.runId != null || + route.chatSessionId != null || + (route.kind == AppRouteKind.pipelines && route.pipelineId != null), cupertino: _cupertino, destination: _destinationOf(route.kind), onDestinationSelected: _selectDestination, diff --git a/app/lib/features/runs/ui/run_detail_visit_sections.dart b/app/lib/features/runs/ui/run_detail_visit_sections.dart index 56e26b5e..689d23a1 100644 --- a/app/lib/features/runs/ui/run_detail_visit_sections.dart +++ b/app/lib/features/runs/ui/run_detail_visit_sections.dart @@ -128,18 +128,19 @@ class RunVisitSectionStrip extends StatelessWidget { } /// The stage page's tabs: Summary (Input and Output), Artifacts, Changes and -/// More (Session and Definition). The finer sections stay addressable. +/// Session. The finer sections stay addressable. const shownVisitSections = [ RunVisitSection.summary, RunVisitSection.artifacts, RunVisitSection.changes, - RunVisitSection.more, + RunVisitSection.session, ]; /// The tab that shows [section]. RunVisitSection visitTabFor(RunVisitSection section) => switch (section) { RunVisitSection.input || RunVisitSection.output => RunVisitSection.summary, - RunVisitSection.session || RunVisitSection.definition => RunVisitSection.more, + // The stage's definition lives on the pipeline, not on a run's visit. + RunVisitSection.more || RunVisitSection.definition => RunVisitSection.session, _ => section, }; @@ -178,10 +179,7 @@ Widget runVisitSectionBody({ cupertino: cupertino, ); case RunVisitSection.more: - return _MoreSection( - session: body(RunVisitSection.session), - definition: body(RunVisitSection.definition), - ); + return body(RunVisitSection.session); case RunVisitSection.input: return runDetailFieldTab( tabKey: 'visit-input', @@ -230,57 +228,6 @@ Widget runVisitSectionBody({ } } -/// Session and Definition behind one tab, with a small switch between them. -class _MoreSection extends StatefulWidget { - const _MoreSection({required this.session, required this.definition}); - - final Widget session; - final Widget definition; - - @override - State<_MoreSection> createState() => _MoreSectionState(); -} - -class _MoreSectionState extends State<_MoreSection> { - var _definition = false; - - @override - Widget build(BuildContext context) { - final cupertino = usesCupertinoHost(context); - final control = cupertino - ? CupertinoSlidingSegmentedControl( - key: const Key('run-visit-more-switch'), - groupValue: _definition, - onValueChanged: (value) => - setState(() => _definition = value ?? false), - children: const {false: Text('Session'), true: Text('Definition')}, - ) - : SegmentedButton( - key: const Key('run-visit-more-switch'), - showSelectedIcon: false, - segments: const [ - ButtonSegment(value: false, label: Text('Session')), - ButtonSegment(value: true, label: Text('Definition')), - ], - selected: {_definition}, - onSelectionChanged: (value) => - setState(() => _definition = value.single), - ); - return Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - Padding( - padding: const EdgeInsets.fromLTRB(16, 8, 16, 0), - child: control, - ), - Expanded(child: _definition ? widget.definition : widget.session), - ], - ); - } -} - -/// The stage's Input and Output as sticky collapsibles, each with a copy -/// button for its recorded text. class _VisitSummary extends StatefulWidget { const _VisitSummary({ super.key, diff --git a/app/lib/shell/adaptive_shell.dart b/app/lib/shell/adaptive_shell.dart index 0851e56f..9c80322a 100644 --- a/app/lib/shell/adaptive_shell.dart +++ b/app/lib/shell/adaptive_shell.dart @@ -15,6 +15,7 @@ class AdaptiveShell extends StatefulWidget { this.onDestinationSelected, this.onSearch, this.attentionCount = 0, + this.detailOpen = false, }); final Map destinationBodies; @@ -33,6 +34,10 @@ class AdaptiveShell extends StatefulWidget { /// so it stays visible from any destination. Zero shows no badge. final int attentionCount; + /// A pipeline, run or chat is open: on a phone it takes the whole screen, + /// like its own page, and the destination bar steps aside until Back. + final bool detailOpen; + @override State createState() => _AdaptiveShellState(); } @@ -183,18 +188,19 @@ class _AdaptiveShellState extends State { : Column( children: [ Expanded(child: _destinationStack(contents, index)), - CupertinoTabBar( - currentIndex: index, - onTap: (value) => - _select(AppDestination.values[value]), - items: _items((destination) { - final item = destinationDetails(destination); - return BottomNavigationBarItem( - icon: _icon(destination, item.cupertinoIcon), - label: item.label, - ); - }), - ), + if (!widget.detailOpen) + CupertinoTabBar( + currentIndex: index, + onTap: (value) => + _select(AppDestination.values[value]), + items: _items((destination) { + final item = destinationDetails(destination); + return BottomNavigationBarItem( + icon: _icon(destination, item.cupertinoIcon), + label: item.label, + ); + }), + ), ], ), ), @@ -250,7 +256,7 @@ class _AdaptiveShellState extends State { Expanded(child: _destinationStack(contents, index)), ], ), - bottomNavigationBar: wide + bottomNavigationBar: wide || widget.detailOpen ? null : NavigationBar( selectedIndex: index, diff --git a/app/test/application/app_router_test.dart b/app/test/application/app_router_test.dart index 5f0c1f33..51f2409f 100644 --- a/app/test/application/app_router_test.dart +++ b/app/test/application/app_router_test.dart @@ -13,6 +13,7 @@ AppRouterDelegate delegate(AppRoute initial, {void Function()? onChat}) => ); void main() { + TestWidgetsFlutterBinding.ensureInitialized(); test('system Back leaves one chat session for the chat list', () async { var left = 0; final router = delegate(AppRoute.chatSession('s1'), onChat: () => left++); @@ -22,6 +23,33 @@ void main() { expect(left, 1); }); + test('system Back steps up one level at a time', () async { + var runs = 0; + final router = AppRouterDelegate( + builder: (context, route) => const SizedBox.shrink(), + onPopToRuns: () => runs++, + onPopToChat: () {}, + cupertino: false, + initial: AppRoute.run.stage(77, 'plan', visit: 0), + ); + addTearDown(router.dispose); + + // A stage returns to its run, then the run to the Runs list. + expect(await router.popRoute(), isTrue); + expect(router.route, AppRoute.run(77)); + expect(await router.popRoute(), isTrue); + expect(runs, 1); + + // A pipeline stage returns to its pipeline, then to the list, and the + // list leaves Back to the platform. + router.goTo(AppRoute.pipelineStage(4, 'plan', version: 2)); + expect(await router.popRoute(), isTrue); + expect(router.route, AppRoute.pipeline(4, version: 2)); + expect(await router.popRoute(), isTrue); + expect(router.route, AppRoute.pipelines); + expect(await router.popRoute(), isFalse); + }); + test('system Back on a list destination stays with the platform', () async { final router = delegate(AppRoute.chat); addTearDown(router.dispose); diff --git a/app/test/application/search_wiring_test.dart b/app/test/application/search_wiring_test.dart index bcd8c33e..f0e20723 100644 --- a/app/test/application/search_wiring_test.dart +++ b/app/test/application/search_wiring_test.dart @@ -268,7 +268,7 @@ void main() { testWidgets( 'the Search tab opens focused and the Runs tab keeps the open run', (tester) async { - tester.view.physicalSize = const Size(390, 844); + tester.view.physicalSize = const Size(900, 1000); tester.view.devicePixelRatio = 1; addTearDown(tester.view.resetPhysicalSize); addTearDown(tester.view.resetDevicePixelRatio); @@ -295,7 +295,8 @@ void main() { ); await replyRunList(tester, channel); await replyRunDetail(tester, channel, 2); - expect(find.byKey(const ValueKey('shell.back')), findsOneWidget); + // On a phone an open run fills the screen and the tabs step aside, so + // switching tabs with a run open is a wide-window move. // Search is the fifth tab. await tapTab(tester, 'Search'); @@ -337,7 +338,7 @@ void main() { testWidgets('a result opens through the existing run route over one socket', ( tester, ) async { - tester.view.physicalSize = const Size(390, 844); + tester.view.physicalSize = const Size(900, 1000); tester.view.devicePixelRatio = 1; addTearDown(tester.view.resetPhysicalSize); addTearDown(tester.view.resetDevicePixelRatio); diff --git a/app/test/features/runs/ui/run_detail_visit_sections_test.dart b/app/test/features/runs/ui/run_detail_visit_sections_test.dart index c6eb84b1..edd92d48 100644 --- a/app/test/features/runs/ui/run_detail_visit_sections_test.dart +++ b/app/test/features/runs/ui/run_detail_visit_sections_test.dart @@ -21,12 +21,12 @@ void main() { expect(find.text('Back'), findsNothing); // The page bar's own Back is the only one. expect(find.byKey(const Key('run-visit-back')), findsOneWidget); - // Four tabs: Summary, Artifacts, Changes, More. + // Four tabs: Summary, Artifacts, Changes, Session. expect(shownVisitSections, [ RunVisitSection.summary, RunVisitSection.artifacts, RunVisitSection.changes, - RunVisitSection.more, + RunVisitSection.session, ]); // Summary holds both Input and Output. expect(find.text('Input'), findsOneWidget); @@ -73,9 +73,8 @@ void main() { expect(find.text('sess-1'), findsOneWidget); expect(find.text('Open session.html'), findsOneWidget); - await openVisitTab(tester, RunVisitSection.definition); - expect(find.byType(StageDefinitionView), findsOneWidget); - expect(find.text('Draft the plan.'), findsOneWidget); + // The stage's definition belongs to the pipeline, not to a visit. + expect(find.byType(StageDefinitionView), findsNothing); }); testWidgets('${platform.name} artifacts tab reports the capture state', ( @@ -178,21 +177,6 @@ void main() { expect(find.byType(ArtifactGalleryPage), findsOneWidget); }); - testWidgets('${platform.name} missing definition uses exact wording', ( - tester, - ) async { - await openVisit( - tester, - platform, - run: visitRunFixture(declareStage: false), - ); - await openVisitTab(tester, RunVisitSection.definition); - - expect(find.byType(StageDefinitionView), findsNothing); - expect(find.text(unknownStageDefinition), findsOneWidget); - expect(find.text('Draft the plan.'), findsNothing); - }); - testWidgets('${platform.name} visit sections at 320 with 2x dark text', ( tester, ) async { diff --git a/app/test/features/runs/ui/run_detail_visit_support.dart b/app/test/features/runs/ui/run_detail_visit_support.dart index caed4dd4..d1ac587a 100644 --- a/app/test/features/runs/ui/run_detail_visit_support.dart +++ b/app/test/features/runs/ui/run_detail_visit_support.dart @@ -115,8 +115,7 @@ Future openVisit( await tester.pumpAndSettle(); } -/// Opens the tab showing [section]: Input and Output are on Summary, Session -/// and Definition behind More's switch. +/// Opens the tab showing [section]: Input and Output are on Summary. Future openVisitTab(WidgetTester tester, RunVisitSection section) async { final shown = visitTabFor(section); final tab = find.byKey(ValueKey('run-visit-tab-${shown.name}')); @@ -124,15 +123,4 @@ Future openVisitTab(WidgetTester tester, RunVisitSection section) async { await tester.pumpAndSettle(); await tester.tap(tab); await tester.pumpAndSettle(); - if (section == RunVisitSection.session || - section == RunVisitSection.definition) { - final choice = find.descendant( - of: find.byKey(const Key('run-visit-more-switch')), - matching: find.text( - section == RunVisitSection.session ? 'Session' : 'Definition', - ), - ); - await tester.tap(choice); - await tester.pumpAndSettle(); - } } diff --git a/app/test/shell/shell_bar_test.dart b/app/test/shell/shell_bar_test.dart index d9734edb..329decdf 100644 --- a/app/test/shell/shell_bar_test.dart +++ b/app/test/shell/shell_bar_test.dart @@ -99,4 +99,23 @@ void main() { findsNothing, ); }); + + testWidgets('an open detail fills a phone screen without the tab bar', ( + tester, + ) async { + tester.view.physicalSize = const Size(390, 844); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); + Widget shell({required bool detail}) => MaterialApp( + home: AdaptiveShell( + destination: AppDestination.runs, + detailOpen: detail, + destinationBodies: {AppDestination.runs: (_) => const Text('runs')}, + ), + ); + await tester.pumpWidget(shell(detail: false)); + expect(find.byType(NavigationBar), findsOneWidget); + await tester.pumpWidget(shell(detail: true)); + expect(find.byType(NavigationBar), findsNothing); + }); }