feat(chat): keep the rail and chat list beside the open chat on wide windows
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import '../../shell/destination.dart';
|
||||
import '../../shell/detail_page.dart';
|
||||
import '../../shell/list_detail.dart';
|
||||
import '../../ui/adaptive/host.dart';
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../core/api_gateway.dart';
|
||||
@@ -165,7 +168,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The open chat is a real page above the main screen at every window width.
|
||||
/// On a phone the open chat is a real page above the main screen.
|
||||
final DetailPageHost _page = DetailPageHost();
|
||||
|
||||
@override
|
||||
@@ -200,11 +203,13 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final selected = _selected;
|
||||
// Chats are real Navigator pages at every width. Do not swap a conversation
|
||||
// into the home page and manually emulate Back on tablets/foldables.
|
||||
// A phone opens a chat as a real Navigator page with stock Back. A wide
|
||||
// window keeps the destination rail and the chat list beside the open
|
||||
// chat, which has no Back: another row, `/close` or a route change swaps it.
|
||||
final beside = showsListBesideDetail(context);
|
||||
_page.sync(
|
||||
context,
|
||||
selected: selected != null,
|
||||
selected: selected != null && !beside,
|
||||
destination: AppDestination.chat,
|
||||
onClosed: _back,
|
||||
builder: (context) => selected == null
|
||||
@@ -221,6 +226,41 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
activeSessionId: selected,
|
||||
publishShellBar: true,
|
||||
);
|
||||
return list;
|
||||
if (!beside) return list;
|
||||
return ListDetailPanes(
|
||||
list: list,
|
||||
detail: selected == null
|
||||
? const _NoChatSelected()
|
||||
: DetailPane(
|
||||
key: const ValueKey('chat-detail-pane'),
|
||||
destination: AppDestination.chat,
|
||||
implyBack: false,
|
||||
builder: (context) => _thread(selected, _back),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The open-chat pane before any chat is chosen.
|
||||
class _NoChatSelected extends StatelessWidget {
|
||||
const _NoChatSelected();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino = usesCupertinoHost(context);
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
cupertino
|
||||
? CupertinoIcons.chat_bubble_2
|
||||
: Icons.chat_bubble_outline,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
const Text('Select a chat to open it here.'),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,23 +86,32 @@ PageRoute<void> detailPageRoute(
|
||||
required AppDestination destination,
|
||||
required WidgetBuilder builder,
|
||||
}) {
|
||||
final page = _DetailPage(destination: destination, builder: builder);
|
||||
final page = DetailPane(destination: destination, builder: builder);
|
||||
return usesCupertinoHost(context)
|
||||
? CupertinoPageRoute<void>(builder: (_) => page)
|
||||
: MaterialPageRoute<void>(builder: (_) => page);
|
||||
}
|
||||
|
||||
class _DetailPage extends StatefulWidget {
|
||||
const _DetailPage({required this.destination, required this.builder});
|
||||
/// An open item's own bar over its content: what the content publishes
|
||||
/// through [ShellBar] (title and actions). As a pushed page it implies the
|
||||
/// platform's Back; inline beside a list ([implyBack] false) it shows none.
|
||||
class DetailPane extends StatefulWidget {
|
||||
const DetailPane({
|
||||
super.key,
|
||||
required this.destination,
|
||||
required this.builder,
|
||||
this.implyBack = true,
|
||||
});
|
||||
|
||||
final AppDestination destination;
|
||||
final WidgetBuilder builder;
|
||||
final bool implyBack;
|
||||
|
||||
@override
|
||||
State<_DetailPage> createState() => _DetailPageState();
|
||||
State<DetailPane> createState() => _DetailPaneState();
|
||||
}
|
||||
|
||||
class _DetailPageState extends State<_DetailPage> {
|
||||
class _DetailPaneState extends State<DetailPane> {
|
||||
final ShellBarRegistry _bar = ShellBarRegistry();
|
||||
|
||||
@override
|
||||
@@ -127,7 +136,7 @@ class _DetailPageState extends State<_DetailPage> {
|
||||
if (usesCupertinoHost(context)) {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
automaticallyImplyLeading: true,
|
||||
automaticallyImplyLeading: widget.implyBack,
|
||||
middle: Text(title),
|
||||
trailing: actions.isEmpty
|
||||
? null
|
||||
@@ -138,7 +147,7 @@ class _DetailPageState extends State<_DetailPage> {
|
||||
}
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
automaticallyImplyLeading: true,
|
||||
automaticallyImplyLeading: widget.implyBack,
|
||||
title: Text(title),
|
||||
actions: actions,
|
||||
),
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../ui/adaptive/host.dart';
|
||||
|
||||
/// At least this wide, a destination keeps its list beside the open item
|
||||
/// (with the destination rail) instead of pushing the item as its own page.
|
||||
const double kListDetailMinWidth = 600;
|
||||
|
||||
/// The list pane's share of a two-pane window, bounded so neither the rows
|
||||
/// nor the open item become unusably narrow.
|
||||
const double _listFraction = 0.36;
|
||||
const double _listMinWidth = 280;
|
||||
const double _listMaxWidth = 400;
|
||||
|
||||
/// Whether the window at [context] shows list and detail side by side.
|
||||
bool showsListBesideDetail(BuildContext context) =>
|
||||
MediaQuery.sizeOf(context).width >= kListDetailMinWidth;
|
||||
|
||||
/// A list beside its open item, split by the platform's own divider.
|
||||
class ListDetailPanes extends StatelessWidget {
|
||||
const ListDetailPanes({super.key, required this.list, required this.detail});
|
||||
|
||||
final Widget list;
|
||||
final Widget detail;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final divider = usesCupertinoHost(context)
|
||||
? Container(
|
||||
width: 1,
|
||||
color: CupertinoColors.separator.resolveFrom(context),
|
||||
)
|
||||
: const VerticalDivider(width: 1);
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final width = (constraints.maxWidth * _listFraction).clamp(
|
||||
_listMinWidth,
|
||||
_listMaxWidth,
|
||||
);
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
SizedBox(width: width, child: list),
|
||||
divider,
|
||||
Expanded(child: detail),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
# Wide Chat keeps rail and list beside the open chat
|
||||
|
||||
User request: on desktop, tablets and the unfolded Fold, opening a chat must not
|
||||
replace the whole screen; the destination bar/rail and the chat list stay visible.
|
||||
|
||||
## Behavior
|
||||
|
||||
- At least `kListDetailMinWidth` (600 logical px, `lib/shell/list_detail.dart`)
|
||||
Chat shows `ListDetailPanes`: the list (36% of the body, 280–400 px) beside the
|
||||
open chat, with the destination rail/sidebar still visible. Before a selection
|
||||
the detail pane says "Select a chat to open it here."
|
||||
- The open chat sits in a `DetailPane` (the former private detail-page frame in
|
||||
`lib/shell/detail_page.dart`, now shared) with its own bar (title, model, info)
|
||||
and **no Back**; the shell bar keeps the list's New chat/Refresh. Another row,
|
||||
`/close`, a destination or a route change swaps or clears it.
|
||||
- Narrower than 600 nothing changed: a chat is a pushed Navigator page with stock
|
||||
Back (f22afabd / cf784245).
|
||||
- Resizing across the threshold moves an open chat between the pane and a pushed
|
||||
page (`DetailPageHost.sync` follows the width).
|
||||
|
||||
## Open decision
|
||||
|
||||
With a chat open in the wide layout no page is pushed, and the router still
|
||||
excludes a selected chat from the root double-back (cf784245). Android system
|
||||
Back there therefore exits the app in one press. Not changed here because the
|
||||
user explicitly asked to remove chat Back interception; needs a decision.
|
||||
|
||||
## Evidence
|
||||
|
||||
- Tests: new `test/features/chat/chat_list_detail_test.dart` (1280 and 800 wide:
|
||||
rail, list, swap, no Back, no pushed route; 390: pushed page). Updated the 900-px
|
||||
deep-link test to two-pane expectations and pinned phone-path tests to 390 px.
|
||||
`flutter analyze` clean; full suite **1,862 tests pass**.
|
||||
- Browser: `tool/chat_list_detail_probe.mjs` on a loopback fixture,
|
||||
captures in `build/chat-list-detail-1280/` and `build/chat-list-detail-800/`.
|
||||
- Not deployed, no APK, no device verification.
|
||||
@@ -155,7 +155,7 @@ Future<void> replyHistory(
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets(
|
||||
'a /chat/s1 deep link renders that thread and Back returns to /chat ($cupertino)',
|
||||
'a wide /chat/s1 deep link shows that thread beside the list and route Back returns to /chat ($cupertino)',
|
||||
(tester) async {
|
||||
tester.view.physicalSize = const Size(900, 900);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
@@ -207,14 +207,21 @@ void main() {
|
||||
expect(find.text('1 tool'), findsOneWidget);
|
||||
expect(find.text('Kept behind a native disclosure.'), findsNothing);
|
||||
|
||||
// One shell bar only: the embedded list/thread adds no second one.
|
||||
// The shell bar stays over the list and rail; the open chat has its
|
||||
// own bar in its pane, with no Back: the list beside it is the way out.
|
||||
expect(find.byType(ChatSessionsScreen), findsOneWidget);
|
||||
expect(
|
||||
find.byType(NavigationRail),
|
||||
cupertino ? findsNothing : findsOneWidget,
|
||||
);
|
||||
if (cupertino) {
|
||||
expect(find.byType(CupertinoNavigationBar), findsOneWidget);
|
||||
expect(find.byType(CupertinoNavigationBar), findsNWidgets(2));
|
||||
expect(find.byType(AppBar), findsNothing);
|
||||
} else {
|
||||
expect(find.byType(AppBar), findsOneWidget);
|
||||
expect(find.byType(AppBar), findsNWidgets(2));
|
||||
expect(find.byType(CupertinoNavigationBar), findsNothing);
|
||||
}
|
||||
expect(findNativeBack(), findsNothing);
|
||||
|
||||
// A live frame updates the held thread.
|
||||
channel.incoming.add(
|
||||
@@ -233,16 +240,18 @@ void main() {
|
||||
await tester.pump();
|
||||
expect(find.text('A live line arrived.'), findsOneWidget);
|
||||
|
||||
// The open chat takes over the app bar: one Back there, and no
|
||||
// second header row under it.
|
||||
// The pane bar carries the thread's controls: no second header row.
|
||||
expect(find.byKey(const Key('chat-thread-header')), findsNothing);
|
||||
await tester.tap(findNativeBack());
|
||||
// A real Navigator pop finishes its native reverse transition.
|
||||
// Browser Back to /chat clears the open pane and keeps the list.
|
||||
await provider.didPushRouteInformation(
|
||||
RouteInformation(uri: Uri.parse('/chat')),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(provider.value.uri.path, '/chat');
|
||||
expect(find.byType(ChatThreadView), findsNothing);
|
||||
expect(find.byType(ChatSessionsScreen), findsOneWidget);
|
||||
expect(find.text('Wire chat'), findsOneWidget);
|
||||
expect(find.text('Select a chat to open it here.'), findsOneWidget);
|
||||
|
||||
// Browser Forward re-opens the same session through its route.
|
||||
await provider.didPushRouteInformation(
|
||||
|
||||
@@ -29,7 +29,9 @@ class _Gateway extends FakeChatGateway {
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final width in [390.0, 840.0]) {
|
||||
// Wide windows keep the chat beside its list instead of pushing a page; that
|
||||
// layout is covered by test/features/chat/chat_list_detail_test.dart.
|
||||
for (final width in [390.0]) {
|
||||
testWidgets(
|
||||
'list → chat → top → bottom → one system Back pops a real route at $width',
|
||||
(tester) async {
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/screen.dart';
|
||||
import 'package:pipelines_app/shell/adaptive_shell.dart';
|
||||
import 'package:pipelines_app/shell/destination.dart';
|
||||
|
||||
import '../../native_back.dart';
|
||||
import 'conversation/chat_thread_fixtures.dart';
|
||||
|
||||
class _Gateway extends FakeChatGateway {
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
||||
if (type == 'chat_sessions') {
|
||||
return Future.value({
|
||||
'chat_sessions': [
|
||||
{'id': 'a', 'title': 'First chat'},
|
||||
{'id': 'b', 'title': 'Second chat'},
|
||||
],
|
||||
});
|
||||
}
|
||||
if (type == 'chat_shells') return Future.value({'chat_shells': []});
|
||||
return super.call(type, fields);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _pumpShell(WidgetTester tester, Size size) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final gateway = _Gateway()..history = (_) async => chatPage(const []);
|
||||
addTearDown(gateway.close);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: AdaptiveShell(
|
||||
destination: AppDestination.chat,
|
||||
destinationBodies: {
|
||||
AppDestination.chat: (_) => ChatScreen(gateway: gateway),
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final size in [const Size(1280, 800), const Size(800, 830)]) {
|
||||
testWidgets('a wide window keeps the rail and list beside the open chat '
|
||||
'at $size', (tester) async {
|
||||
await _pumpShell(tester, size);
|
||||
expect(find.text('Select a chat to open it here.'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('First chat'));
|
||||
await tester.pumpAndSettle();
|
||||
final navigator = tester.state<NavigatorState>(find.byType(Navigator));
|
||||
expect(navigator.canPop(), isFalse, reason: 'No page covers the shell');
|
||||
expect(find.byType(NavigationRail), findsOneWidget);
|
||||
expect(find.byKey(const ValueKey('chat-thread-a')), findsOneWidget);
|
||||
expect(find.text('Second chat'), findsOneWidget);
|
||||
// The shell bar keeps the list's controls; the pane bar has the chat's
|
||||
// title and no Back.
|
||||
expect(find.byKey(const Key('chat-new-chat')), findsOneWidget);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(const ValueKey('chat-detail-pane')),
|
||||
matching: find.text('First chat'),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(findNativeBack(), findsNothing);
|
||||
|
||||
// Another row swaps the open chat in place.
|
||||
await tester.tap(find.text('Second chat').first);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const ValueKey('chat-thread-a')), findsNothing);
|
||||
expect(find.byKey(const ValueKey('chat-thread-b')), findsOneWidget);
|
||||
expect(navigator.canPop(), isFalse);
|
||||
|
||||
// The rail still switches destinations with a chat open.
|
||||
await tester.tap(find.text('Runs'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const ValueKey('chat-thread-b')), findsNothing);
|
||||
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('a phone pushes the open chat as its own page', (tester) async {
|
||||
await _pumpShell(tester, const Size(390, 844));
|
||||
expect(find.text('Select a chat to open it here.'), findsNothing);
|
||||
|
||||
await tester.tap(find.text('First chat'));
|
||||
await tester.pumpAndSettle();
|
||||
final navigator = tester.state<NavigatorState>(find.byType(Navigator));
|
||||
expect(navigator.canPop(), isTrue);
|
||||
expect(findNativeBack(), findsOneWidget);
|
||||
expect(find.byType(NavigationBar), findsNothing);
|
||||
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
}
|
||||
@@ -62,6 +62,10 @@ Future<void> _pumpScreen(
|
||||
_ScreenGateway gateway, {
|
||||
String? initialSessionId,
|
||||
}) async {
|
||||
// The phone layout: an open chat is its own page with the native Back.
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
// Captures the wide Chat list/detail layout against a loopback fixture, never operator data.
|
||||
// PROBE_WIDTH=1280 PROBE_HEIGHT=800 node tool/chat_list_detail_probe.mjs <web-build> <out>
|
||||
import assert from 'node:assert/strict';
|
||||
import { mkdir, mkdtemp, writeFile } from 'node:fs/promises';
|
||||
import { once } from 'node:events';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join, resolve } from 'node:path';
|
||||
import { startFixture } from './runs_probe_server.mjs';
|
||||
import { launchChrome, waitForPort, waitForPage, connect, sleep } from './pipelines_probe_cdp_lib.mjs';
|
||||
import { axNodes, enableSemantics, waitFor, capture } from './pipelines_probe_cdp_input.mjs';
|
||||
|
||||
const width = Number(process.env.PROBE_WIDTH ?? 1280);
|
||||
const height = Number(process.env.PROBE_HEIGHT ?? 800);
|
||||
const messages = Array.from({ length: 6 }, (_, i) => ({
|
||||
id: `m${i}`,
|
||||
role: i % 2 ? 'assistant' : 'user',
|
||||
parts: [{ id: `p${i}`, type: 'text', text: `Recorded fixture message ${i}.` }],
|
||||
}));
|
||||
const output = resolve(process.argv[3] ?? 'build/chat-list-detail');
|
||||
await mkdir(output, { recursive: true });
|
||||
const fixture = await startFixture({ root: resolve(process.argv[2]), chatMessages: messages });
|
||||
const profile = await mkdtemp(join(tmpdir(), 'chat-list-detail-'));
|
||||
const chrome = launchChrome('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', profile, 'about:blank');
|
||||
const log = { width, height, checks: [], captures: [] };
|
||||
let c;
|
||||
const named = async (pattern) => (await axNodes(c)).filter(n => pattern.test(n.name?.value ?? ''));
|
||||
try {
|
||||
c = await connect((await waitForPage(await waitForPort(join(profile, 'DevToolsActivePort')))).webSocketDebuggerUrl);
|
||||
await c.send('Page.enable');
|
||||
await c.send('Emulation.setDeviceMetricsOverride', { width, height, deviceScaleFactor: 1, mobile: false });
|
||||
await c.send('Page.navigate', { url: fixture.url + '/chat' });
|
||||
assert.ok(await waitFor(() => c.evaluate("Boolean(document.querySelector('flt-semantics-placeholder'))"), 30000));
|
||||
await enableSemantics(c);
|
||||
assert.ok(await waitFor(async () => (await named(/Select a chat/)).length > 0, 30000), 'empty detail pane');
|
||||
log.checks.push('empty pane beside list');
|
||||
await sleep(500);
|
||||
await capture(c, output, log, 'list-empty-pane');
|
||||
|
||||
const row = (await named(/^Probe conversation/)).find(n => n.backendDOMNodeId);
|
||||
assert.ok(row, 'chat list row');
|
||||
const { model } = await c.send('DOM.getBoxModel', { backendNodeId: row.backendDOMNodeId });
|
||||
const [x1, y1, , , x3, y3] = model.content;
|
||||
await c.send('Input.dispatchMouseEvent', { type: 'mousePressed', x: (x1 + x3) / 2, y: (y1 + y3) / 2, button: 'left', clickCount: 1 });
|
||||
await c.send('Input.dispatchMouseEvent', { type: 'mouseReleased', x: (x1 + x3) / 2, y: (y1 + y3) / 2, button: 'left', clickCount: 1 });
|
||||
assert.ok(await waitFor(async () => (await named(/Recorded fixture message 5/)).length > 0, 30000), 'open chat transcript');
|
||||
await sleep(800);
|
||||
// The rail, the list and the open chat are all on screen; nothing offers Back.
|
||||
for (const label of ['Pipelines', 'Runs', 'Settings']) {
|
||||
assert.ok((await named(new RegExp(`^${label}`))).length > 0, `rail ${label}`);
|
||||
}
|
||||
assert.ok((await named(/^Probe conversation/)).length > 0, 'list stays beside the chat');
|
||||
assert.equal((await named(/^Back(\s|$)/)).length, 0, 'no Back in the two-pane layout');
|
||||
log.path = await c.evaluate('location.pathname');
|
||||
log.checks.push('rail, list and open chat visible together; no Back');
|
||||
await capture(c, output, log, 'list-open-chat');
|
||||
console.log(JSON.stringify(log, null, 2));
|
||||
} catch (error) {
|
||||
if (c) {
|
||||
await capture(c, output, log, 'failure');
|
||||
await writeFile(join(output, 'failure-ax.json'), JSON.stringify(await axNodes(c), null, 2));
|
||||
}
|
||||
throw error;
|
||||
} finally {
|
||||
await writeFile(join(output, 'result.json'), JSON.stringify(log, null, 2));
|
||||
c?.close(); const exited = once(chrome, 'exit'); chrome.kill(); await exited;
|
||||
await fixture.close();
|
||||
}
|
||||
Reference in New Issue
Block a user