Skip to content

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

chore: use `NDataTable` for table list (#9436)

boojack4fa48462087d
diff --git a/frontend/src/components/DatabaseOverviewPanel.vue b/frontend/src/components/DatabaseOverviewPanel.vue
index f550ecc0da..eb5e16e283 100644
--- a/frontend/src/components/DatabaseOverviewPanel.vue
+++ b/frontend/src/components/DatabaseOverviewPanel.vue
@@ -105,7 +105,7 @@
<span v-else>{{ $t("db.tables") }}</span>
</div>
- <TableTable
+ <TableDataTable
:database="database"
:schema-name="state.selectedSchemaName"
:table-list="tableList"
@@ -173,7 +173,7 @@ import { DatabaseMetadataView } from "@/types/proto/v1/database_service";
import { BBTableSectionDataSource } from "../bbkit/types";
import AnomalyTable from "../components/AnomalyCenter/AnomalyTable.vue";
import FunctionTable from "../components/FunctionTable.vue";
-import TableTable from "../components/TableTable.vue";
+import TableDataTable from "../components/TableDataTable.vue";
import ViewTable from "../components/ViewTable.vue";
import { ComposedDatabase, DataSource } from "../types";
import StreamTable from "./StreamTable.vue";
diff --git a/frontend/src/components/TableDataTable.vue b/frontend/src/components/TableDataTable.vue
new file mode 100644
index 0000000000..4431660f4b
--- /dev/null
+++ b/frontend/src/components/TableDataTable.vue
@@ -0,0 +1,189 @@
+<template>
+ <NDataTable
+ :columns="columns"
+ :data="mixedTableList"
+ :row-props="rowProps"
+ :max-height="640"
+ :virtual-scroll="true"
+ :striped="true"
+ :bordered="true"
+ :bottom-bordered="true"
+ />
+
+ <TableDetailDrawer
+ :show="!!state.selectedTableName"
+ :database-name="database.name"
+ :schema-name="schemaName"
+ :table-name="state.selectedTableName ?? ''"
+ :classification-config="classificationConfig"
+ @dismiss="state.selectedTableName = undefined"
+ />
+</template>
+
+<script lang="ts" setup>
+import { DataTableColumn, NDataTable } from "naive-ui";
+import { computed, PropType, reactive, onMounted, h } from "vue";
+import { useI18n } from "vue-i18n";
+import { useRoute } from "vue-router";
+import EllipsisText from "@/components/EllipsisText.vue";
+import ClassificationLevelBadge from "@/components/SchemaTemplate/ClassificationLevelBadge.vue";
+import { useSettingV1Store } from "@/store/modules";
+import { ComposedDatabase } from "@/types";
+import { Engine } from "@/types/proto/v1/common";
+import { TableMetadata } from "@/types/proto/v1/database_service";
+import { bytesToString, isGhostTable } from "@/utils";
+import TableDetailDrawer from "./TableDetailDrawer.vue";
+
+type LocalState = {
+ selectedTableName?: string;
+};
+
+const props = defineProps({
+ database: {
+ required: true,
+ type: Object as PropType<ComposedDatabase>,
+ },
+ schemaName: {
+ type: String,
+ default: "",
+ },
+ tableList: {
+ required: true,
+ type: Object as PropType<TableMetadata[]>,
+ },
+});
+
+const { t } = useI18n();
+const route = useRoute();
+const state = reactive<LocalState>({});
+const settingStore = useSettingV1Store();
+
+onMounted(() => {
+ const table = route.query.table as string;
+ if (table) {
+ state.selectedTableName = table;
+ }
+});
+
+const classificationConfig = computed(() => {
+ return settingStore.getProjectClassification(
+ props.database.projectEntity.dataClassificationConfigId
+ );
+});
+
+const engine = computed(() => props.database.instanceEntity.engine);
+
+const isPostgres = computed(
+ () => engine.value === Engine.POSTGRES || engine.value === Engine.RISINGWAVE
+);
+
+const hasSchemaProperty = computed(() => {
+ return (
+ isPostgres.value ||
+ engine.value === Engine.SNOWFLAKE ||
+ engine.value === Engine.ORACLE ||
+ engine.value === Engine.DM ||
+ engine.value === Engine.MSSQL
+ );
+});
+
+const hasClassificationProperty = computed(() => {
+ return (
+ (engine.value === Engine.MYSQL || engine.value === Engine.POSTGRES) &&
+ classificationConfig.value
+ );
+});
+
+const hasEngineProperty = computed(() => {
+ return !isPostgres.value;
+});
+
+const columns = computed(() => {
+ const columns: (DataTableColumn<TableMetadata> & { hide?: boolean })[] = [
+ {
+ key: "schema",
+ title: t("common.schema"),
+ hide: !hasSchemaProperty.value,
+ render: () => {
+ return props.schemaName;
+ },
+ },
+ {
+ key: "name",
+ title: t("common.name"),
+ render: (row) => {
+ return row.name;
+ },
+ },
+ {
+ key: "engine",
+ title: t("database.engine"),
+ hide: !hasEngineProperty.value,
+ render: (row) => {
+ return row.engine;
+ },
+ },
+ {
+ key: "classification",
+ title: t("database.classification.self"),
+ hide: !hasClassificationProperty.value,
+ render: (table) => {
+ return h(ClassificationLevelBadge, {
+ level: table.classification,
+ config: classificationConfig.value,
+ });
+ },
+ },
+ {
+ key: "rowCountEst",
+ title: t("database.row-count-est"),
+ render: (row) => {
+ return String(row.rowCount);
+ },
+ },
+ {
+ key: "dataSize",
+ title: t("database.data-size"),
+ render: (row) => {
+ return bytesToString(row.dataSize.toNumber());
+ },
+ },
+ {
+ key: "indexSize",
+ title: t("database.index-size"),
+ render: (row) => {
+ return bytesToString(row.indexSize.toNumber());
+ },
+ },
+ {
+ key: "comment",
+ title: t("database.comment"),
+ render: (row) => {
+ return h(EllipsisText, { text: row.comment });
+ },
+ },
+ ];
+
+ return columns.filter((column) => !column.hide);
+});
+
+const rowProps = (row: TableMetadata) => {
+ return {
+ onClick: () => {
+ state.selectedTableName = row.name;
+ },
+ };
+};
+
+const regularTableList = computed(() =>
+ props.tableList.filter((table) => !isGhostTable(table))
+);
+const reservedTableList = computed(() =>
+ props.tableList.filter((table) => isGhostTable(table))
+);
+
+const mixedTableList = computed(() => {
+ const tableList = [...regularTableList.value, ...reservedTableList.value];
+ return tableList;
+});
+</script>
diff --git a/frontend/src/components/TableTable.vue b/frontend/src/components/TableTable.vue
deleted file mode 100644
index 9d7b66af3a..0000000000
--- a/frontend/src/components/TableTable.vue
+++ /dev/null
@@ -1,217 +0,0 @@
-<template>
- <BBTable
- :column-list="columnList"
- :data-source="mixedTableList"
- :show-header="true"
- :left-bordered="true"
- :right-bordered="true"
- :row-clickable="true"
- :custom-footer="true"
- @click-row="clickTable"
- >
- <template #body="{ rowData: table }: { rowData: TableMetadata }">
- <BBTableCell v-if="hasSchemaProperty" :left-padding="4" class="w-8">
- {{ schemaName }}
- </BBTableCell>
- <BBTableCell :left-padding="hasSchemaProperty ? 2 : 4" class="w-16">
- <div class="flex items-center space-x-2">
- <EllipsisText>{{ table.name }}</EllipsisText>
- <BBBadge
- v-if="isGhostTable(table)"
- text="gh-ost"
- :can-remove="false"
- class="text-xs whitespace-nowrap"
- />
- </div>
- </BBTableCell>
- <BBTableCell v-if="hasEngineProperty" class="w-8">
- {{ table.engine }}
- </BBTableCell>
- <BBTableCell v-if="hasClassificationProperty" class="w-8">
- <ClassificationLevelBadge
- :classification="table.classification"
- :classification-config="classificationConfig"
- />
- </BBTableCell>
- <BBTableCell class="w-8">
- {{ table.rowCount }}
- </BBTableCell>
- <BBTableCell class="w-8">
- {{ bytesToString(table.dataSize.toNumber()) }}
- </BBTableCell>
- <BBTableCell class="w-8">
- {{ bytesToString(table.indexSize.toNumber()) }}
- </BBTableCell>
- <BBTableCell class="w-16 break-all">
- {{ table.userComment }}
- </BBTableCell>
- </template>
-
- <template v-if="hasReservedTables && !state.showReservedTableList" #footer>
- <tfoot>
- <tr>
- <td :colspan="columnList.length" class="p-0">
- <div
- class="flex items-center justify-center cursor-pointer hover:bg-gray-200 py-2 text-gray-400 text-sm"
- @click="state.showReservedTableList = true"
- >
- {{ $t("database.show-reserved-tables") }}
- </div>
- </td>
- </tr>
- </tfoot>
- </template>
- </BBTable>
-
- <TableDetailDrawer
- :show="!!state.selectedTableName"
- :database-name="database.name"
- :schema-name="schemaName"
- :table-name="state.selectedTableName ?? ''"
- :classification-config="classificationConfig"
- @dismiss="state.selectedTableName = undefined"
- />
-</template>
-
-<script lang="ts" setup>
-import { computed, PropType, reactive, onMounted } from "vue";
-import { useI18n } from "vue-i18n";
-import { useRoute } from "vue-router";
-import { BBTableColumn } from "@/bbkit";
-import EllipsisText from "@/components/EllipsisText.vue";
-import { useSettingV1Store } from "@/store/modules";
-import { ComposedDatabase } from "@/types";
-import { Engine } from "@/types/proto/v1/common";
-import { TableMetadata } from "@/types/proto/v1/database_service";
-import { bytesToString, isGhostTable } from "@/utils";
-import TableDetailDrawer from "./TableDetailDrawer.vue";
-
-type LocalState = {
- showReservedTableList: boolean;
- selectedTableName?: string;
-};
-
-const props = defineProps({
- database: {
- required: true,
- type: Object as PropType<ComposedDatabase>,
- },
- schemaName: {
- type: String,
- default: "",
- },
- tableList: {
- required: true,
- type: Object as PropType<TableMetadata[]>,
- },
-});
-
-const { t } = useI18n();
-const route = useRoute();
-const state = reactive<LocalState>({
- showReservedTableList: false,
-});
-const settingStore = useSettingV1Store();
-
-onMounted(() => {
- const table = route.query.table as string;
- if (table) {
- state.selectedTableName = table;
- }
-});
-
-const classificationConfig = computed(() => {
- return settingStore.getProjectClassification(
- props.database.projectEntity.dataClassificationConfigId
- );
-});
-
-const engine = computed(() => props.database.instanceEntity.engine);
-
-const isPostgres = computed(
- () => engine.value === Engine.POSTGRES || engine.value === Engine.RISINGWAVE
-);
-
-const hasSchemaProperty = computed(() => {
- return (
- isPostgres.value ||
- engine.value === Engine.SNOWFLAKE ||
- engine.value === Engine.ORACLE ||
- engine.value === Engine.DM ||
- engine.value === Engine.MSSQL
- );
-});
-
-const hasClassificationProperty = computed(() => {
- return (
- (engine.value === Engine.MYSQL || engine.value === Engine.POSTGRES) &&
- classificationConfig.value
- );
-});
-
-const hasEngineProperty = computed(() => {
- return !isPostgres.value;
-});
-
-const columnList = computed(() => {
- const SCHEMA: BBTableColumn = {
- title: t("common.schema"),
- };
- const NAME: BBTableColumn = {
- title: t("common.name"),
- };
- const ENGINE: BBTableColumn = {
- title: t("database.engine"),
- };
- const CLASSIFICATION: BBTableColumn = {
- title: t("database.classification.self"),
- };
- const ROW_COUNT_EST: BBTableColumn = {
- title: t("database.row-count-est"),
- };
- const DATA_SIZE: BBTableColumn = {
- title: t("database.data-size"),
- };
- const INDEX_SIZE: BBTableColumn = {
- title: t("database.index-size"),
- };
- const COMMENT: BBTableColumn = {
- title: t("database.comment"),
- };
- const columns: BBTableColumn[] = [];
- if (hasSchemaProperty.value) {
- columns.push(SCHEMA);
- }
- columns.push(NAME);
- if (hasEngineProperty.value) {
- columns.push(ENGINE);
- }
- if (hasClassificationProperty.value) {
- columns.push(CLASSIFICATION);
- }
- columns.push(ROW_COUNT_EST, DATA_SIZE, INDEX_SIZE, COMMENT);
-
- return columns;
-});
-
-const regularTableList = computed(() =>
- props.tableList.filter((table) => !isGhostTable(table))
-);
-const reservedTableList = computed(() =>
- props.tableList.filter((table) => isGhostTable(table))
-);
-const hasReservedTables = computed(() => reservedTableList.value.length > 0);
-
-const mixedTableList = computed(() => {
- const tableList = [...regularTableList.value];
- if (state.showReservedTableList) {
- tableList.push(...reservedTableList.value);
- }
-
- return tableList;
-});
-
-const clickTable = (_: number, row: number, e: MouseEvent) => {
- state.selectedTableName = mixedTableList.value[row].name;
-};
-</script>