Skip to content

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

chore: use virtual list for rendering large list in database tree (#7204)

boojack28f4eff04376
diff --git a/frontend/src/components/SchemaDesigner/DatabaseTree.vue b/frontend/src/components/SchemaDesigner/DatabaseTree.vue
index ca670a22ec..184ee99395 100644
--- a/frontend/src/components/SchemaDesigner/DatabaseTree.vue
+++ b/frontend/src/components/SchemaDesigner/DatabaseTree.vue
@@ -20,9 +20,14 @@
</template>
</NInput>
</div>
- <div ref="treeRef" class="schema-editor-database-tree pb-2 h-auto">
+ <div
+ class="schema-designer-database-tree pb-2 overflow-y-auto h-full text-sm"
+ >
<NTree
+ ref="treeRef"
:key="treeKeyRef"
+ virtual-scroll
+ style="height: 100%"
:block-line="true"
:data="treeData"
:pattern="searchPattern"
@@ -65,7 +70,6 @@ import { escape, isUndefined } from "lodash-es";
import { TreeOption, NEllipsis, NInput, NDropdown, NTree } from "naive-ui";
import { computed, watch, ref, h, reactive, nextTick } from "vue";
import { useI18n } from "vue-i18n";
-import scrollIntoView from "scroll-into-view-if-needed";
import SchemaIcon from "~icons/heroicons-outline/view-columns";
import TableIcon from "~icons/heroicons-outline/table-cells";
import EllipsisIcon from "~icons/heroicons-solid/ellipsis-horizontal";
@@ -133,7 +137,7 @@ const contextMenu = reactive<TreeContextMenu>({
clientY: 0,
treeNode: undefined,
});
-const treeRef = ref();
+const treeRef = ref<InstanceType<typeof NTree>>();
const searchPattern = ref("");
const expandedKeysRef = ref<string[]>([]);
const selectedKeysRef = ref<string[]>([]);
@@ -274,12 +278,9 @@ watch(
if (state.shouldRelocateTreeNode) {
nextTick(() => {
- const element = treeRef.value?.querySelector(".n-tree-node--selected");
- if (element) {
- scrollIntoView(element, {
- scrollMode: "if-needed",
- });
- }
+ treeRef.value?.scrollTo({
+ key: selectedKeysRef.value[0],
+ });
});
}
}
@@ -442,37 +443,36 @@ const handleDropdownClickoutside = (e: MouseEvent) => {
</script>
<style>
-.schema-editor-database-tree .n-tree-node-wrapper {
+.schema-designer-database-tree .n-tree-node-wrapper {
@apply !py-px;
}
-.schema-editor-database-tree .n-tree-node-content__prefix {
+.schema-designer-database-tree .n-tree-node-content__prefix {
@apply shrink-0 !mr-1;
}
-.schema-editor-database-tree .n-tree-node-content__text {
+.schema-designer-database-tree .n-tree-node-content__text {
@apply truncate mr-1;
}
-.schema-editor-database-tree .n-tree-node-content__suffix {
+.schema-designer-database-tree .n-tree-node-content__suffix {
@apply rounded-sm !hidden hover:opacity-80;
}
-.schema-editor-database-tree
+.schema-designer-database-tree
.n-tree-node-wrapper:hover
.n-tree-node-content__suffix {
@apply !flex;
}
-.schema-editor-database-tree
+.schema-designer-database-tree
.n-tree-node-wrapper
.n-tree-node--selected
.n-tree-node-content__suffix {
@apply !flex;
}
-.schema-editor-database-tree .n-tree-node-switcher {
+.schema-designer-database-tree .n-tree-node-switcher {
@apply px-0 !w-4 !h-7;
}
</style>
<style scoped>
-.schema-editor-database-tree {
- @apply overflow-y-auto;
+.schema-designer-database-tree {
max-height: calc(100% - 48px);
}
</style>
diff --git a/frontend/src/components/SchemaEditor/DatabaseTree.vue b/frontend/src/components/SchemaEditor/DatabaseTree.vue
index aa4203aed1..b199c798ea 100644
--- a/frontend/src/components/SchemaEditor/DatabaseTree.vue
+++ b/frontend/src/components/SchemaEditor/DatabaseTree.vue
@@ -10,9 +10,14 @@
</template>
</NInput>
</div>
- <div ref="treeRef" class="schema-editor-database-tree pb-2 h-auto">
+ <div
+ class="schema-editor-database-tree pb-2 overflow-y-auto h-full text-sm"
+ >
<NTree
+ ref="treeRef"
block-line
+ virtual-scroll
+ style="height: 100%"
:data="treeDataRef"
:pattern="searchPattern"
:render-prefix="renderPrefix"
@@ -59,7 +64,6 @@ import { escape, head, isUndefined } from "lodash-es";
import { TreeOption, NEllipsis, NInput, NDropdown, NTree } from "naive-ui";
import { computed, onMounted, watch, ref, h, reactive, nextTick } from "vue";
import { useI18n } from "vue-i18n";
-import scrollIntoView from "scroll-into-view-if-needed";
import DatabaseIcon from "~icons/heroicons-outline/circle-stack";
import SchemaIcon from "~icons/heroicons-outline/view-columns";
import TableIcon from "~icons/heroicons-outline/table-cells";
@@ -152,7 +156,7 @@ const contextMenu = reactive<TreeContextMenu>({
clientY: 0,
treeNode: undefined,
});
-const treeRef = ref();
+const treeRef = ref<InstanceType<typeof NTree>>();
const searchPattern = ref("");
const expandedKeysRef = ref<string[]>([]);
const selectedKeysRef = ref<string[]>([]);
@@ -437,12 +441,9 @@ watch(
if (state.shouldRelocateTreeNode) {
nextTick(() => {
- const element = treeRef.value?.querySelector(".n-tree-node--selected");
- if (element) {
- scrollIntoView(element, {
- scrollMode: "if-needed",
- });
- }
+ treeRef.value?.scrollTo({
+ key: selectedKeysRef.value[0],
+ });
});
}
}
@@ -820,7 +821,6 @@ const handleExpandedKeysChange = (expandedKeys: string[]) => {
<style scoped>
.schema-editor-database-tree {
- @apply overflow-y-auto;
max-height: calc(100% - 48px);
}
</style>