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

+30 -3
View File
@@ -1244,14 +1244,19 @@ export const useConnectionStore = defineStore("connection", () => {
const isExpanded = old.isExpanded;
const isLoading = old.isLoading;
const oldChildren = old.children;
const objectCount = child.objectCount ?? old.objectCount;
Object.assign(old, child);
old.isExpanded = isExpanded;
old.isLoading = isLoading;
old.children = oldChildren;
old.objectCount = objectCount;
return old;
}
if (old?.isExpanded) {
return { ...child, isExpanded: true, children: old.children };
return { ...child, isExpanded: true, children: old.children, objectCount: child.objectCount ?? old.objectCount };
}
if (old && objectTypesForGroupNode(old.type)) {
return { ...child, objectCount: child.objectCount ?? old.objectCount };
}
// Same-id collapsed database/schema shell replace (e.g. DDL → force loadDatabases):
// prior confirmed-empty markers belong to the discarded instance and must not skip
@@ -1304,6 +1309,13 @@ export const useConnectionStore = defineStore("connection", () => {
const parent = findParentNode(treeNodes.value, nodeId);
if (parent?.children) {
parent.children = parent.children.filter((c) => c.id !== nodeId);
// Keep the group badge in sync with remaining real children (exclude load-more).
if (parent.objectCount != null) {
parent.objectCount = withoutLoadMoreNodes(parent.children).length;
}
}
if (parent?.hiddenChildren) {
parent.hiddenChildren = parent.hiddenChildren.filter((child) => child.id !== nodeId);
}
if (selectedTreeNodeId.value === nodeId) selectedTreeNodeId.value = null;
selectedTreeNodeIds.value = selectedTreeNodeIds.value.filter((id) => id !== nodeId);
@@ -5116,13 +5128,28 @@ export const useConnectionStore = defineStore("connection", () => {
if (node.connectionId && !connectedIds.value.has(node.connectionId)) return;
const expandedIds = collectExpandedNodeIds([node]);
expandedIds.add(node.id);
const previousChildren = node.children;
const previousHiddenChildren = node.hiddenChildren;
const previousObjectCount = node.objectCount;
const previousLoadedIds = [...loadedTreeNodeChildrenIds.value].filter((id) => id === node.id || id.startsWith(`${node.id}:`));
const previousConfirmedEmptyIds = [...confirmedEmptyTreeNodeIds.value].filter((id) => id === node.id || id.startsWith(`${node.id}:`));
await clearPersistedTreeCacheForNode(node);
clearLoadedChildrenCache(node.id);
if (node.type !== "connection-group") {
node.children = [];
}
await loadTreeNodeChildren(node, { force: true });
await restoreExpandedChildren(node, expandedIds, { force: true });
try {
await loadTreeNodeChildren(node, { force: true });
await restoreExpandedChildren(node, expandedIds, { force: true });
} catch (error) {
node.children = previousChildren;
node.hiddenChildren = previousHiddenChildren;
node.objectCount = previousObjectCount;
clearLoadedChildrenCache(node.id, { deletePersisted: false });
for (const id of previousLoadedIds) loadedTreeNodeChildrenIds.value.add(id);
for (const id of previousConfirmedEmptyIds) confirmedEmptyTreeNodeIds.value.add(id);
throw error;
}
}
async function refreshTreeNodeForTableNameFilter(node: TreeNode, scopeKey: string, revision: number) {