Integrate split chat menu callbacks
This commit is contained in:
@@ -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<JsonMap> onOpen;
|
||||
final ValueChanged<JsonMap>? onOpenBeside;
|
||||
final ValueChanged<JsonMap>? onOpenBelow;
|
||||
final ValueChanged<JsonMap> onRename;
|
||||
final ValueChanged<JsonMap> onClose;
|
||||
final ValueChanged<JsonMap> 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,
|
||||
|
||||
@@ -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<JsonMap>? onOpenBeside;
|
||||
final ValueChanged<JsonMap>? 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<ChatSessionsScreen> {
|
||||
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<ChatSessionsScreen> {
|
||||
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,
|
||||
|
||||
@@ -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<SessionAction> onSelected;
|
||||
final Set<String> 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),
|
||||
],
|
||||
|
||||
@@ -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<String> duplicateTitles;
|
||||
final ValueChanged<JsonMap> onOpen;
|
||||
final ValueChanged<JsonMap>? onOpenBeside;
|
||||
final ValueChanged<JsonMap>? onOpenBelow;
|
||||
final ValueChanged<JsonMap> onRename;
|
||||
final ValueChanged<JsonMap> onClose;
|
||||
final ValueChanged<JsonMap> 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,
|
||||
|
||||
@@ -86,6 +86,8 @@ SessionListItem chatSessionRowItem(
|
||||
required Set<String> duplicateTitles,
|
||||
required bool Function(JsonMap) isUnseen,
|
||||
required ValueChanged<JsonMap> onOpen,
|
||||
ValueChanged<JsonMap>? onOpenBeside,
|
||||
ValueChanged<JsonMap>? onOpenBelow,
|
||||
required ValueChanged<JsonMap> onStar,
|
||||
required ValueChanged<JsonMap>? onColor,
|
||||
required ValueChanged<JsonMap> onRename,
|
||||
@@ -103,6 +105,8 @@ SessionListItem chatSessionRowItem(
|
||||
unseen: isUnseen(session),
|
||||
divider: divider,
|
||||
onOpen: onOpen,
|
||||
onOpenBeside: onOpenBeside,
|
||||
onOpenBelow: onOpenBelow,
|
||||
onStar: onStar,
|
||||
onColor: onColor,
|
||||
onRename: onRename,
|
||||
|
||||
@@ -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<String> duplicateTitles;
|
||||
final ValueChanged<JsonMap> onOpen;
|
||||
final ValueChanged<JsonMap>? onOpenBeside;
|
||||
final ValueChanged<JsonMap>? onOpenBelow;
|
||||
final ValueChanged<JsonMap> onRename;
|
||||
final ValueChanged<JsonMap> onClose;
|
||||
final ValueChanged<JsonMap> 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,
|
||||
|
||||
@@ -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<JsonMap> onOpen;
|
||||
final ValueChanged<JsonMap>? onOpenBeside;
|
||||
final ValueChanged<JsonMap>? onOpenBelow;
|
||||
final VoidCallback? onLongPress;
|
||||
final ValueChanged<SessionAction> onAction;
|
||||
final bool selected;
|
||||
@@ -122,6 +126,8 @@ class ChatSessionRow extends StatelessWidget {
|
||||
session: session,
|
||||
duplicateTitles: duplicateTitles,
|
||||
onSelected: onAction,
|
||||
allowOpenBeside: onOpenBeside != null,
|
||||
allowOpenBelow: onOpenBelow != null,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ Widget memoChatSessionRow({
|
||||
required bool unseen,
|
||||
required bool divider,
|
||||
required ValueChanged<JsonMap> onOpen,
|
||||
ValueChanged<JsonMap>? onOpenBeside,
|
||||
ValueChanged<JsonMap>? onOpenBelow,
|
||||
required ValueChanged<JsonMap> onStar,
|
||||
required ValueChanged<JsonMap>? onColor,
|
||||
required ValueChanged<JsonMap> 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),
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
# Split-chat session menu
|
||||
|
||||
`ChatSessionsScreen` accepts optional `onOpenBeside` and `onOpenBelow`
|
||||
`ValueChanged<JsonMap>` 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.
|
||||
@@ -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 = <JsonMap>[];
|
||||
final right = <JsonMap>[];
|
||||
final below = <JsonMap>[];
|
||||
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 = <JsonMap>[];
|
||||
final below = <JsonMap>[];
|
||||
Future<void> 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 = <JsonMap>[];
|
||||
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');
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user