fix(sidebar): refresh object counts after drop

This commit is contained in:
Freedom authored and GitHub committed 2026-07-31 14:39:58 +08:00
1 parent 959af4d841
commit 2ec9328eea
13 files changed
+269 -10

No files matched your search

@@ -2030,15 +2030,17 @@ async function confirmDropObject() {
const msgKey = node.type === "view" ? "contextMenu.dropViewSuccess" : node.type === "materialized_view" ? "contextMenu.dropViewSuccess" : node.type === "procedure" ? "contextMenu.dropProcedureSuccess" : "contextMenu.dropFunctionSuccess";
toast(t(msgKey, { name: node.label }), 3000);
closeDroppedTableObjectTabsForNode(node);
// Procedure/function drops refresh their parent instead of removing this
// node directly, so clear their pin before the old identity can survive.
// Refresh the parent object list so group badges and children stay in sync.
// Clear the pin first — refresh rebuilds nodes and the old identity must not survive.
connectionStore.removePinnedTreeNodes([node]);
if (node.type === "view" || node.type === "materialized_view") {
connectionStore.removeTreeNode(node.id);
releaseActiveNodeReference([node.id]);
} else {
try {
await refreshTableList(node);
} catch (error: any) {
// DROP already succeeded; keep the sidebar consistent if metadata refresh fails.
connectionStore.removeTreeNode(node.id);
toast(t("contextMenu.objectDropRefreshFailed", { message: error?.message || String(error) }), 5000);
}
releaseActiveNodeReference([node.id]);
} catch (e: any) {
toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);
}
@@ -2134,6 +2136,7 @@ async function confirmBatchDrop() {
showBatchDropConfirm.value = false;
return;
}
const refreshScopes = new Map<string, TreeNode>();
for (const target of targets) {
if (!target.connectionId || !target.database) continue;
await connectionStore.ensureConnected(target.connectionId);
@@ -2141,11 +2144,18 @@ async function confirmBatchDrop() {
if (!sql) continue;
await executeTreeNodeSqlWithProductionGuard(target, sql, { database: target.database, schema: target.schema });
closeDroppedTableObjectTabsForNode(target);
// Remove immediately so a later failure cannot leave dropped objects in the tree.
connectionStore.removeTreeNode(target.id);
releaseActiveNodeReference([target.id]);
refreshScopes.set(`${target.connectionId}:${target.database}:${target.schema ?? ""}`, target);
}
toast(t("contextMenu.batchDropSuccess", { count: targets.length }), 3000);
showBatchDropConfirm.value = false;
const refreshResults = await Promise.allSettled([...refreshScopes.values()].map((target) => refreshTableList(target)));
const refreshFailure = refreshResults.find((result): result is PromiseRejectedResult => result.status === "rejected");
if (refreshFailure) {
toast(t("contextMenu.objectDropRefreshFailed", { message: refreshFailure.reason?.message || String(refreshFailure.reason) }), 5000);
}
} catch (e: any) {
toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);
}