Open active chat when Chat is reselected
Route destination re-selections through the adaptive shell so Chat can restore its retained workspace and focus the composer. Add shell and phone coverage plus implementation notes for the empty-list behavior and verification limits.
This commit is contained in:
@@ -697,20 +697,29 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
}
|
||||
|
||||
void _selectDestination(AppDestination destination) {
|
||||
final current = tabForRoute(_delegate.route);
|
||||
final last = _tabRoutes[destination];
|
||||
if (destination == AppDestination.chat && current == destination) {
|
||||
final reopened = chatRouteForRetap(
|
||||
_delegate.shellRoute,
|
||||
_chatWorkspaceRoute,
|
||||
isValidSession: (id) =>
|
||||
_availableChatSessionIds == null ||
|
||||
_availableChatSessionIds!.contains(id),
|
||||
);
|
||||
_delegate.goTo(reopened ?? _routeOf(destination));
|
||||
_delegate.goTo(last ?? _routeOf(destination));
|
||||
}
|
||||
|
||||
/// A tap on the destination already shown. Chat reopens its retained
|
||||
/// workspace when the list is showing; other tabs select as before.
|
||||
void _reselectDestination(AppDestination destination) {
|
||||
if (destination != AppDestination.chat) {
|
||||
_selectDestination(destination);
|
||||
return;
|
||||
}
|
||||
_delegate.goTo(last ?? _routeOf(destination));
|
||||
final onList = _delegate.shellRoute.chatSessionId == null;
|
||||
final reopened = chatRouteForRetap(
|
||||
_delegate.shellRoute,
|
||||
_chatWorkspaceRoute,
|
||||
isValidSession: (id) =>
|
||||
_availableChatSessionIds == null ||
|
||||
_availableChatSessionIds!.contains(id),
|
||||
);
|
||||
_delegate.goTo(reopened ?? _routeOf(destination));
|
||||
// From the list, the reopened chat's composer takes focus, as Ctrl+K does.
|
||||
// A chat already showing keeps its focus behaviour.
|
||||
if (onList && reopened != null) _focusOpenChatComposer();
|
||||
}
|
||||
|
||||
void _routeChanged() {
|
||||
@@ -832,6 +841,7 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
runningRunCount: counts.running,
|
||||
destination: _destinationOf(route.kind),
|
||||
onDestinationSelected: _selectDestination,
|
||||
onDestinationReselected: _reselectDestination,
|
||||
onOpenChat: _focusOpenChatComposer,
|
||||
onClosePage: () => _delegate.goTo(
|
||||
_bodyRoutes[AppDestination.pipelines] ?? AppRoute.pipelines,
|
||||
|
||||
@@ -21,6 +21,7 @@ class AdaptiveShell extends StatefulWidget {
|
||||
this.destinationBodies = const {},
|
||||
this.destination,
|
||||
this.onDestinationSelected,
|
||||
this.onDestinationReselected,
|
||||
this.onClosePage,
|
||||
this.onSearch,
|
||||
this.onOpenChat,
|
||||
@@ -43,6 +44,11 @@ class AdaptiveShell extends StatefulWidget {
|
||||
/// selection, which preserves the plain-shell tests and native composition.
|
||||
final AppDestination? destination;
|
||||
final ValueChanged<AppDestination>? onDestinationSelected;
|
||||
|
||||
/// Runs when a destination's control is tapped while that destination is
|
||||
/// already shown (a re-select). The host decides what it means; Chat reopens
|
||||
/// its active chats. Null keeps re-selects as plain selections.
|
||||
final ValueChanged<AppDestination>? onDestinationReselected;
|
||||
final VoidCallback? onClosePage;
|
||||
|
||||
/// Opens the transient Search page. Null hides the action, so the plain
|
||||
@@ -105,6 +111,18 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The entry every tab control calls when tapped: a destination shown
|
||||
/// already is re-selected (see [AdaptiveShell.onDestinationReselected]), any
|
||||
/// other is selected.
|
||||
void _tapDestination(AppDestination destination) {
|
||||
final reselected = widget.onDestinationReselected;
|
||||
if (destination == _selected && reselected != null) {
|
||||
reselected(destination);
|
||||
return;
|
||||
}
|
||||
_select(destination);
|
||||
}
|
||||
|
||||
void _select(AppDestination destination) {
|
||||
final callback = widget.onDestinationSelected;
|
||||
if (callback != null) {
|
||||
@@ -201,7 +219,7 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
child: FloatingDestinationBar(
|
||||
showLabels: true,
|
||||
currentIndex: index,
|
||||
onTap: (value) => _select(shellTabDestinations[value]),
|
||||
onTap: (value) => _tapDestination(shellTabDestinations[value]),
|
||||
items: _destinationItems(),
|
||||
alignment: split ? AlignmentDirectional.bottomStart : null,
|
||||
),
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
# Chat tab re-tap opens the active chat
|
||||
|
||||
## Change
|
||||
- `lib/shell/adaptive_shell.dart`: new `onDestinationReselected` hook on
|
||||
`AdaptiveShell`. Every tab control calls `_tapDestination`; a tap on the
|
||||
destination already shown goes to the hook (when given), any other tap selects
|
||||
as before.
|
||||
- `lib/application/pipelines_app.dart`: the Chat re-tap decision (`chatRouteForRetap`
|
||||
with the retained workspace route) moved from `_selectDestination` into
|
||||
`_reselectDestination`, passed as `onDestinationReselected`. Other tabs keep
|
||||
`_selectDestination`'s behaviour.
|
||||
- Tests: `test/shell/destination_reselect_test.dart` (new, 3 cases) and
|
||||
`test/application/chat_registration_test.dart` (one new phone case: list ->
|
||||
re-tap Chat -> active chat shows).
|
||||
|
||||
## Focused results (app/, memwatch)
|
||||
- Baseline before edits: `chat_registration_test`, `app_route_test`,
|
||||
`destination_shortcuts_test` -> 21 passed, 0 failed.
|
||||
- After edits, 11 files: `destination_reselect_test`, `chat_registration_test`,
|
||||
`app_route_test`, `tab_location_navigation_test`, `pipelines_app_test`,
|
||||
`tab_history_back_test`, `floating_tab_bar_test`, `chat_control_tab_test`,
|
||||
`terminal_chat_tab_test`, `chat_wide_back_test`, `chat_scroll_back_test`
|
||||
-> 55 passed, 0 failed (one earlier run failed on my own test's second
|
||||
phone re-tap, which is unreachable; that step was removed, not the expectation).
|
||||
- `tool/analyze.sh` -> clean.
|
||||
|
||||
## States covered by tests
|
||||
- Phone: list (chat detail Back'd) -> re-tap Chat -> `/chat/a` with the thread.
|
||||
- No open chats / removed chat: stays on the list (existing case in
|
||||
`chat_registration_test`, still passing).
|
||||
- Shell: re-tap calls the hook and not selection; other tab selects; with no
|
||||
hook a re-tap is a plain selection.
|
||||
|
||||
## Limitations
|
||||
- Not browser- or device-verified (no capture here, per stage rules).
|
||||
- On a phone the open chat page covers the tab bar, so the "already showing"
|
||||
re-tap is not reachable there; it is not tested.
|
||||
- A future NavigationRail or phone bottom bar must call `_tapDestination` (the
|
||||
shell's tab entry) to get the same re-select behaviour.
|
||||
|
||||
## Review fix: composer focus on re-tap from the list
|
||||
- `lib/application/pipelines_app.dart` (`_reselectDestination`): when the Chat
|
||||
re-tap reopens the retained chat from the list, its composer now takes focus
|
||||
(`_focusOpenChatComposer`, the same request Ctrl+K makes), after `goTo`, as
|
||||
`_openChat` does. A re-tap while a chat is already showing requests nothing.
|
||||
- Test: `test/application/chat_registration_test.dart`, new case
|
||||
"mobile Chats retap from the list focuses the reopened chat composer"
|
||||
(phone size, list after Back -> re-tap Chat -> `chat-composer-a` EditableText
|
||||
has focus). The focus request is not platform-specific; a wide layout has no
|
||||
Back control that hides the workspace, so the case is run at phone size.
|
||||
- Mutation check: with the focus call disabled the new case fails (6 passed,
|
||||
1 failed); restored, the file passes.
|
||||
|
||||
## Focused results after the fix (app/, memwatch)
|
||||
- `test/application/chat_registration_test.dart test/shell/destination_reselect_test.dart`
|
||||
-> 10 passed, 0 failed (verdict named only these two paths).
|
||||
- `tool/analyze.sh` -> clean.
|
||||
- Not run: the other nine files from the earlier run; not rerun this visit.
|
||||
@@ -653,6 +653,59 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'mobile Chats retap from the list focuses the reopened chat composer',
|
||||
(tester) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
tester.view.physicalSize = const Size(560, 1000);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
final client = PipelinesClient(channelFactory: (_) => channel);
|
||||
final provider = PlatformRouteInformationProvider(
|
||||
initialRouteInformation: RouteInformation(uri: Uri.parse('/chat')),
|
||||
);
|
||||
addTearDown(provider.dispose);
|
||||
addTearDown(client.dispose);
|
||||
await tester.pumpWidget(
|
||||
PipelinesApp(
|
||||
androidSupported: false,
|
||||
server: webServer(),
|
||||
client: client,
|
||||
routeInformationProvider: provider,
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
await replyChatSessions(tester, channel, ['a']);
|
||||
await tester.pumpAndSettle();
|
||||
final chatTab = find.byKey(const ValueKey('shell.destination.chat'));
|
||||
await tester.tap(find.text('Chat a').first);
|
||||
await tester.pump();
|
||||
await replyChatHistory(
|
||||
tester,
|
||||
channel,
|
||||
subscribeIndex: 0,
|
||||
historyIndex: 0,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byTooltip('Back').hitTestable());
|
||||
await tester.pumpAndSettle();
|
||||
expect(provider.value.uri.path, '/chat');
|
||||
|
||||
await tester.tap(chatTab);
|
||||
await tester.pumpAndSettle();
|
||||
expect(provider.value.uri.path, '/chat/a');
|
||||
final composer = tester.widget<EditableText>(
|
||||
find.descendant(
|
||||
of: find.byKey(const ValueKey('chat-composer-a')),
|
||||
matching: find.byType(EditableText),
|
||||
),
|
||||
);
|
||||
expect(composer.focusNode.hasFocus, isTrue);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'mobile Chats retap stays on list with no history or a removed chat',
|
||||
(tester) async {
|
||||
@@ -770,4 +823,52 @@ void main() {
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'phone Chat re-tap from the list opens the active chat',
|
||||
(tester) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
tester.view.physicalSize = const Size(560, 1000);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
final client = PipelinesClient(channelFactory: (_) => channel);
|
||||
final provider = PlatformRouteInformationProvider(
|
||||
initialRouteInformation: RouteInformation(uri: Uri.parse('/chat')),
|
||||
);
|
||||
addTearDown(provider.dispose);
|
||||
addTearDown(client.dispose);
|
||||
await tester.pumpWidget(
|
||||
PipelinesApp(
|
||||
androidSupported: false,
|
||||
server: webServer(),
|
||||
client: client,
|
||||
routeInformationProvider: provider,
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
await replyChatSessions(tester, channel, ['a']);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Chat a').first);
|
||||
await tester.pump();
|
||||
await replyChatHistory(
|
||||
tester,
|
||||
channel,
|
||||
subscribeIndex: 0,
|
||||
historyIndex: 0,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byTooltip('Back').hitTestable());
|
||||
await tester.pumpAndSettle();
|
||||
expect(provider.value.uri.path, '/chat');
|
||||
expect(find.byType(ChatThreadView), findsNothing);
|
||||
|
||||
final chatTab = find.byKey(const ValueKey('shell.destination.chat'));
|
||||
await tester.tap(chatTab);
|
||||
await tester.pumpAndSettle();
|
||||
expect(provider.value.uri.path, '/chat/a');
|
||||
expect(find.byType(ChatThreadView), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
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';
|
||||
|
||||
void main() {
|
||||
Map<AppDestination, WidgetBuilder> bodies() => {
|
||||
for (final destination in shellTabDestinations)
|
||||
destination: (_) => Text(destination.name),
|
||||
};
|
||||
|
||||
testWidgets('tapping the shown tab re-selects it instead of selecting', (
|
||||
tester,
|
||||
) async {
|
||||
final selected = <AppDestination>[];
|
||||
final reselected = <AppDestination>[];
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: AdaptiveShell(
|
||||
destinationBodies: bodies(),
|
||||
destination: AppDestination.chat,
|
||||
onDestinationSelected: selected.add,
|
||||
onDestinationReselected: reselected.add,
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
await tester.tap(find.byKey(const ValueKey('shell.destination.chat')));
|
||||
await tester.pump();
|
||||
|
||||
expect(reselected, [AppDestination.chat]);
|
||||
expect(selected, isEmpty);
|
||||
});
|
||||
|
||||
testWidgets('tapping another tab selects it, not a re-select', (
|
||||
tester,
|
||||
) async {
|
||||
final selected = <AppDestination>[];
|
||||
final reselected = <AppDestination>[];
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: AdaptiveShell(
|
||||
destinationBodies: bodies(),
|
||||
destination: AppDestination.chat,
|
||||
onDestinationSelected: selected.add,
|
||||
onDestinationReselected: reselected.add,
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
await tester.tap(find.byKey(const ValueKey('shell.destination.runs')));
|
||||
await tester.pump();
|
||||
|
||||
expect(selected, [AppDestination.runs]);
|
||||
expect(reselected, isEmpty);
|
||||
});
|
||||
|
||||
testWidgets('without a re-select hook a shown tab is selected as before', (
|
||||
tester,
|
||||
) async {
|
||||
final selected = <AppDestination>[];
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: AdaptiveShell(
|
||||
destinationBodies: bodies(),
|
||||
destination: AppDestination.chat,
|
||||
onDestinationSelected: selected.add,
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
await tester.tap(find.byKey(const ValueKey('shell.destination.chat')));
|
||||
await tester.pump();
|
||||
|
||||
expect(selected, [AppDestination.chat]);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user