feat(sidebar): add connection copy paste shortcuts

This commit is contained in:
二丫讲梵 authored and GitHub committed 2026-07-04 12:19:56 +08:00
1 parent d8047a77b4
commit 90d2ede740
19 files changed
+509 -20

No files matched your search

+52 -3
View File
@@ -147,11 +147,21 @@ interface TreeClipboardTableEntry {
tableName: string;
}
export interface TreeClipboard {
kind: "table-copy";
tables: TreeClipboardTableEntry[];
interface TreeClipboardConnectionEntry {
config: ConnectionConfig;
sourceGroupId: string | null;
}
export type TreeClipboard =
| {
kind: "table-copy";
tables: TreeClipboardTableEntry[];
}
| {
kind: "connection-copy";
connections: TreeClipboardConnectionEntry[];
};
interface LoadTreeOptions {
force?: boolean;
expectedSidebarSearchQuery?: string;
@@ -1017,6 +1027,43 @@ export const useConnectionStore = defineStore("connection", () => {
stopCreatingConnectionInGroup();
}
function copyConnectionsToTreeClipboard(connectionIds: Iterable<string>): number {
const seen = new Set<string>();
const entries: TreeClipboardConnectionEntry[] = [];
for (const connectionId of connectionIds) {
if (seen.has(connectionId)) continue;
seen.add(connectionId);
const config = getConfig(connectionId);
if (!config) continue;
entries.push({
config: { ...config },
sourceGroupId: findConnectionLocation(sidebarLayout.value, connectionId)?.groupId ?? null,
});
}
if (!entries.length) return 0;
treeClipboard.value = { kind: "connection-copy", connections: entries };
return entries.length;
}
async function pasteConnectionClipboard(targetGroupId?: string | null): Promise<number> {
const clipboard = treeClipboard.value;
if (clipboard?.kind !== "connection-copy" || clipboard.connections.length === 0) return 0;
let pastedCount = 0;
for (const entry of clipboard.connections) {
await addConnection(
{
...entry.config,
id: uuid(),
name: `${entry.config.name} (Copy)`,
},
targetGroupId === undefined ? entry.sourceGroupId : targetGroupId,
);
pastedCount += 1;
}
return pastedCount;
}
function invalidateCompletionCache(connectionId: string, database?: string) {
const cachePrefix = database == null ? `${connectionId}:` : `${connectionId}:${database}:`;
const exactCacheKey = database == null ? null : `${connectionId}:${database}`;
@@ -3979,6 +4026,8 @@ export const useConnectionStore = defineStore("connection", () => {
isTreeNodePinned,
toggleTreeNodePin,
addConnection,
copyConnectionsToTreeClipboard,
pasteConnectionClipboard,
addEphemeralConnection,
updateConnection,
setDefaultDatabase,