From 41a9e99da8c4d4862f990e4bdbf6b078afb8a12b Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Sat, 31 Oct 2026 16:30:05 +0000 Subject: [PATCH] fix(app): selecting another item closes the previous item's pane page On a wide split window a run's stage page (or an artifact, a file) opens inside the detail pane's own navigator. Selecting another run kept that page on top, so the pane still showed the old stage. ListDetailPanes now takes the selected item's identity (run, chat or pipeline id) and the pane navigator pops back to the item when it changes. --- app/lib/features/chat/screen.dart | 1 + app/lib/features/pipelines/screen.dart | 1 + app/lib/features/runs/screen.dart | 1 + app/lib/shell/detail_pane_navigator.dart | 17 ++++- app/lib/shell/list_detail.dart | 16 ++++- app/test/shell/detail_pane_reset_test.dart | 74 ++++++++++++++++++++++ 6 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 app/test/shell/detail_pane_reset_test.dart diff --git a/app/lib/features/chat/screen.dart b/app/lib/features/chat/screen.dart index c8049662..559b4b4f 100644 --- a/app/lib/features/chat/screen.dart +++ b/app/lib/features/chat/screen.dart @@ -256,6 +256,7 @@ class _ChatScreenState extends State { if (!beside) return list; return ListDetailPanes( list: list, + detailIdentity: selected, detail: selected == null ? const EmptyDetailPane( destination: AppDestination.chat, diff --git a/app/lib/features/pipelines/screen.dart b/app/lib/features/pipelines/screen.dart index 174920af..cfc8d093 100644 --- a/app/lib/features/pipelines/screen.dart +++ b/app/lib/features/pipelines/screen.dart @@ -255,6 +255,7 @@ class _PipelinesScreenState extends State { list: ContentWidth( child: PipelineListPanel(controller: _controller), ), + detailIdentity: _controller.selectedId, detail: _controller.hasSelection ? DetailPane( key: const ValueKey('pipeline-detail-pane'), diff --git a/app/lib/features/runs/screen.dart b/app/lib/features/runs/screen.dart index 805044a3..d0784ea7 100644 --- a/app/lib/features/runs/screen.dart +++ b/app/lib/features/runs/screen.dart @@ -277,6 +277,7 @@ class _RunsScreenState extends State { if (narrow) return list; return ListDetailPanes( list: list, + detailIdentity: controller.selectedRunId, detail: selected ? DetailPane( key: const ValueKey('run-detail-pane'), diff --git a/app/lib/shell/detail_pane_navigator.dart b/app/lib/shell/detail_pane_navigator.dart index 62e87203..ede2e21f 100644 --- a/app/lib/shell/detail_pane_navigator.dart +++ b/app/lib/shell/detail_pane_navigator.dart @@ -12,12 +12,17 @@ import '../ui/adaptive/host.dart'; /// /// The item is this navigator's first page under a fixed key, so a rebuilt /// item updates in place and is never remounted. The system Back pops a page -/// pushed here before it leaves the item. +/// pushed here before it leaves the item. Opening a different item +/// ([identity] changes) closes any page the previous item had pushed, so the +/// pane shows the newly selected item. class DetailPaneNavigator extends StatefulWidget { - const DetailPaneNavigator({super.key, required this.child}); + const DetailPaneNavigator({super.key, required this.child, this.identity}); final Widget child; + /// Which item the pane shows (a run, chat or pipeline id). + final Object? identity; + @override State createState() => _DetailPaneNavigatorState(); } @@ -26,6 +31,14 @@ class _DetailPaneNavigatorState extends State { final GlobalKey _navigator = GlobalKey(); static const _rootKey = ValueKey('list-detail-root'); + @override + void didUpdateWidget(covariant DetailPaneNavigator oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.identity != widget.identity) { + _navigator.currentState?.popUntil((route) => route.isFirst); + } + } + @override Widget build(BuildContext context) { final Page root = usesCupertinoHost(context) diff --git a/app/lib/shell/list_detail.dart b/app/lib/shell/list_detail.dart index 863a30c1..b3ab2f80 100644 --- a/app/lib/shell/list_detail.dart +++ b/app/lib/shell/list_detail.dart @@ -110,11 +110,20 @@ class ListPaneWidth extends StatelessWidget { /// composer) float above the shell's bar, never on it, and its content clears /// both. Pages the item opens stay in its pane ([DetailPaneNavigator]). class ListDetailPanes extends StatelessWidget { - const ListDetailPanes({super.key, required this.list, required this.detail}); + const ListDetailPanes({ + super.key, + required this.list, + required this.detail, + this.detailIdentity, + }); final Widget list; final Widget detail; + /// Which item [detail] shows; selecting another item closes any page the + /// previous one opened in its pane. + final Object? detailIdentity; + @override Widget build(BuildContext context) { final divider = usesCupertinoHost(context) @@ -151,7 +160,10 @@ class ListDetailPanes extends StatelessWidget { ), child: PageTabsEdge( edge: FloatingBarEdge.bottom, - child: DetailPaneNavigator(child: body), + child: DetailPaneNavigator( + identity: detailIdentity, + child: body, + ), ), ); // The tab bar sits over the detail pane, never the list (the diff --git a/app/test/shell/detail_pane_reset_test.dart b/app/test/shell/detail_pane_reset_test.dart new file mode 100644 index 00000000..becdb31f --- /dev/null +++ b/app/test/shell/detail_pane_reset_test.dart @@ -0,0 +1,74 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/shell/adaptive_shell.dart'; +import 'package:pipelines_app/shell/destination.dart'; +import 'package:pipelines_app/shell/list_detail.dart'; + +/// On a wide split window a page an item opened in its pane (a run's stage +/// page) closes when another item is selected, so the pane shows the newly +/// selected item instead of the old item's page. +void main() { + for (final cupertino in [false, true]) { + testWidgets('selecting another item closes the previous item\'s page ' + '(${cupertino ? 'cupertino' : 'material'})', (tester) async { + tester.view.physicalSize = const Size(1200, 800); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); + final selected = ValueNotifier(1); + addTearDown(selected.dispose); + + Widget detail(int id) => Builder( + builder: (context) => Center( + child: GestureDetector( + key: const Key('open-page'), + onTap: () => Navigator.of(context).push( + PageRouteBuilder( + pageBuilder: (_, _, _) => Text('page of item $id'), + ), + ), + child: Text('item $id'), + ), + ), + ); + + final shell = AdaptiveShell( + cupertino: cupertino, + destination: AppDestination.runs, + destinationBodies: { + AppDestination.runs: (_) => ValueListenableBuilder( + valueListenable: selected, + builder: (_, id, _) => ListDetailPanes( + list: const Text('list'), + detailIdentity: id, + detail: detail(id), + ), + ), + }, + ); + await tester.pumpWidget( + cupertino + ? CupertinoApp(home: shell) + : MaterialApp( + theme: ThemeData(platform: TargetPlatform.android), + home: shell, + ), + ); + await tester.pumpAndSettle(); + + await tester.tap(find.byKey(const Key('open-page'))); + await tester.pumpAndSettle(); + expect(find.text('page of item 1'), findsOneWidget); + + // The same item rebuilt keeps its page open. + selected.value = 1; + await tester.pumpAndSettle(); + expect(find.text('page of item 1'), findsOneWidget); + + selected.value = 2; + await tester.pumpAndSettle(); + expect(find.text('page of item 1'), findsNothing); + expect(find.text('item 2'), findsOneWidget); + }); + } +}