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.
This commit is contained in:
@@ -256,6 +256,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
if (!beside) return list;
|
||||
return ListDetailPanes(
|
||||
list: list,
|
||||
detailIdentity: selected,
|
||||
detail: selected == null
|
||||
? const EmptyDetailPane(
|
||||
destination: AppDestination.chat,
|
||||
|
||||
@@ -255,6 +255,7 @@ class _PipelinesScreenState extends State<PipelinesScreen> {
|
||||
list: ContentWidth(
|
||||
child: PipelineListPanel(controller: _controller),
|
||||
),
|
||||
detailIdentity: _controller.selectedId,
|
||||
detail: _controller.hasSelection
|
||||
? DetailPane(
|
||||
key: const ValueKey('pipeline-detail-pane'),
|
||||
|
||||
@@ -277,6 +277,7 @@ class _RunsScreenState extends State<RunsScreen> {
|
||||
if (narrow) return list;
|
||||
return ListDetailPanes(
|
||||
list: list,
|
||||
detailIdentity: controller.selectedRunId,
|
||||
detail: selected
|
||||
? DetailPane(
|
||||
key: const ValueKey('run-detail-pane'),
|
||||
|
||||
@@ -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<DetailPaneNavigator> createState() => _DetailPaneNavigatorState();
|
||||
}
|
||||
@@ -26,6 +31,14 @@ class _DetailPaneNavigatorState extends State<DetailPaneNavigator> {
|
||||
final GlobalKey<NavigatorState> _navigator = GlobalKey();
|
||||
static const _rootKey = ValueKey<String>('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<void> root = usesCupertinoHost(context)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<int>(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<void>(
|
||||
pageBuilder: (_, _, _) => Text('page of item $id'),
|
||||
),
|
||||
),
|
||||
child: Text('item $id'),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final shell = AdaptiveShell(
|
||||
cupertino: cupertino,
|
||||
destination: AppDestination.runs,
|
||||
destinationBodies: {
|
||||
AppDestination.runs: (_) => ValueListenableBuilder<int>(
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user