Skip to content

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

feat(sql-editor): implement table list and column list with virtual list (#7647)

Liu Jib0f6e2b18bf9
diff --git a/frontend/src/views/sql-editor/AsidePanel/AsidePanel.vue b/frontend/src/views/sql-editor/AsidePanel/AsidePanel.vue
index 53a44d39d0..ce9f4803c9 100644
--- a/frontend/src/views/sql-editor/AsidePanel/AsidePanel.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/AsidePanel.vue
@@ -2,7 +2,8 @@
<div class="aside-panel h-full">
<NTabs
v-model:value="tabStore.asidePanelTab"
- class="h-full"
+ class="h-full overflow-hidden"
+ pane-style="height: calc(100% - 33px); padding: 0 4px;"
:tabs-padding="8"
>
<NTabPane name="databases" :tab="$t('common.databases')">
@@ -11,6 +12,7 @@
type="segment"
size="small"
class="h-full"
+ pane-style="height: calc(100% - 35px); padding: 0;"
>
<NTabPane name="projects" :tab="$t('common.projects')">
<Splitpanes
@@ -63,6 +65,7 @@
size="small"
type="segment"
class="h-full"
+ pane-style="height: calc(100% - 35px); padding: 0;"
>
<NTabPane name="my" :tab="$t('sheet.mine')">
<SheetList view="my" />
@@ -144,10 +147,3 @@ watchEffect(() => {
}
});
</script>
-
-<style scoped>
-.aside-panel .n-tab-pane {
- height: calc(100% - 40px);
- @apply pt-0;
-}
-</style>
diff --git a/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue b/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue
index 86493da181..33473e5e3a 100644
--- a/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue
@@ -1,7 +1,7 @@
<template>
<div
v-if="connectionTreeStore.tree.state === ConnectionTreeState.LOADED"
- class="databases-tree p-2 space-y-2 h-full flex flex-col"
+ class="databases-tree pt-2 px-0.5 gap-y-2 h-full flex flex-col"
:class="connectionTreeStore.tree.mode"
>
<div class="databases-tree--input">
diff --git a/frontend/src/views/sql-editor/AsidePanel/QueryHistoryContainer.vue b/frontend/src/views/sql-editor/AsidePanel/QueryHistoryContainer.vue
index 1f4a40db33..d594d47186 100644
--- a/frontend/src/views/sql-editor/AsidePanel/QueryHistoryContainer.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/QueryHistoryContainer.vue
@@ -1,7 +1,7 @@
<!-- eslint-disable vue/no-v-html -->
<template>
<div
- class="relative p-2 space-y-2 w-full h-full flex flex-col justify-start items-start"
+ class="relative py-2 px-0.5 w-full h-full flex flex-col justify-start items-start"
>
<div class="w-full">
<NInput
@@ -18,7 +18,7 @@
<div
v-for="history in data"
:key="history.name"
- class="w-full px-1 pr-2 py-2 border-b flex flex-col justify-start items-start cursor-pointer hover:bg-gray-50"
+ class="w-full pl-1 pr-2 py-1 border-b flex flex-col justify-start items-start cursor-pointer hover:bg-gray-50"
@click="handleQueryHistoryClick(history)"
>
<div class="w-full flex flex-row justify-between items-center">
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPanel/ColumnList.vue b/frontend/src/views/sql-editor/AsidePanel/SchemaPanel/ColumnList.vue
new file mode 100644
index 0000000000..b2d64f518e
--- /dev/null
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPanel/ColumnList.vue
@@ -0,0 +1,42 @@
+<template>
+ <div class="overflow-hidden">
+ <VirtualList
+ :items="table.columns"
+ :key-field="`name`"
+ :item-resizable="true"
+ :item-size="24"
+ >
+ <template #default="{ item: column }: VirtualListItem">
+ <div class="flex items-start px-4">
+ <div
+ class="text-sm leading-6 text-gray-600whitespace-pre-wrap break-words flex-2 min-w-[4rem]"
+ >
+ {{ column.name }}
+ </div>
+ <div
+ class="shrink-0 text-right text-sm leading-6 text-gray-400 overflow-x-hidden whitespace-nowrap flex-1 min-w-[4rem]"
+ >
+ {{ column.type }}
+ </div>
+ </div>
+ </template>
+ </VirtualList>
+ </div>
+</template>
+
+<script setup lang="ts">
+import { VirtualList } from "vueuc";
+import {
+ ColumnMetadata,
+ TableMetadata,
+} from "@/types/proto/v1/database_service";
+
+export type VirtualListItem = {
+ item: ColumnMetadata;
+ index: number;
+};
+
+defineProps<{
+ table: TableMetadata;
+}>();
+</script>
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPanel/DatabaseSchema.vue b/frontend/src/views/sql-editor/AsidePanel/SchemaPanel/DatabaseSchema.vue
index 0d90a03233..07472a388f 100644
--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPanel/DatabaseSchema.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPanel/DatabaseSchema.vue
@@ -33,23 +33,12 @@
</div>
</div>
- <div class="flex-1 p-1 overflow-y-auto flex flex-col">
- <template v-for="(schema, i) in availableSchemas" :key="i">
- <div v-for="(table, j) in schema.tables" :key="j" class="text-sm">
- <div
- class="flex items-center h-6 px-1 text-gray-600 whitespace-pre-wrap break-words rounded-sm"
- :class="
- rowClickable && ['hover:bg-[rgb(243,243,245)]', 'cursor-pointer']
- "
- @click="handleClickTable(schema, table)"
- >
- <heroicons-outline:table class="h-4 w-4 mr-1" />
- <span v-if="schema.name">{{ schema.name }}.</span>
- <span>{{ table.name }}</span>
- </div>
- </div>
- </template>
- </div>
+ <TableList
+ class="flex-1 w-full py-1"
+ :schema-list="availableSchemas"
+ :row-clickable="rowClickable"
+ @select-table="(schema, table) => $emit('select-table', schema, table)"
+ />
</div>
</template>
@@ -57,12 +46,12 @@
import { computed } from "vue";
import { useCurrentUserV1 } from "@/store";
import type { ComposedDatabase } from "@/types";
-import type {
+import { Engine } from "@/types/proto/v1/common";
+import {
DatabaseMetadata,
SchemaMetadata,
TableMetadata,
-} from "@/types/proto/store/database";
-import { Engine } from "@/types/proto/v1/common";
+} from "@/types/proto/v1/database_service";
import {
databaseV1Slug,
instanceV1HasAlterSchema,
@@ -71,6 +60,7 @@ import {
import AlterSchemaButton from "./AlterSchemaButton.vue";
import ExternalLinkButton from "./ExternalLinkButton.vue";
import SchemaDiagramButton from "./SchemaDiagramButton.vue";
+import TableList from "./TableList.vue";
const props = defineProps<{
database: ComposedDatabase;
@@ -118,11 +108,4 @@ const handleClickHeader = () => {
if (!props.headerClickable) return;
emit("click-header");
};
-
-const handleClickTable = (schema: SchemaMetadata, table: TableMetadata) => {
- if (!rowClickable.value) {
- return;
- }
- emit("select-table", schema, table);
-};
</script>
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPanel/SchemaDiagramButton.vue b/frontend/src/views/sql-editor/AsidePanel/SchemaPanel/SchemaDiagramButton.vue
index 54ed6c0efd..fdb92124b2 100644
--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPanel/SchemaDiagramButton.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPanel/SchemaDiagramButton.vue
@@ -36,7 +36,7 @@ import { NButton } from "naive-ui";
import { reactive } from "vue";
import { SchemaDiagram, SchemaDiagramIcon } from "@/components/SchemaDiagram";
import type { ComposedDatabase } from "@/types";
-import type { DatabaseMetadata } from "@/types/proto/store/database";
+import type { DatabaseMetadata } from "@/types/proto/v1/database_service";
type LocalState = {
show: boolean;
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPanel/SchemaPanel.vue b/frontend/src/views/sql-editor/AsidePanel/SchemaPanel/SchemaPanel.vue
index c2ad92ddb8..0a0f3b26e1 100644
--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPanel/SchemaPanel.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPanel/SchemaPanel.vue
@@ -41,7 +41,7 @@ import {
DatabaseMetadata,
SchemaMetadata,
TableMetadata,
-} from "@/types/proto/store/database";
+} from "@/types/proto/v1/database_service";
import DatabaseSchema from "./DatabaseSchema.vue";
import TableSchema from "./TableSchema.vue";
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPanel/TableList.vue b/frontend/src/views/sql-editor/AsidePanel/SchemaPanel/TableList.vue
new file mode 100644
index 0000000000..68e8c08dfd
--- /dev/null
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPanel/TableList.vue
@@ -0,0 +1,74 @@
+<template>
+ <div class="flex flex-col overflow-hidden">
+ <VirtualList
+ :items="flattenTableList"
+ :key-field="`key`"
+ :item-resizable="true"
+ :item-size="24"
+ >
+ <template
+ #default="{ item: { key, schema, table }, index }: VirtualListItem"
+ >
+ <div class="text-sm leading-6 px-2" :data-key="key" :data-index="index">
+ <div
+ class="flex items-center text-gray-600 whitespace-pre-wrap break-words rounded-sm"
+ :class="
+ rowClickable && ['hover:bg-[rgb(243,243,245)]', 'cursor-pointer']
+ "
+ @click="handleClickTable(schema, table)"
+ >
+ <heroicons-outline:table class="h-4 w-4 mr-1 shrink-0" />
+ <span v-if="schema.name">{{ schema.name }}.</span>
+ <span>{{ table.name }}</span>
+ </div>
+ </div>
+ </template>
+ </VirtualList>
+ </div>
+</template>
+
+<script setup lang="ts">
+import { computed } from "vue";
+import { VirtualList } from "vueuc";
+import {
+ SchemaMetadata,
+ TableMetadata,
+} from "@/types/proto/v1/database_service";
+
+export type SchemaAndTable = {
+ key: string;
+ schema: SchemaMetadata;
+ table: TableMetadata;
+};
+
+export type VirtualListItem = {
+ item: SchemaAndTable;
+ index: number;
+};
+
+const props = defineProps<{
+ schemaList: SchemaMetadata[];
+ rowClickable?: boolean;
+}>();
+
+const emit = defineEmits<{
+ (e: "select-table", schema: SchemaMetadata, table: TableMetadata): void;
+}>();
+
+const flattenTableList = computed(() => {
+ return props.schemaList.flatMap((schema) => {
+ return schema.tables.map<SchemaAndTable>((table) => ({
+ key: `${schema.name}.${table.name}`,
+ schema,
+ table,
+ }));
+ });
+});
+
+const handleClickTable = (schema: SchemaMetadata, table: TableMetadata) => {
+ if (!props.rowClickable) {
+ return;
+ }
+ emit("select-table", schema, table);
+};
+</script>
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPanel/TableSchema.vue b/frontend/src/views/sql-editor/AsidePanel/SchemaPanel/TableSchema.vue
index 53a2c35761..b5d10f2eec 100644
--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPanel/TableSchema.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPanel/TableSchema.vue
@@ -30,23 +30,7 @@
</div>
</div>
- <div
- class="grid py-1 pl-4 pr-4 overflow-y-auto gap-x-1"
- style="grid-template-columns: minmax(4rem, 2fr) minmax(4rem, 1fr)"
- >
- <template v-for="(column, index) in table.columns" :key="index">
- <div
- class="text-sm leading-6 text-gray-600whitespace-pre-wrap break-words"
- >
- {{ column.name }}
- </div>
- <div
- class="text-right text-sm leading-6 text-gray-400 overflow-x-hidden whitespace-nowrap"
- >
- {{ column.type }}
- </div>
- </template>
- </div>
+ <ColumnList :table="table" class="w-full flex-1 py-1" />
</div>
</template>
@@ -57,9 +41,10 @@ import type {
DatabaseMetadata,
SchemaMetadata,
TableMetadata,
-} from "@/types/proto/store/database";
+} from "@/types/proto/v1/database_service";
import { databaseV1Slug } from "@/utils";
import AlterSchemaButton from "./AlterSchemaButton.vue";
+import ColumnList from "./ColumnList.vue";
import ExternalLinkButton from "./ExternalLinkButton.vue";
const props = defineProps<{
diff --git a/frontend/src/views/sql-editor/AsidePanel/SheetList/SheetList.vue b/frontend/src/views/sql-editor/AsidePanel/SheetList/SheetList.vue
index f683892730..e5ef9fa9a5 100644
--- a/frontend/src/views/sql-editor/AsidePanel/SheetList/SheetList.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/SheetList/SheetList.vue
@@ -1,6 +1,6 @@
<template>
- <div class="flex flex-col h-full overflow-hidden">
- <div class="px-2 py-2 gap-x-1 flex items-center">
+ <div class="flex flex-col h-full px-0.5 pt-2 gap-y-2">
+ <div class="flex items-center gap-x-1">
<NInput
v-model:value="keyword"
size="small"
@@ -12,7 +12,11 @@
<heroicons-outline:search class="h-5 w-5 text-gray-300" />
</template>
</NInput>
- <NButton quaternary style="--n-padding: 0 8px" @click="addSheet">
+ <NButton
+ quaternary
+ style="--n-padding: 0 5px; --n-height: 28px"
+ @click="addSheet"
+ >
<template #icon>
<heroicons:plus />
</template>