Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore(sql-editor): remember last expanded keys when connection panel reopens (#11484)

Liu Jifc0d5646fb90
diff --git a/frontend/src/store/modules/sqlEditor/tree.ts b/frontend/src/store/modules/sqlEditor/tree.ts
index 5ef17d4a9f..9ff9b4ee46 100644
--- a/frontend/src/store/modules/sqlEditor/tree.ts
+++ b/frontend/src/store/modules/sqlEditor/tree.ts
@@ -114,6 +114,7 @@ export const useSQLEditorTreeStore = defineStore("sqlEditorTree", () => {
});
const state = ref<TreeState>("UNSET");
const tree = ref<TreeNode[]>([]);
+ const expandedKeys = ref<string[]>([]);
const collectNode = <T extends NodeType>(node: TreeNode<T>) => {
const { type, target } = node.meta;
@@ -132,15 +133,18 @@ export const useSQLEditorTreeStore = defineStore("sqlEditorTree", () => {
const buildTree = () => {
nodeListMapById.clear();
+ expandedKeys.value = [];
tree.value = buildTreeImpl(
filteredDatabaseList.value,
filteredFactorList.value
);
};
+
const cleanup = () => {
tree.value = [];
factorList.value = defaultFactorList();
nodeListMapById.clear();
+ expandedKeys.value = [];
state.value = "UNSET";
};
@@ -181,6 +185,7 @@ export const useSQLEditorTreeStore = defineStore("sqlEditorTree", () => {
collectNode,
nodesByTarget,
buildTree,
+ expandedKeys,
cleanup,
};
});
diff --git a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vue b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vue
index b2266c6104..d958d0e0da 100644
--- a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vue
+++ b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vue
@@ -52,6 +52,7 @@
import { useElementSize, useMounted } from "@vueuse/core";
import { head } from "lodash-es";
import { NTree, NDropdown, type TreeOption } from "naive-ui";
+import { storeToRefs } from "pinia";
import { ref, computed, nextTick, watch, h } from "vue";
import { onMounted } from "vue";
import MaskSpinner from "@/components/misc/MaskSpinner.vue";
@@ -137,7 +138,7 @@ const selectedKeys = computed(() => {
}
return [];
});
-const expandedKeys = ref<string[]>([]);
+const { expandedKeys } = storeToRefs(treeStore);
const upsertExpandedKeys = (key: string) => {
if (expandedKeys.value.includes(key)) {
return;
@@ -305,8 +306,12 @@ watch(
{ immediate: true }
);
-const calcDefaultExpandKeys = async () => {
+const calcDefaultExpandKeys = async (override = false) => {
await nextTick();
+ if (expandedKeys.value.length > 0 && !override) {
+ // keep as-is
+ return;
+ }
const openingDatabaseList = resolveOpeningDatabaseListFromSQLEditorTabList();
const keys = new Set<string>();
// Recursively expand opening databases' parent nodes
@@ -338,15 +343,14 @@ const calcDefaultExpandKeys = async () => {
}
}
}
- console.log("defaultExpandKeys", Array.from(keys).join(","));
expandedKeys.value = Array.from(keys);
};
useEmitteryEventListener(editorEvents, "tree-ready", () => {
- calcDefaultExpandKeys();
+ calcDefaultExpandKeys(true);
});
-onMounted(calcDefaultExpandKeys);
+onMounted(() => calcDefaultExpandKeys(false));
</script>
<style lang="postcss" scoped>