Keep browser chat server connections together in saved-server settings

This commit is contained in:
2026-11-08 22:01:09 +00:00
parent 349428f11d
commit 497cd66a1e
5 changed files with 92 additions and 10 deletions
@@ -23,21 +23,27 @@ class SavedServerRow extends StatelessWidget {
required this.selected,
required this.busy,
required this.onAction,
this.allowSelection = true,
this.primaryContext = false,
});
final bool allowSelection, primaryContext;
final SavedServer server;
final bool selected;
final bool busy;
final ValueChanged<SavedServerAction> onAction;
String _label(SavedServerAction action) => switch (action) {
SavedServerAction.use => 'Use ${server.name}',
SavedServerAction.use =>
primaryContext
? 'Use ${server.name} for pipelines and runs'
: 'Use ${server.name}',
SavedServerAction.edit => 'Edit ${server.name}',
SavedServerAction.remove => 'Remove ${server.name}',
};
List<SavedServerAction> get _actions => <SavedServerAction>[
if (!selected) SavedServerAction.use,
if (allowSelection && !selected) SavedServerAction.use,
SavedServerAction.edit,
SavedServerAction.remove,
];
@@ -87,7 +93,9 @@ class SavedServerRow extends StatelessWidget {
PopupMenuItem(value: action, child: Text(_label(action))),
],
);
final Widget mark = selected
final Widget mark = !allowSelection
? Icon(cupertino ? CupertinoIcons.desktopcomputer : Icons.computer)
: selected
? Icon(
cupertino
? CupertinoIcons.checkmark_circle_fill
@@ -109,13 +117,18 @@ class SavedServerRow extends StatelessWidget {
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
if (selected) const Text('Selected server'),
if (selected)
Text(
primaryContext ? 'Pipelines and runs server' : 'Selected server',
),
for (final (index, address) in server.endpoints.indexed)
Text('${index == 0 ? 'Preferred' : 'Backup $index'}: $address'),
],
),
trailing: menu,
onTap: selected || busy ? null : () => onAction(SavedServerAction.use),
onTap: !allowSelection || selected || busy
? null
: () => onAction(SavedServerAction.use),
);
}
}
@@ -1,6 +1,7 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import '../../core/servers/server_catalog.dart';
@@ -21,7 +22,12 @@ class _ServerSaveFailure implements Exception {
}
class SavedServersSection extends StatelessWidget {
const SavedServersSection({super.key, required this.connections});
const SavedServersSection({
super.key,
required this.connections,
this.allowPrimarySelection,
});
final bool? allowPrimarySelection;
final ServerConnections connections;
Future<void> _edit(BuildContext context, [SavedServer? server]) async {
@@ -100,17 +106,27 @@ class SavedServersSection extends StatelessWidget {
builder: (context, _) {
final cupertino = usesCupertinoHost(context);
final error = connections.error;
final allowSelection = allowPrimarySelection ?? !kIsWeb;
return SettingsGroup(
title: 'Servers',
leadingRows: true,
footer: error == null
? null
: Text(error, style: TextStyle(color: settingsErrorColor(context))),
footer: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('All saved machines connect for chat.'),
if (allowSelection)
const Text('The primary machine is used for pipelines and runs.'),
if (error != null)
Text(error, style: TextStyle(color: settingsErrorColor(context))),
],
),
children: [
for (final server in connections.catalog.servers)
SavedServerRow(
server: server,
selected: server.id == connections.catalog.active?.id,
allowSelection: allowSelection,
primaryContext: true,
busy: connections.busy,
onAction: (act) => _act(context, server, act),
),
+6
View File
@@ -18,3 +18,9 @@ and native discovery regressions. Analyzer clean (NWAPbG), full-app fixture buil
results and editable selected name/address fit. The fixture served controlled
JSON at /api/discovery; actual backend auth/discovery has separate Node/Go tests.
No production deployment or device testing in this commit.
Saved browser server rows no longer offer an exclusive Use action or navigate on
tap. All saved machines connect for chat; primary selection is explicitly for
pipelines/runs on native hosts. A widget regression covers preservation of the
browser's current server identity when another saved machine is tapped. Combined
discovery/settings layout suite: 43 tests passed (out.c7dJ7j).
@@ -2,6 +2,10 @@ import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/servers/server_catalog.dart';
import 'package:pipelines_app/core/servers/server_catalog_store.dart';
import 'package:pipelines_app/features/settings/server_connections.dart';
import 'package:pipelines_app/features/settings/saved_servers_section.dart';
import 'package:pipelines_app/features/settings/saved_server_row.dart';
import 'package:pipelines_app/features/settings/saved_server_editor.dart';
import 'package:pipelines_app/features/onboarding/discovery/browser_server_discovery.dart';
import 'package:pipelines_app/features/onboarding/onboarding_flow.dart';
@@ -20,6 +24,49 @@ BrowserServerDiscovery discovery() => BrowserServerDiscovery(
);
void main() {
testWidgets(
'browser server rows cannot navigate away by selecting one machine',
(tester) async {
final home = SavedServer.validated(
id: 'home',
name: 'Home',
endpoints: ['wss://home.test/connect'],
);
final other = SavedServer.validated(
id: 'other',
name: 'Other',
endpoints: ['wss://other.test/connect'],
);
final connections = ServerConnections(
store: MemoryServerCatalogStore(
catalog: ServerCatalog(servers: [home, other], selectedId: home.id),
),
onSelected: (_) async =>
fail('Browser must keep all chat connections in this page'),
);
addTearDown(connections.dispose);
await connections.load();
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: SavedServersSection(
connections: connections,
allowPrimarySelection: false,
),
),
),
);
await tester.tap(find.text('Other'));
await tester.pumpAndSettle();
expect(connections.catalog.active!.id, 'home');
await tester.tap(find.byKey(savedServerMenuKey('other')));
await tester.pumpAndSettle();
expect(find.textContaining('Use Other'), findsNothing);
expect(find.text('Edit Other'), findsOneWidget);
expect(find.text('Remove Other'), findsOneWidget);
},
);
testWidgets(
'choosing a discovered machine prefills editable name and address',
(tester) async {
@@ -181,7 +181,7 @@ void main() {
);
expect(find.byType(SavedServerRow), findsNWidgets(2));
expect(find.text('Selected server'), findsOneWidget);
expect(find.text('Pipelines and runs server'), findsOneWidget);
expect(
find.byWidgetPredicate(
(widget) => widget is Icon && widget.semanticLabel == 'Selected',