fix(sidebar): refresh table list after batch paste

This commit is contained in:
zhangsan authored and GitHub committed 2026-07-25 19:39:25 +08:00
1 parent 913e3f553e
commit 7e0f77eded
2 files changed
+27 -5

No files matched your search

@@ -2808,7 +2808,7 @@ async function confirmPasteTable() {
showPasteDialog.value = false; showPasteDialog.value = false;
let successCount = 0; let successCount = 0;
let failCount = 0; let failCount = 0;
const refreshedConnections = new Set<string>(); const refreshTargets = new Map<string, { connectionId: string; database: string; schema?: string }>();
for (const entry of entries) { for (const entry of entries) {
const targetName = entry.targetName.trim(); const targetName = entry.targetName.trim();
try { try {
@@ -2840,15 +2840,24 @@ async function confirmPasteTable() {
} }
successCount++; successCount++;
const refreshKey = `${entry.connectionId}:${entry.database}:${entry.schema || ""}`; const refreshKey = `${entry.connectionId}:${entry.database}:${entry.schema || ""}`;
if (!refreshedConnections.has(refreshKey)) { refreshTargets.set(refreshKey, {
refreshedConnections.add(refreshKey); connectionId: entry.connectionId,
await connectionStore.refreshObjectListTreeNode(entry.connectionId, entry.database, entry.schema); database: entry.database,
} schema: entry.schema,
});
} catch (e: any) { } catch (e: any) {
failCount++; failCount++;
console.error(`Failed to paste table "${entry.sourceName}" -> "${targetName}":`, e); console.error(`Failed to paste table "${entry.sourceName}" -> "${targetName}":`, e);
} }
} }
for (const refreshTarget of refreshTargets.values()) {
try {
await connectionStore.refreshObjectListTreeNode(refreshTarget.connectionId, refreshTarget.database, refreshTarget.schema);
} catch (e: any) {
failCount++;
console.error(`Failed to refresh pasted tables for "${refreshTarget.database}"${refreshTarget.schema ? ` schema "${refreshTarget.schema}"` : ""}:`, e);
}
}
if (failCount === 0) { if (failCount === 0) {
toast(t("contextMenu.batchPasteSuccess", { count: successCount }), 3000); toast(t("contextMenu.batchPasteSuccess", { count: successCount }), 3000);
} else { } else {
+13
View File
@@ -71,3 +71,16 @@ test("table copy menu uses the shared single and multi-selection clipboard path"
assert.match(copySelectedNamesBody, /updateTreeClipboardForNodes\(nodes\)/); assert.match(copySelectedNamesBody, /updateTreeClipboardForNodes\(nodes\)/);
assert.match(copySelectedNamesBody, /copyToClipboard\(nodes\.map\(copyNameForTreeNode\)\.join\("\\n"\)\)/); assert.match(copySelectedNamesBody, /copyToClipboard\(nodes\.map\(copyNameForTreeNode\)\.join\("\\n"\)\)/);
}); });
test("batch table paste refreshes each object list after all tables are processed", () => {
const runtimeHost = readFileSync("apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue", "utf8");
const confirmPasteTableBody = functionBody(runtimeHost, "confirmPasteTable");
const pasteLoopIndex = confirmPasteTableBody.indexOf("for (const entry of entries)");
const refreshLoopIndex = confirmPasteTableBody.indexOf("for (const refreshTarget of refreshTargets.values())");
assert.notEqual(pasteLoopIndex, -1);
assert.notEqual(refreshLoopIndex, -1);
assert.ok(refreshLoopIndex > pasteLoopIndex, "object-list refresh must run after the table paste loop");
assert.doesNotMatch(confirmPasteTableBody.slice(pasteLoopIndex, refreshLoopIndex), /refreshObjectListTreeNode/);
assert.match(confirmPasteTableBody.slice(refreshLoopIndex), /refreshObjectListTreeNode\(refreshTarget\.connectionId, refreshTarget\.database, refreshTarget\.schema\)/);
});