fix(sidebar): refresh table list after batch paste

This commit is contained in:
zhangsan 2026-07-25 19:39:25 +08:00 committed by GitHub
parent 913e3f553e
commit 7e0f77eded
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 5 deletions

View File

@ -2808,7 +2808,7 @@ async function confirmPasteTable() {
showPasteDialog.value = false;
let successCount = 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) {
const targetName = entry.targetName.trim();
try {
@ -2840,15 +2840,24 @@ async function confirmPasteTable() {
}
successCount++;
const refreshKey = `${entry.connectionId}:${entry.database}:${entry.schema || ""}`;
if (!refreshedConnections.has(refreshKey)) {
refreshedConnections.add(refreshKey);
await connectionStore.refreshObjectListTreeNode(entry.connectionId, entry.database, entry.schema);
}
refreshTargets.set(refreshKey, {
connectionId: entry.connectionId,
database: entry.database,
schema: entry.schema,
});
} catch (e: any) {
failCount++;
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) {
toast(t("contextMenu.batchPasteSuccess", { count: successCount }), 3000);
} else {

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, /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\)/);
});