From ce59b12702d7c9154cf39906a6a94a6462f8844a Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Fri, 6 Nov 2026 17:56:22 +0000 Subject: [PATCH] Add session menu actions for opening split chats --- .../chat/ui/sessions/chat_sessions_body.dart | 8 ++ .../ui/sessions/chat_sessions_screen.dart | 28 +++- .../chat/ui/sessions/session_actions.dart | 25 +++- .../ui/sessions/session_list_cupertino.dart | 6 + .../chat/ui/sessions/session_list_items.dart | 4 + .../ui/sessions/session_list_material.dart | 6 + .../chat/ui/sessions/session_row_content.dart | 6 + .../chat/ui/sessions/session_row_memo.dart | 8 ++ app/notes/chat-split-session-menu.md | 19 +++ .../ui/sessions/chat_split_menu_test.dart | 133 ++++++++++++++++++ 10 files changed, 241 insertions(+), 2 deletions(-) create mode 100644 app/notes/chat-split-session-menu.md create mode 100644 app/test/features/chat/ui/sessions/chat_split_menu_test.dart diff --git a/app/lib/features/chat/ui/sessions/chat_sessions_body.dart b/app/lib/features/chat/ui/sessions/chat_sessions_body.dart index 5e485c8a..8ac0be32 100644 --- a/app/lib/features/chat/ui/sessions/chat_sessions_body.dart +++ b/app/lib/features/chat/ui/sessions/chat_sessions_body.dart @@ -32,6 +32,8 @@ class ChatSessionsBody extends StatelessWidget { required this.loading, required this.error, required this.onOpen, + this.onOpenBeside, + this.onOpenBelow, required this.onRename, required this.onClose, required this.onReopen, @@ -53,6 +55,8 @@ class ChatSessionsBody extends StatelessWidget { final bool loading; final String? error; final ValueChanged onOpen; + final ValueChanged? onOpenBeside; + final ValueChanged? onOpenBelow; final ValueChanged onRename; final ValueChanged onClose; final ValueChanged onReopen; @@ -85,6 +89,8 @@ class ChatSessionsBody extends StatelessWidget { emptyMessage: visible.isEmpty ? emptyMessage : null, duplicateTitles: duplicateTitles, onOpen: onOpen, + onOpenBeside: onOpenBeside, + onOpenBelow: onOpenBelow, onRename: onRename, onClose: onClose, onReopen: onReopen, @@ -104,6 +110,8 @@ class ChatSessionsBody extends StatelessWidget { emptyMessage: visible.isEmpty ? emptyMessage : null, duplicateTitles: duplicateTitles, onOpen: onOpen, + onOpenBeside: onOpenBeside, + onOpenBelow: onOpenBelow, onRename: onRename, onClose: onClose, onReopen: onReopen, diff --git a/app/lib/features/chat/ui/sessions/chat_sessions_screen.dart b/app/lib/features/chat/ui/sessions/chat_sessions_screen.dart index 3f9decb8..abefa84b 100644 --- a/app/lib/features/chat/ui/sessions/chat_sessions_screen.dart +++ b/app/lib/features/chat/ui/sessions/chat_sessions_screen.dart @@ -28,6 +28,8 @@ class ChatSessionsScreen extends StatefulWidget { super.key, required this.gateway, required this.onOpen, + this.onOpenBeside, + this.onOpenBelow, this.onShortcutOpen, this.embedded = false, this.syncToken = 0, @@ -41,6 +43,10 @@ class ChatSessionsScreen extends StatefulWidget { final ApiGateway gateway; final void Function(JsonMap session) onOpen; + /// Optional split-pane actions; absent when the host cannot offer a split. + final ValueChanged? onOpenBeside; + final ValueChanged? onOpenBelow; + /// Opens a row the shell's Ctrl+1…Ctrl+9 named, so the destination can put /// the keyboard in its composer; null opens it like a tap ([onOpen]). final void Function(JsonMap session)? onShortcutOpen; @@ -186,9 +192,23 @@ class _ChatSessionsScreenState extends State { if (session != null && mounted) widget.onOpen(session); } - void _open(JsonMap session, {bool byShortcut = false}) { + void _markOpened(JsonMap session) { _markedActiveSessionId = _sessionId(session); unawaited(_controller.markOpened(session)); + } + + void _openBeside(JsonMap session) { + _markOpened(session); + widget.onOpenBeside?.call(session); + } + + void _openBelow(JsonMap session) { + _markOpened(session); + widget.onOpenBelow?.call(session); + } + + void _open(JsonMap session, {bool byShortcut = false}) { + _markOpened(session); final open = byShortcut ? widget.onShortcutOpen : null; (open ?? widget.onOpen)(session); } @@ -269,6 +289,12 @@ class _ChatSessionsScreenState extends State { loading: _controller.loading, error: _controller.error, onOpen: _open, + onOpenBeside: widget.onOpenBeside == null + ? null + : _openBeside, + onOpenBelow: widget.onOpenBelow == null + ? null + : _openBelow, onRename: _rename, onClose: _close, onReopen: _reopen, diff --git a/app/lib/features/chat/ui/sessions/session_actions.dart b/app/lib/features/chat/ui/sessions/session_actions.dart index f792eebd..47a7c843 100644 --- a/app/lib/features/chat/ui/sessions/session_actions.dart +++ b/app/lib/features/chat/ui/sessions/session_actions.dart @@ -7,7 +7,16 @@ import 'chat_adaptive.dart'; import 'session_row_style.dart'; import '../../../../ui/layout/app_overflow_menu.dart'; -enum SessionAction { star, color, rename, close, reopen, hide } +enum SessionAction { + openBeside, + openBelow, + star, + color, + rename, + close, + reopen, + hide, +} /// The close confirmation's body, matching the web client's explanation. String closeChatConfirmation(String title) => @@ -22,11 +31,15 @@ class SessionActionsButton extends StatelessWidget { required this.session, required this.onSelected, this.duplicateTitles = const {}, + this.allowOpenBeside = false, + this.allowOpenBelow = false, }); final JsonMap session; final ValueChanged onSelected; final Set duplicateTitles; + final bool allowOpenBeside; + final bool allowOpenBelow; @override Widget build(BuildContext context) { @@ -35,6 +48,16 @@ class SessionActionsButton extends StatelessWidget { label: sessionActionsLabel(session, duplicateTitles), sheetTitle: chatSessionTitle(session), actions: [ + if (allowOpenBeside) + const AppMenuAction( + value: SessionAction.openBeside, + label: 'Open to the right', + ), + if (allowOpenBelow) + const AppMenuAction( + value: SessionAction.openBelow, + label: 'Open below', + ), for (final item in _items(session)) AppMenuAction(value: item.action, label: item.label), ], diff --git a/app/lib/features/chat/ui/sessions/session_list_cupertino.dart b/app/lib/features/chat/ui/sessions/session_list_cupertino.dart index 66c77225..b235841f 100644 --- a/app/lib/features/chat/ui/sessions/session_list_cupertino.dart +++ b/app/lib/features/chat/ui/sessions/session_list_cupertino.dart @@ -13,6 +13,8 @@ class CupertinoSessionList extends StatelessWidget { required this.emptyMessage, required this.duplicateTitles, required this.onOpen, + this.onOpenBeside, + this.onOpenBelow, required this.onRename, required this.onClose, required this.onReopen, @@ -33,6 +35,8 @@ class CupertinoSessionList extends StatelessWidget { final String? emptyMessage; final Set duplicateTitles; final ValueChanged onOpen; + final ValueChanged? onOpenBeside; + final ValueChanged? onOpenBelow; final ValueChanged onRename; final ValueChanged onClose; final ValueChanged onReopen; @@ -84,6 +88,8 @@ class CupertinoSessionList extends StatelessWidget { duplicateTitles: duplicateTitles, isUnseen: isUnseen, onOpen: onOpen, + onOpenBeside: onOpenBeside, + onOpenBelow: onOpenBelow, onStar: onStar, onColor: onColor, onRename: onRename, diff --git a/app/lib/features/chat/ui/sessions/session_list_items.dart b/app/lib/features/chat/ui/sessions/session_list_items.dart index d856ea71..75b93894 100644 --- a/app/lib/features/chat/ui/sessions/session_list_items.dart +++ b/app/lib/features/chat/ui/sessions/session_list_items.dart @@ -86,6 +86,8 @@ SessionListItem chatSessionRowItem( required Set duplicateTitles, required bool Function(JsonMap) isUnseen, required ValueChanged onOpen, + ValueChanged? onOpenBeside, + ValueChanged? onOpenBelow, required ValueChanged onStar, required ValueChanged? onColor, required ValueChanged onRename, @@ -103,6 +105,8 @@ SessionListItem chatSessionRowItem( unseen: isUnseen(session), divider: divider, onOpen: onOpen, + onOpenBeside: onOpenBeside, + onOpenBelow: onOpenBelow, onStar: onStar, onColor: onColor, onRename: onRename, diff --git a/app/lib/features/chat/ui/sessions/session_list_material.dart b/app/lib/features/chat/ui/sessions/session_list_material.dart index 1857e382..ddc35bde 100644 --- a/app/lib/features/chat/ui/sessions/session_list_material.dart +++ b/app/lib/features/chat/ui/sessions/session_list_material.dart @@ -12,6 +12,8 @@ class MaterialSessionList extends StatelessWidget { required this.emptyMessage, required this.duplicateTitles, required this.onOpen, + this.onOpenBeside, + this.onOpenBelow, required this.onRename, required this.onClose, required this.onReopen, @@ -32,6 +34,8 @@ class MaterialSessionList extends StatelessWidget { final String? emptyMessage; final Set duplicateTitles; final ValueChanged onOpen; + final ValueChanged? onOpenBeside; + final ValueChanged? onOpenBelow; final ValueChanged onRename; final ValueChanged onClose; final ValueChanged onReopen; @@ -100,6 +104,8 @@ class MaterialSessionList extends StatelessWidget { duplicateTitles: duplicateTitles, isUnseen: isUnseen, onOpen: onOpen, + onOpenBeside: onOpenBeside, + onOpenBelow: onOpenBelow, onStar: onStar, onColor: onColor, onRename: onRename, diff --git a/app/lib/features/chat/ui/sessions/session_row_content.dart b/app/lib/features/chat/ui/sessions/session_row_content.dart index 4e25f709..f85097d2 100644 --- a/app/lib/features/chat/ui/sessions/session_row_content.dart +++ b/app/lib/features/chat/ui/sessions/session_row_content.dart @@ -29,6 +29,8 @@ class ChatSessionRow extends StatelessWidget { super.key, required this.session, required this.onOpen, + this.onOpenBeside, + this.onOpenBelow, required this.onAction, this.selected = false, this.unseen = false, @@ -39,6 +41,8 @@ class ChatSessionRow extends StatelessWidget { final JsonMap session; final ValueChanged onOpen; + final ValueChanged? onOpenBeside; + final ValueChanged? onOpenBelow; final VoidCallback? onLongPress; final ValueChanged onAction; final bool selected; @@ -122,6 +126,8 @@ class ChatSessionRow extends StatelessWidget { session: session, duplicateTitles: duplicateTitles, onSelected: onAction, + allowOpenBeside: onOpenBeside != null, + allowOpenBelow: onOpenBelow != null, ), ); } diff --git a/app/lib/features/chat/ui/sessions/session_row_memo.dart b/app/lib/features/chat/ui/sessions/session_row_memo.dart index f35a9f7e..3c88958a 100644 --- a/app/lib/features/chat/ui/sessions/session_row_memo.dart +++ b/app/lib/features/chat/ui/sessions/session_row_memo.dart @@ -18,6 +18,8 @@ Widget memoChatSessionRow({ required bool unseen, required bool divider, required ValueChanged onOpen, + ValueChanged? onOpenBeside, + ValueChanged? onOpenBelow, required ValueChanged onStar, required ValueChanged? onColor, required ValueChanged onRename, @@ -34,6 +36,8 @@ Widget memoChatSessionRow({ unseen, divider, onOpen, + onOpenBeside, + onOpenBelow, onStar, onColor, onRename, @@ -48,9 +52,13 @@ Widget memoChatSessionRow({ unseen: unseen, divider: divider, onOpen: onOpen, + onOpenBeside: onOpenBeside, + onOpenBelow: onOpenBelow, // A long-press is the touch way to the colour, the row's quick mark. onLongPress: onColor == null ? null : () => onColor(session), onAction: (action) => switch (action) { + SessionAction.openBeside => onOpenBeside?.call(session), + SessionAction.openBelow => onOpenBelow?.call(session), SessionAction.star => onStar(session), SessionAction.color => onColor?.call(session), SessionAction.rename => onRename(session), diff --git a/app/notes/chat-split-session-menu.md b/app/notes/chat-split-session-menu.md new file mode 100644 index 00000000..d2bf4b0c --- /dev/null +++ b/app/notes/chat-split-session-menu.md @@ -0,0 +1,19 @@ +# Split-chat session menu + +`ChatSessionsScreen` accepts optional `onOpenBeside` and `onOpenBelow` +`ValueChanged` callbacks. They are forwarded through both native list +hosts and included in row memoization. Each provided callback adds its native +More-menu choice: **Open to the right** or **Open below**. An absent callback +hides that choice, so the workspace host controls split availability. + +The selected existing session is passed unchanged. Split opening follows the +same device-local read/unread bookkeeping as ordinary opening; it does not +create, close, reopen or mutate a backend session. Ordinary row opening remains +unchanged. Capability changes on mounted rows invalidate the memoized menu. + +Checks: bounded analysis clean; all 126 session UI tests passed through the +memory watchdog (peak 1432 MB, 13s). Eight new menu tests exercise both Material +and Cupertino selection, exact selected session/callback, no unrelated backend +requests, absent capabilities, changing direction availability on mounted rows, +and normal opening. Full-app rendered split acceptance belongs to the manager's +workspace integration; no browser or device acceptance is claimed here. diff --git a/app/test/features/chat/ui/sessions/chat_split_menu_test.dart b/app/test/features/chat/ui/sessions/chat_split_menu_test.dart new file mode 100644 index 00000000..91316e1c --- /dev/null +++ b/app/test/features/chat/ui/sessions/chat_split_menu_test.dart @@ -0,0 +1,133 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/core/api_gateway.dart'; +import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_screen.dart'; + +import 'chat_test_harness.dart'; +import 'fake_chat_gateway.dart'; + +void main() { + for (final cupertino in [false, true]) { + for (final beside in [false, true]) { + testWidgets( + '${cupertino ? 'Cupertino' : 'Material'} split menu passes selected chat ${beside ? 'beside' : 'below'}', + (tester) async { + final gateway = FakeChatGateway() + ..sessionsReply = {'chat_sessions': sampleSessions()}; + addTearDown(gateway.pushed.close); + final opened = []; + final right = []; + final below = []; + final screen = ChatSessionsScreen( + gateway: gateway, + onOpen: opened.add, + onOpenBeside: right.add, + onOpenBelow: below.add, + localStore: MemoryChatSessionLocalStore(), + ); + await tester.pumpWidget( + cupertino ? CupertinoApp(home: screen) : MaterialApp(home: screen), + ); + await tester.pumpAndSettle(); + await tester.tap(find.byKey(const Key('chat-actions-s2'))); + await tester.pumpAndSettle(); + expect(find.text('Open to the right'), findsOneWidget); + expect(find.text('Open below'), findsOneWidget); + if (cupertino) { + expect(find.byType(CupertinoActionSheet), findsOneWidget); + } + await tester.tap( + find.text(beside ? 'Open to the right' : 'Open below'), + ); + await tester.pumpAndSettle(); + expect(opened, isEmpty); + expect(beside ? right : below, hasLength(1)); + expect((beside ? right : below).single['id'], 's2'); + expect((beside ? right : below).single['title'], 'Open chat'); + expect(beside ? below : right, isEmpty); + expect( + gateway.calls.where((call) => call.type != 'chat_sessions'), + isEmpty, + ); + expect(find.text('Open to the right'), findsNothing); + }, + ); + } + + testWidgets( + '${cupertino ? 'Cupertino' : 'Material'} updates available directions on mounted rows', + (tester) async { + final gateway = FakeChatGateway() + ..sessionsReply = {'chat_sessions': sampleSessions()}; + addTearDown(gateway.pushed.close); + final right = []; + final below = []; + Future show({required bool horizontal}) async { + final screen = ChatSessionsScreen( + gateway: gateway, + onOpen: (_) {}, + onOpenBeside: horizontal ? right.add : null, + onOpenBelow: horizontal ? null : below.add, + localStore: MemoryChatSessionLocalStore(), + ); + await tester.pumpWidget( + cupertino ? CupertinoApp(home: screen) : MaterialApp(home: screen), + ); + await tester.pumpAndSettle(); + await tester.tap(find.byKey(const Key('chat-actions-s2'))); + await tester.pumpAndSettle(); + } + + await show(horizontal: true); + expect(find.text('Open to the right'), findsOneWidget); + expect(find.text('Open below'), findsNothing); + if (cupertino) { + await tester.tap(find.text('Cancel')); + } else { + await tester.tapAt(const Offset(5, 5)); + } + await tester.pumpAndSettle(); + await show(horizontal: false); + expect(find.text('Open to the right'), findsNothing); + expect(find.text('Open below'), findsOneWidget); + await tester.tap(find.text('Open below')); + await tester.pumpAndSettle(); + expect(right, isEmpty); + expect(below.single['id'], 's2'); + }, + ); + + testWidgets( + '${cupertino ? 'Cupertino' : 'Material'} hides unavailable split choices and keeps row open', + (tester) async { + final gateway = FakeChatGateway() + ..sessionsReply = {'chat_sessions': sampleSessions()}; + addTearDown(gateway.pushed.close); + final opened = []; + final screen = ChatSessionsScreen( + gateway: gateway, + onOpen: opened.add, + localStore: MemoryChatSessionLocalStore(), + ); + await tester.pumpWidget( + cupertino ? CupertinoApp(home: screen) : MaterialApp(home: screen), + ); + await tester.pumpAndSettle(); + await tester.tap(find.byKey(const Key('chat-actions-s2'))); + await tester.pumpAndSettle(); + expect(find.text('Open to the right'), findsNothing); + expect(find.text('Open below'), findsNothing); + if (cupertino) { + await tester.tap(find.text('Cancel')); + } else { + await tester.tapAt(const Offset(5, 5)); + } + await tester.pumpAndSettle(); + await tester.tap(find.byKey(const Key('chat-row-s2'))); + await tester.pumpAndSettle(); + expect(opened.single['id'], 's2'); + }, + ); + } +}