Keep browser chat server connections together in saved-server settings
This commit is contained in:
@@ -23,21 +23,27 @@ class SavedServerRow extends StatelessWidget {
|
|||||||
required this.selected,
|
required this.selected,
|
||||||
required this.busy,
|
required this.busy,
|
||||||
required this.onAction,
|
required this.onAction,
|
||||||
|
this.allowSelection = true,
|
||||||
|
this.primaryContext = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
final bool allowSelection, primaryContext;
|
||||||
final SavedServer server;
|
final SavedServer server;
|
||||||
final bool selected;
|
final bool selected;
|
||||||
final bool busy;
|
final bool busy;
|
||||||
final ValueChanged<SavedServerAction> onAction;
|
final ValueChanged<SavedServerAction> onAction;
|
||||||
|
|
||||||
String _label(SavedServerAction action) => switch (action) {
|
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.edit => 'Edit ${server.name}',
|
||||||
SavedServerAction.remove => 'Remove ${server.name}',
|
SavedServerAction.remove => 'Remove ${server.name}',
|
||||||
};
|
};
|
||||||
|
|
||||||
List<SavedServerAction> get _actions => <SavedServerAction>[
|
List<SavedServerAction> get _actions => <SavedServerAction>[
|
||||||
if (!selected) SavedServerAction.use,
|
if (allowSelection && !selected) SavedServerAction.use,
|
||||||
SavedServerAction.edit,
|
SavedServerAction.edit,
|
||||||
SavedServerAction.remove,
|
SavedServerAction.remove,
|
||||||
];
|
];
|
||||||
@@ -87,7 +93,9 @@ class SavedServerRow extends StatelessWidget {
|
|||||||
PopupMenuItem(value: action, child: Text(_label(action))),
|
PopupMenuItem(value: action, child: Text(_label(action))),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
final Widget mark = selected
|
final Widget mark = !allowSelection
|
||||||
|
? Icon(cupertino ? CupertinoIcons.desktopcomputer : Icons.computer)
|
||||||
|
: selected
|
||||||
? Icon(
|
? Icon(
|
||||||
cupertino
|
cupertino
|
||||||
? CupertinoIcons.checkmark_circle_fill
|
? CupertinoIcons.checkmark_circle_fill
|
||||||
@@ -109,13 +117,18 @@ class SavedServerRow extends StatelessWidget {
|
|||||||
subtitle: Column(
|
subtitle: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: <Widget>[
|
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)
|
for (final (index, address) in server.endpoints.indexed)
|
||||||
Text('${index == 0 ? 'Preferred' : 'Backup $index'}: $address'),
|
Text('${index == 0 ? 'Preferred' : 'Backup $index'}: $address'),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
trailing: menu,
|
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 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../../core/servers/server_catalog.dart';
|
import '../../core/servers/server_catalog.dart';
|
||||||
@@ -21,7 +22,12 @@ class _ServerSaveFailure implements Exception {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class SavedServersSection extends StatelessWidget {
|
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;
|
final ServerConnections connections;
|
||||||
|
|
||||||
Future<void> _edit(BuildContext context, [SavedServer? server]) async {
|
Future<void> _edit(BuildContext context, [SavedServer? server]) async {
|
||||||
@@ -100,17 +106,27 @@ class SavedServersSection extends StatelessWidget {
|
|||||||
builder: (context, _) {
|
builder: (context, _) {
|
||||||
final cupertino = usesCupertinoHost(context);
|
final cupertino = usesCupertinoHost(context);
|
||||||
final error = connections.error;
|
final error = connections.error;
|
||||||
|
final allowSelection = allowPrimarySelection ?? !kIsWeb;
|
||||||
return SettingsGroup(
|
return SettingsGroup(
|
||||||
title: 'Servers',
|
title: 'Servers',
|
||||||
leadingRows: true,
|
leadingRows: true,
|
||||||
footer: error == null
|
footer: Column(
|
||||||
? null
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
: Text(error, style: TextStyle(color: settingsErrorColor(context))),
|
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: [
|
children: [
|
||||||
for (final server in connections.catalog.servers)
|
for (final server in connections.catalog.servers)
|
||||||
SavedServerRow(
|
SavedServerRow(
|
||||||
server: server,
|
server: server,
|
||||||
selected: server.id == connections.catalog.active?.id,
|
selected: server.id == connections.catalog.active?.id,
|
||||||
|
allowSelection: allowSelection,
|
||||||
|
primaryContext: true,
|
||||||
busy: connections.busy,
|
busy: connections.busy,
|
||||||
onAction: (act) => _act(context, server, act),
|
onAction: (act) => _act(context, server, act),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -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
|
results and editable selected name/address fit. The fixture served controlled
|
||||||
JSON at /api/discovery; actual backend auth/discovery has separate Node/Go tests.
|
JSON at /api/discovery; actual backend auth/discovery has separate Node/Go tests.
|
||||||
No production deployment or device testing in this commit.
|
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/material.dart';
|
||||||
import 'package:flutter_test/flutter_test.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.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/settings/saved_server_editor.dart';
|
||||||
import 'package:pipelines_app/features/onboarding/discovery/browser_server_discovery.dart';
|
import 'package:pipelines_app/features/onboarding/discovery/browser_server_discovery.dart';
|
||||||
import 'package:pipelines_app/features/onboarding/onboarding_flow.dart';
|
import 'package:pipelines_app/features/onboarding/onboarding_flow.dart';
|
||||||
@@ -20,6 +24,49 @@ BrowserServerDiscovery discovery() => BrowserServerDiscovery(
|
|||||||
);
|
);
|
||||||
|
|
||||||
void main() {
|
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(
|
testWidgets(
|
||||||
'choosing a discovered machine prefills editable name and address',
|
'choosing a discovered machine prefills editable name and address',
|
||||||
(tester) async {
|
(tester) async {
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ void main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(find.byType(SavedServerRow), findsNWidgets(2));
|
expect(find.byType(SavedServerRow), findsNWidgets(2));
|
||||||
expect(find.text('Selected server'), findsOneWidget);
|
expect(find.text('Pipelines and runs server'), findsOneWidget);
|
||||||
expect(
|
expect(
|
||||||
find.byWidgetPredicate(
|
find.byWidgetPredicate(
|
||||||
(widget) => widget is Icon && widget.semanticLabel == 'Selected',
|
(widget) => widget is Icon && widget.semanticLabel == 'Selected',
|
||||||
|
|||||||
Reference in New Issue
Block a user