Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions lib/features/connections/connections_panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ class ConnectionsPanel extends StatefulWidget {
this.onSqliteObjectSelected,
this.onSqliteOpenSqlWorkspace,
this.onExtensionObjectSelected,
this.onConnectionRemoved,

/// When true, [initState] does not call [_loadData]. Widget tests that seed
/// SQLite in setUp should call [ConnectionsPanelState.reloadConnectionsFromDb]
Expand Down Expand Up @@ -565,6 +566,10 @@ class ConnectionsPanel extends StatefulWidget {
String name,
)? onExtensionObjectSelected;

/// Called after a connection was removed, so the shell can leave its
/// workspace if it was the open one.
final void Function(int connectionId)? onConnectionRemoved;

final bool skipInitialDbLoadForTest;

@override
Expand Down Expand Up @@ -802,9 +807,31 @@ class ConnectionsPanelState extends State<ConnectionsPanel> {
);
}

/// Asks first: removing a connection deletes its saved settings and
/// password and closes its sessions. The database itself is not touched.
Future<void> _removeConnection(int id) async {
String? name;
for (final c in _connections) {
if (c.id == id) {
name = c.name;
break;
}
}
final confirmed = await QueryaConfirmDialog.show(
context: context,
title: 'Remove connection?',
message: name == null || name.isEmpty
? 'The connection and its saved password are removed from Querya. '
'The database itself is not changed.'
: '"$name" and its saved password are removed from Querya. '
'The database itself is not changed.',
confirmLabel: 'Remove',
isDestructive: true,
);
if (confirmed != true || !mounted) return;
await _closeSessionsOf(id);
await LocalDb.instance.removeConnection(id);
widget.onConnectionRemoved?.call(id);
await _loadData();
}

Expand Down
6 changes: 6 additions & 0 deletions lib/features/main_screen/main_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1754,6 +1754,12 @@ class _ConnectionsPanelSlotState extends State<_ConnectionsPanelSlot> {
onSqliteObjectSelected: widget.onSqliteObjectSelected,
onSqliteOpenSqlWorkspace: widget.onSqliteOpenSqlWorkspace,
onExtensionObjectSelected: widget.onExtensionObjectSelected,
onConnectionRemoved: (id) {
// The open workspace belonged to the removed connection: go home.
if (widget.workspace.value.activeConnection?.id != id) return;
widget.workspace.value = MainScreenWorkspaceState.empty;
QueryaShellStatus.instance.clear();
},
);
}
}
Loading