feat(sidebar): close connected connections in group

This commit is contained in:
jearhe authored and GitHub committed 2026-08-24 13:33:37 +08:00
1 parent 917bbc1238
commit a8369390df
11 files changed
+104 -8

No files matched your search

@@ -212,16 +212,12 @@ export function useSidebarConnectionMutationRuntime(options: SidebarConnectionMu
}
}
async function disconnectConnection() {
const targets = selectedConnectionDisconnectTargets(activeNode.value, selectedTreeNodesInVisibleOrder()).filter((target) => connectionStore.connectedIds.has(target.connectionId));
if (!targets.length) return;
async function disconnectConnectionIds(connectionIds: readonly string[]) {
if (!connectionIds.length) return;
const result = await disconnectSidebarConnections(
targets.map((target) => target.connectionId),
(connectionId) => connectionStore.disconnect(connectionId),
);
const result = await disconnectSidebarConnections(connectionIds, (connectionId) => connectionStore.disconnect(connectionId));
if (!result.failed) {
toast(targets.length > 1 ? t("connection.disconnectedSelected", { count: targets.length }) : t("connection.disconnected"), 2000);
toast(connectionIds.length > 1 ? t("connection.disconnectedSelected", { count: connectionIds.length }) : t("connection.disconnected"), 2000);
return;
}
if (result.succeeded > 0) {
@@ -232,6 +228,13 @@ export function useSidebarConnectionMutationRuntime(options: SidebarConnectionMu
toast(t("connection.saveFailed", { message }), 5000);
}
async function disconnectConnection() {
const connectionIds = selectedConnectionDisconnectTargets(activeNode.value, selectedTreeNodesInVisibleOrder())
.filter((target) => connectionStore.connectedIds.has(target.connectionId))
.map((target) => target.connectionId);
await disconnectConnectionIds(connectionIds);
}
function connectionDisconnectTargets() {
return selectedConnectionDisconnectTargets(activeNode.value, selectedTreeNodesInVisibleOrder());
}
@@ -246,6 +249,24 @@ export function useSidebarConnectionMutationRuntime(options: SidebarConnectionMu
return connectionDisconnectTargets().some((target) => connectionStore.connectedIds.has(target.connectionId));
}
function connectionGroupDisconnectTargets(): string[] {
const node = activeNode.value;
if (node.type !== "connection-group") return [];
return connectionStore.connectionIdsInGroups([node.id]).filter((connectionId) => connectionStore.connectedIds.has(connectionId));
}
function connectionGroupDisconnectMenuLabel(): string {
return t("connectionGroup.closeConnections", { count: connectionGroupDisconnectTargets().length });
}
function canDisconnectConnectionGroup(): boolean {
return connectionGroupDisconnectTargets().length > 0;
}
async function disconnectConnectionGroup() {
await disconnectConnectionIds(connectionGroupDisconnectTargets());
}
/** "断开并忘记本次密码"是否可用:save_password=false 且当前已连接(本次运行期必已输入密码)。 */
function canForgetSessionCredential(): boolean {
const node = activeNode.value;
@@ -426,6 +447,9 @@ export function useSidebarConnectionMutationRuntime(options: SidebarConnectionMu
disconnectConnection,
connectionDisconnectMenuLabel,
canDisconnectConnection,
connectionGroupDisconnectMenuLabel,
canDisconnectConnectionGroup,
disconnectConnectionGroup,
canForgetSessionCredential,
disconnectAndForgetConnectionPassword,
cancelConnectionAttempt,