1+ import 'package:flutter/foundation.dart' show visibleForTesting;
12import 'package:flutter/material.dart' as material;
23import 'package:querya_desktop/core/extensions/extension_driver_catalog.dart' ;
34import 'package:querya_desktop/core/extensions/models/extension_contributions.dart' ;
@@ -9,6 +10,7 @@ import 'package:querya_desktop/features/mongodb/mongodb_connection_form.dart';
910import 'package:querya_desktop/features/mysql/mysql_connection_form.dart' ;
1011import 'package:querya_desktop/features/postgresql/postgresql_connection_form.dart' ;
1112import 'package:querya_desktop/features/redis/redis_connection_form.dart' ;
13+ import 'package:querya_desktop/shared/widgets/app_toast.dart' ;
1214
1315export 'package:querya_desktop/features/connections/connection_edit_secrets.dart' ;
1416
@@ -74,9 +76,29 @@ Future<ConnectionRow?> promptEditConnection(
7476
7577 if (ExtensionDriverCatalog .isExtensionDriverConnection (existing)) {
7678 final manifest = ExtensionDriverCatalog .manifestForConnection (existing);
77- if (manifest == null ) return null ;
78- final driver = _driverForConnection (existing, manifest.contributedDrivers);
79- if (driver == null ) return null ;
79+ if (manifest == null ) {
80+ // Not a silent nothing (#1314): say what is missing.
81+ final who = existing.extensionId? .trim ().isNotEmpty == true
82+ ? 'The extension "${existing .extensionId !.trim ()}"'
83+ : 'The extension for "${existing .type }" connections' ;
84+ _explain (
85+ dialogContext,
86+ '$who that provides "${existing .name }" is not installed or is '
87+ 'disabled. Install or enable it in the extension manager, then edit '
88+ 'the connection.' ,
89+ );
90+ return null ;
91+ }
92+ final driver = driverForConnection (existing, manifest.contributedDrivers);
93+ if (driver == null ) {
94+ _explain (
95+ dialogContext,
96+ 'The extension "${manifest .id }" no longer provides the driver '
97+ '"${existing .type }" that "${existing .name }" uses. Update or '
98+ 'reinstall the extension to edit it.' ,
99+ );
100+ return null ;
101+ }
80102 return showExtensionConnectionForm (
81103 dialogContext,
82104 manifest: manifest,
@@ -112,19 +134,44 @@ Future<ConnectionRow?> promptEditConnection(
112134 folderId: existing.folderId,
113135 initial: existing,
114136 ),
115- _ => null ,
137+ _ => _explainUnknownType (dialogContext, existing) ,
116138 };
117139}
118140
119- DriverContribution ? _driverForConnection (
141+ ConnectionRow ? _explainUnknownType (
142+ material.BuildContext context,
143+ ConnectionRow existing,
144+ ) {
145+ _explain (
146+ context,
147+ 'Unknown connection type "${existing .type }": "${existing .name }" cannot '
148+ 'be edited here.' ,
149+ );
150+ return null ;
151+ }
152+
153+ /// A short error toast on [context] , when it is still mounted.
154+ void _explain (material.BuildContext context, String message) {
155+ if (! context.mounted) return ;
156+ showAppToast (
157+ context: context,
158+ variant: AppToastVariant .error,
159+ message: message,
160+ );
161+ }
162+
163+ /// The driver of [row] in [drivers] : the one whose id is the row's type, or,
164+ /// when the extension contributes exactly one, that one. Never a different
165+ /// driver of an extension that has several (#1314).
166+ @visibleForTesting
167+ DriverContribution ? driverForConnection (
120168 ConnectionRow row,
121169 Iterable <DriverContribution > drivers,
122170) {
123171 final type = row.type.trim ().toLowerCase ();
124- DriverContribution ? first;
125- for (final driver in drivers) {
126- first ?? = driver;
172+ final all = drivers.toList ();
173+ for (final driver in all) {
127174 if (driver.driverId.trim ().toLowerCase () == type) return driver;
128175 }
129- return first ;
176+ return all.length == 1 ? all.single : null ;
130177}
0 commit comments