fix(sidebar): preserve tree expansion state after dropping a table

Remove the dropped table node directly instead of refreshing the entire
table list, which was causing all tree nodes to collapse.
This commit is contained in:
t8y2 2026-05-15 14:55:14 +08:00
parent cec7d6d7ad
commit 2af94c6fea
2 changed files with 9 additions and 1 deletions

View File

@ -732,7 +732,7 @@ async function confirmDropTable() {
await connectionStore.ensureConnected(node.connectionId);
await api.executeQuery(node.connectionId, node.database, buildDropTableSql(), node.schema);
toast(t("contextMenu.dropTableSuccess", { name: node.label }), 3000);
await refreshTableList(node);
connectionStore.removeTreeNode(node.id);
} catch (e: any) {
toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);
}

View File

@ -251,6 +251,13 @@ export const useConnectionStore = defineStore("connection", () => {
loadedTreeNodeChildrenIds.value.add(parent.id);
}
function removeTreeNode(nodeId: string) {
const parent = findParentNode(treeNodes.value, nodeId);
if (parent?.children) {
parent.children = parent.children.filter((c) => c.id !== nodeId);
}
}
function buildSavedSqlRootNode(connectionId: string, existingRoot?: TreeNode): TreeNode {
const savedSqlStore = useSavedSqlStore();
const existingById = new Map<string, TreeNode>();
@ -1565,6 +1572,7 @@ export const useConnectionStore = defineStore("connection", () => {
activeConnectionId,
selectedTreeNodeId,
treeNodes,
removeTreeNode,
refreshAllTree,
refreshSavedSqlTree,
refreshTreeNode,