Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat(schema-diagram): navigation bar (#4441)
Liu Ji8f4a59dd1876
diff --git a/frontend/package.json b/frontend/package.jsonindex fad851656f..2763f4ee61 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -69,7 +69,7 @@"vueuc": "0.4.49"},"devDependencies": {- "@iconify/json": "2.1.159",+ "@iconify/json": "2.2.13","@intlify/vite-plugin-vue-i18n": "6.0.3","@popperjs/core": "2.11.6","@rollup/plugin-yaml": "4.0.1",@@ -112,7 +112,7 @@"tailwindcss": "3.2.1","ts-proto": "^1.136.0","typescript": "4.8.4",- "unplugin-icons": "0.14.13",+ "unplugin-icons": "0.15.2","unplugin-vue-components": "0.22.9","vite": "3.2.2","vitest": "0.24.5",diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yamlindex 3a3f4e2caa..19a8f684e1 100644--- a/frontend/pnpm-lock.yaml+++ b/frontend/pnpm-lock.yaml@@ -3,7 +3,7 @@ lockfileVersion: 5.4specifiers:'@bytebase/vue-kbar': 0.1.8'@codingame/monaco-vscode-api': 1.69.12- '@iconify/json': 2.1.159+ '@iconify/json': 2.2.13'@improbable-eng/grpc-web': ^0.15.0'@intlify/vite-plugin-vue-i18n': 6.0.3'@joe-re/sql-parser': ^1.2.1@@ -87,7 +87,7 @@ specifiers:tailwindcss: 3.2.1ts-proto: ^1.136.0typescript: 4.8.4- unplugin-icons: 0.14.13+ unplugin-icons: 0.15.2unplugin-vue-components: 0.22.9uuid: 9.0.0v-code-diff: 0.3.12@@ -163,7 +163,7 @@ dependencies:vueuc: [email protected]devDependencies:- '@iconify/json': 2.1.159+ '@iconify/json': 2.2.13'@intlify/vite-plugin-vue-i18n': [email protected][email protected]'@popperjs/core': 2.11.6'@rollup/plugin-yaml': [email protected]@@ -206,7 +206,7 @@ devDependencies:tailwindcss: [email protected]ts-proto: 1.136.0typescript: 4.8.4- unplugin-icons: 0.14.13_@[email protected]+ unplugin-icons: 0.15.2_@[email protected]unplugin-vue-components: [email protected][email protected]vite: 3.2.2vitest: 0.24.5@@ -223,14 +223,14 @@ packages:find-up: 5.0.0dev: true- /@antfu/utils/0.5.2:- resolution: {integrity: sha512-CQkeV+oJxUazwjlHD0/3ZD08QWKuGQkhnrKo3e6ly5pd48VUpXbb77q0xMU4+vc2CkJnDS02Eq/M9ugyX20XZA==}- dev: true-/@antfu/utils/0.6.2:resolution: {integrity: sha512-Qdwda+qE1KOKXuM8Gnn09zIJSA293J5putdHBx4J9sdbHzqp5QY4OmH77KgwJoi0PuY+kbddkVVdkSoZ9ruiug==}dev: true+ /@antfu/utils/0.7.2:+ resolution: {integrity: sha512-vy9fM3pIxZmX07dL+VX1aZe7ynZ+YyB0jY+jE6r3hOK6GNY2t6W8rzpFC4tgpbXUYABkFQwgJq2XYXlxbXAI0g==}+ dev: true+/@babel/helper-string-parser/7.19.4:resolution: {integrity: sha512-nHtDoQcuqFmwYNYPz3Rah5ph2p8PFeFCsZk9A/48dPc/rGocJ5J3hAAZ7pb76VWX3fZKu+uEr/FhH5jLx7umrw==}engines: {node: '>=6.9.0'}@@ -408,22 +408,22 @@ packages:resolution: {integrity: sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==}dev: true- /@iconify/json/2.1.159:- resolution: {integrity: sha512-LBJDXNsHMBhBZ2BfN2Es/cB8GmI9+2305biJz/C2riYyUWNIU1BnrM5EzDL4i0FwKq6s7I2C+j2wtBJ3pCeQjA==}+ /@iconify/json/2.2.13:+ resolution: {integrity: sha512-TgTGzEhU2o0gGrkke3hVbkVtZB8EcbCdNR4X6ZbXJsApMuFghS4s+yuEbGHw+mMa3sp40L5qRi7wFU6Q47ysfw==}dependencies:'@iconify/types': 2.0.0- pathe: 0.3.9+ pathe: 1.1.0dev: true/@iconify/types/2.0.0:resolution: {integrity: sha512-+wluvCrRhXrhyOmRDJ3q8mux9JkKy5SJ/v8ol2tu4FVjyYvtEzkc/3pK15ET6RKg4b4w4BmTk1+gsCUhf21Ykg==}dev: true- /@iconify/utils/2.0.1:- resolution: {integrity: sha512-t8IyICk25wgZL4YKn/2kYfjG5MGA6EWZlaUJZ1OEIku4V+kX9V900T5E4HIqS3hLyD6/RJET0zY4vxO9pHLHHw==}+ /@iconify/utils/2.1.0:+ resolution: {integrity: sha512-ouXv1hQfOKq4k3wxQ2OJBYQ2gXBMeFoUCIiORmuUVUNlSq9oOTzQBF3jpFRb0+/P0bnV+RIoHcbZKufZTlJ16g==}dependencies:'@antfu/install-pkg': 0.1.1- '@antfu/utils': 0.5.2+ '@antfu/utils': 0.7.2'@iconify/types': 2.0.0debug: 4.3.4kolorist: 1.6.0@@ -3283,8 +3283,8 @@ packages:engines: {node: '>=8'}dev: true- /pathe/0.3.9:- resolution: {integrity: sha512-6Y6s0vT112P3jD8dGfuS6r+lpa0qqNrLyHPOwvXMnyNTQaYiwgau2DP3aNDsR13xqtGj7rrPo+jFUATpU6/s+g==}+ /pathe/1.1.0:+ resolution: {integrity: sha512-ODbEPR0KKHqECXW1GoxdDb+AZvULmXjVPy4rt+pGo2+TnjJTIPJQSVS6N63n8T2Ip+syHhbn52OewKicV0373w==}dev: true/pathval/1.1.1:@@ -3891,11 +3891,11 @@ packages:engines: {node: '>=4.2.0'}hasBin: true- /unplugin-icons/0.14.13_@[email protected]:- resolution: {integrity: sha512-ZZCw9qZg/zNJeHWicaFYMfsfzMAXOHHnZt5tRxslhPE++/THvg5xGu5AsIRmMCtyNBCpC1Ly1MTb8CZmlqaQTA==}+ /unplugin-icons/0.15.2_@[email protected]:+ resolution: {integrity: sha512-oWTTdLMuqfEYfZcko+KZHDEOIsqT4OeyJB1e4U7luCOo9gto/JLyHkqfbqjmjkjdQqA3DNHS18WOKh5esqQM5g==}peerDependencies:'@svgr/core': '>=5.5.0'- '@vue/compiler-sfc': ^3.0.2+ '@vue/compiler-sfc': ^3.0.2 || ^2.7.0vue-template-compiler: ^2.6.12vue-template-es2015-compiler: ^1.9.0peerDependenciesMeta:@@ -3909,13 +3909,13 @@ packages:optional: truedependencies:'@antfu/install-pkg': 0.1.1- '@antfu/utils': 0.6.2- '@iconify/utils': 2.0.1+ '@antfu/utils': 0.7.2+ '@iconify/utils': 2.1.0'@vue/compiler-sfc': 3.2.41debug: 4.3.4kolorist: 1.6.0local-pkg: 0.4.2- unplugin: 0.10.2+ unplugin: 1.0.1transitivePeerDependencies:- supports-colordev: true@@ -3955,6 +3955,15 @@ packages:webpack-virtual-modules: 0.4.6dev: true+ /unplugin/1.0.1:+ resolution: {integrity: sha512-aqrHaVBWW1JVKBHmGo33T5TxeL0qWzfvjWokObHA9bYmN7eNDkwOxmLjhioHl9878qDFMAaT51XNroRyuz7WxA==}+ dependencies:+ acorn: 8.8.1+ chokidar: 3.5.3+ webpack-sources: 3.2.3+ webpack-virtual-modules: 0.5.0+ dev: true+/update-browserslist-db/[email protected]:resolution: {integrity: sha512-OztqDenkfFkbSG+tRxBeAnCVPckDBcvibKd35yDONx6OU8N7sqgwc7rCbkJ/WcYtVRZ4ba68d6byhC21GFh7sQ==}hasBin: true@@ -4265,6 +4274,10 @@ packages:resolution: {integrity: sha512-5tyDlKLqPfMqjT3Q9TAqf2YqjwmnUleZwzJi1A5qXnlBCdj2AtOJ6wAWdglTIDOPgOiOrXeBeFcsQ8+aGQ6QbA==}dev: true+ /webpack-virtual-modules/0.5.0:+ resolution: {integrity: sha512-kyDivFZ7ZM0BVOUteVbDFhlRt7Ah/CSPwJdi8hBpkK7QLumUqdLtVfm/PX/hkcnrvr0i77fO5+TjZ94Pe+C9iw==}+ dev: true+/which/2.0.2:resolution: {integrity: sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==}engines: {node: '>= 8'}diff --git a/frontend/src/components/SchemaDiagram/Canvas/Canvas.vue b/frontend/src/components/SchemaDiagram/Canvas/Canvas.vueindex 9a9d1e935a..4ae8059e4d 100644--- a/frontend/src/components/SchemaDiagram/Canvas/Canvas.vue+++ b/frontend/src/components/SchemaDiagram/Canvas/Canvas.vue@@ -58,7 +58,7 @@ import { NButtonGroup, NButton } from "naive-ui";import Square2x2 from "~icons/heroicons-outline/squares-2x2";import { useSchemaDiagramContext } from "../common";import ZoomButton from "./ZoomButton.vue";-import { useDragCanvas, useFitView } from "./composables";+import { useDragCanvas, useFitView, useSetCenter } from "./composables";import DummyCanvas from "./DummyCanvas.vue";import { pushNotification } from "@/store";import { ZOOM_RANGE } from "./const";@@ -73,6 +73,7 @@ const { database, busy, zoom, position } = useSchemaDiagramContext();const handleFitView = useFitView(canvas);const { handleZoom } = useDragCanvas(canvas);+useSetCenter(canvas);const renderDummy = () => {return slots["desktop"]?.();diff --git a/frontend/src/components/SchemaDiagram/Canvas/DummyCanvas.vue b/frontend/src/components/SchemaDiagram/Canvas/DummyCanvas.vueindex 0c270dffc8..dbbad06076 100644--- a/frontend/src/components/SchemaDiagram/Canvas/DummyCanvas.vue+++ b/frontend/src/components/SchemaDiagram/Canvas/DummyCanvas.vue@@ -40,10 +40,10 @@import { pushNotification } from "@/store";import { computed, defineComponent, nextTick, PropType, ref, VNode } from "vue";+import { minmax } from "@/utils";import {calcBBox,fitBBox,- minmax,provideSchemaDiagramContext,useSchemaDiagramContext,} from "../common";diff --git a/frontend/src/components/SchemaDiagram/Canvas/composables/index.ts b/frontend/src/components/SchemaDiagram/Canvas/composables/index.tsindex fdfb7fc3bf..504da6ac93 100644--- a/frontend/src/components/SchemaDiagram/Canvas/composables/index.ts+++ b/frontend/src/components/SchemaDiagram/Canvas/composables/index.ts@@ -1,2 +1,3 @@export * from "./useDragCanvas";export * from "./useFitView";+export * from "./useSetCenter";diff --git a/frontend/src/components/SchemaDiagram/Canvas/composables/useDragCanvas.ts b/frontend/src/components/SchemaDiagram/Canvas/composables/useDragCanvas.tsindex 6a2d009e3d..47eed0f2e5 100644--- a/frontend/src/components/SchemaDiagram/Canvas/composables/useDragCanvas.ts+++ b/frontend/src/components/SchemaDiagram/Canvas/composables/useDragCanvas.ts@@ -5,7 +5,7 @@ import normalizeWheel from "normalize-wheel";import type { Point } from "../../types";import { ZOOM_RANGE } from "../const";import { useDraggable, useSchemaDiagramContext } from "../../common";-import { minmax } from "@/utils/math";+import { minmax } from "@/utils";export const useDragCanvas = (canvas: Ref<Element | undefined>) => {const { zoom, position, panning } = useSchemaDiagramContext();diff --git a/frontend/src/components/SchemaDiagram/Canvas/composables/useSetCenter.ts b/frontend/src/components/SchemaDiagram/Canvas/composables/useSetCenter.tsnew file mode 100644index 0000000000..57526caaca--- /dev/null+++ b/frontend/src/components/SchemaDiagram/Canvas/composables/useSetCenter.ts@@ -0,0 +1,48 @@+import { type Ref } from "vue";++import type { CenterTarget, CenterTargetType, Rect } from "../../types";+import { useSchemaDiagramContext } from "../../common";+import { fitView } from "../libs/fitView";+import { minmax } from "@/utils";+import { ZOOM_RANGE } from "../const";++export const useSetCenter = (canvas: Ref<Element | undefined>) => {+ const { position, zoom, events, rectOfTable } = useSchemaDiagramContext();++ const setCenter = (rect: Rect, padding: number[]) => {+ if (!canvas.value) {+ return;+ }+ // Fit view according to the center rect with limited zoom range.+ const zoomMin = minmax(zoom.value, ZOOM_RANGE.min, 0.5);+ const zoomMax = minmax(zoom.value, zoomMin, 1);+ const layout = fitView(canvas.value, [rect], padding, [zoomMin, zoomMax]);+ zoom.value = layout.zoom;+ position.value = {+ x: layout.rect.x,+ y: layout.rect.y,+ };+ };++ events.on("set-center", (e) => {+ const { padding = [0, 0, 0, 0] } = e;+ if (isTypedCenterTarget(e, "point")) {+ const center = e.target;+ setCenter({ ...center, width: 0, height: 0 }, padding);+ } else if (isTypedCenterTarget(e, "rect")) {+ setCenter(e.target, padding);+ } else if (isTypedCenterTarget(e, "table")) {+ const rect = rectOfTable(e.target);+ setCenter(rect, padding);+ } else {+ console.assert(false, `unknown set-center target "${e}"`);+ }+ });+};++const isTypedCenterTarget = <T extends CenterTargetType>(+ e: CenterTarget,+ type: T+): e is CenterTarget<T> => {+ return e.type === type;+};diff --git a/frontend/src/components/SchemaDiagram/Canvas/libs/fitView.ts b/frontend/src/components/SchemaDiagram/Canvas/libs/fitView.tsindex ede4bd6484..65b69e7e93 100644--- a/frontend/src/components/SchemaDiagram/Canvas/libs/fitView.ts+++ b/frontend/src/components/SchemaDiagram/Canvas/libs/fitView.ts@@ -1,19 +1,16 @@import type { Geometry, Rect } from "../../types";import { calcBBox, fitBBox } from "../../common";+import { ZOOM_RANGE } from "../const";export const fitView = (canvas: Element,geometries: Geometry[],paddings: number[] = [0, 0, 0, 0], // [T,R,B,L]- zoomRange: number[] = [0.5, 2]+ zoomRange: number[] = [ZOOM_RANGE.min, ZOOM_RANGE.max]) => {const contentBBox = calcBBox(geometries);- if (- contentBBox.width < Number.EPSILON ||- contentBBox.height < Number.EPSILON- ) {- return { zoom: 1, rect: contentBBox };- }+ if (contentBBox.width < Number.EPSILON) contentBBox.width = Number.EPSILON;+ if (contentBBox.height < Number.EPSILON) contentBBox.height = Number.EPSILON;const canvasBBox = canvas.getBoundingClientRect();const [paddingTop, paddingRight, paddingBottom, paddingLeft] = paddings;diff --git a/frontend/src/components/SchemaDiagram/Navigator/Navigator.vue b/frontend/src/components/SchemaDiagram/Navigator/Navigator.vuenew file mode 100644index 0000000000..6381f39c6f--- /dev/null+++ b/frontend/src/components/SchemaDiagram/Navigator/Navigator.vue@@ -0,0 +1,50 @@+<template>+ <div class="relative h-full">+ <div+ class="h-full bg-white overflow-hidden border-y border-gray-200 flex flex-col transition-all"+ :class="[state.expand ? 'w-60 shadow border-l' : 'w-0']"+ >+ <div class="p-1">+ <NInput+ v-model:value="state.keyword"+ :placeholder="$t('common.search')"+ >+ <template #prefix>+ <heroicons-outline:search class="h-5 w-5 text-gray-300" />+ </template>+ </NInput>+ </div>+ <div class="w-full flex-1 overflow-x-hidden overflow-y-auto p-1 pr-2">+ <Tree :keyword="state.keyword" />+ </div>+ </div>++ <div+ class="absolute rounded-full shadow-lg w-6 h-6 top-[4rem] flex items-center justify-center bg-white hover:bg-control-bg cursor-pointer z-[1] transition-all"+ :class="[state.expand ? 'left-[100%] -translate-x-3' : '-left-3']"+ @click="state.expand = !state.expand"+ >+ <heroicons-outline:chevron-left+ class="w-4 h-4 transition-transform"+ :class="[state.expand ? '' : '-scale-100 translate-x-[3px]']"+ />+ </div>+ </div>+</template>++<script lang="ts" setup>+import { reactive } from "vue";+import { NInput } from "naive-ui";++import Tree from "./Tree.vue";++type LocalState = {+ expand: boolean;+ keyword: string;+};++const state = reactive<LocalState>({+ expand: true,+ keyword: "",+});+</script>diff --git a/frontend/src/components/SchemaDiagram/Navigator/Tree.vue b/frontend/src/components/SchemaDiagram/Navigator/Tree.vuenew file mode 100644index 0000000000..3dbc9a18ee--- /dev/null+++ b/frontend/src/components/SchemaDiagram/Navigator/Tree.vue@@ -0,0 +1,136 @@+<template>+ <NTree+ class="bb-schema-diagram-nav-tree select-none"+ :class="[isFlatTree && 'flat']"+ :data="treeData"+ :block-line="true"+ :pattern="keyword"+ :show-irrelevant-nodes="false"+ :default-expand-all="true"+ :selected-keys="[]"+ :expand-on-click="true"+ :render-label="renderLabel"+ :render-prefix="renderPrefix"+ :node-props="nodeProps"+ />+</template>++<script lang="ts" setup>+import { computed, h } from "vue";+import { NTree, type TreeOption } from "naive-ui";++import { useSchemaDiagramContext } from "../common";+import { TreeNode } from "./types";+import { Label, Prefix } from "./TreeNode";+import { isDescendantOf } from "@/utils";+import { isTypedNode } from "./utils";++const props = withDefaults(+ defineProps<{+ keyword?: string;+ }>(),+ {+ keyword: "",+ }+);++const context = useSchemaDiagramContext();+const { databaseMetadata, events } = context;++const isFlatTree = computed(() => {+ const { schemas } = databaseMetadata.value;+ return schemas.length === 1 && schemas[0].name === "";+});++const treeData = computed(() => {+ const schemaNodeList = databaseMetadata.value.schemas.map<TreeNode<"schema">>(+ (schema) => {+ const children = schema.tables.map<TreeNode<"table">>((table) => {+ return {+ key: table.name,+ label: table.name,+ type: "table",+ data: table,+ isLeaf: true,+ children: [],+ };+ });+ return {+ key: schema.name,+ label: schema.name,+ type: "schema",+ data: schema,+ isLeaf: children.length === 0,+ children,+ };+ }+ );+ if (schemaNodeList.length === 1 && schemaNodeList[0].data.name === "") {+ return schemaNodeList[0].children;+ }+ return schemaNodeList;+});++// dynamic render the highlight keywords+const renderLabel = ({ option }: { option: TreeOption }) => {+ const node = option as any as TreeNode;+ return h(Label, { node, keyword: props.keyword });+};++// Render icons before nodes.+const renderPrefix = ({ option }: { option: TreeOption }) => {+ const node = option as any as TreeNode;+ return h(Prefix, { node });+};++const nodeProps = ({ option }: { option: TreeOption }) => {+ const node = option as TreeNode;+ return {+ onClick(e: MouseEvent) {+ if (node.disabled) return;++ if (isDescendantOf(e.target as Element, ".n-tree-node-content")) {+ // Check if clicked on the content part.+ // And ignore the fold/unfold arrow.+ if (isTypedNode(node, "table")) {+ events.emit("set-center", {+ type: "table",+ target: node.data,+ });+ }+ }+ },+ "data-node-type": node.type,+ };+};+</script>++<style lang="postcss">+.bb-schema-diagram-nav-tree.flat .n-tree-node-switcher {+ @apply !hidden;+}+.bb-schema-diagram-nav-tree .n-tree-node-content {+ @apply !pl-0;+}+.bb-schema-diagram-nav-tree .n-tree-node-content__prefix {+ @apply shrink-0 !mr-1;+}+.bb-schema-diagram-nav-tree.project+ .n-tree-node[data-node-type="project"]+ .n-tree-node-content__prefix {+ @apply hidden;+}+.bb-schema-diagram-nav-tree .n-tree-node-content__text {+ @apply truncate mr-1;+}+.bb-schema-diagram-nav-tree .n-tree-node--pending {+ background-color: transparent !important;+}+.bb-schema-diagram-nav-tree .n-tree-node--pending:hover {+ background-color: var(--n-node-color-hover) !important;+}+.bb-schema-diagram-nav-tree .n-tree-node--selected,+.bb-schema-diagram-nav-tree .n-tree-node--selected:hover {+ background-color: var(--n-node-color-active) !important;+}+</style>diff --git a/frontend/src/components/SchemaDiagram/Navigator/TreeNode/Label.vue b/frontend/src/components/SchemaDiagram/Navigator/TreeNode/Label.vuenew file mode 100644index 0000000000..4c3f231cfb--- /dev/null+++ b/frontend/src/components/SchemaDiagram/Navigator/TreeNode/Label.vue@@ -0,0 +1,37 @@+<template>+ <!-- eslint-disable vue/no-v-html -->+ <span+ class="truncate"+ :data-schema-editor-nav-tree-node-id="id"+ v-html="html"+ />+</template>++<script lang="ts" setup>+import { computed } from "vue";+import { escape } from "lodash-es";++import type { TreeNode } from "../types";+import { getHighlightHTMLByKeyWords } from "@/utils";++const props = defineProps<{+ node: TreeNode;+ keyword: string;+}>();++// render an unique id for every node+// for auto scroll to the node when tab switches+const id = computed(() => {+ const { node } = props;+ return `tree-node-label-${node.type}-${node.id}`;+});++const text = computed(() => {+ const { node } = props;+ return node.data.name;+});++const html = computed(() => {+ return getHighlightHTMLByKeyWords(escape(text.value), escape(props.keyword));+});+</script>diff --git a/frontend/src/components/SchemaDiagram/Navigator/TreeNode/Prefix.vue b/frontend/src/components/SchemaDiagram/Navigator/TreeNode/Prefix.vuenew file mode 100644index 0000000000..c7901b1d98--- /dev/null+++ b/frontend/src/components/SchemaDiagram/Navigator/TreeNode/Prefix.vue@@ -0,0 +1,16 @@+<template>+ <template v-if="node.type === 'schema'">+ <heroicons-outline:rectangle-stack class="w-4 h-4" />+ </template>+ <template v-if="node.type === 'table'">+ <heroicons-outline:table-cells class="w-4 h-4" />+ </template>+</template>++<script lang="ts" setup>+import type { TreeNode } from "../types";++defineProps<{+ node: TreeNode;+}>();+</script>diff --git a/frontend/src/components/SchemaDiagram/Navigator/TreeNode/index.ts b/frontend/src/components/SchemaDiagram/Navigator/TreeNode/index.tsnew file mode 100644index 0000000000..4b063aa525--- /dev/null+++ b/frontend/src/components/SchemaDiagram/Navigator/TreeNode/index.ts@@ -0,0 +1,4 @@+import Label from "./Label.vue";+import Prefix from "./Prefix.vue";++export { Label, Prefix };diff --git a/frontend/src/components/SchemaDiagram/Navigator/types.ts b/frontend/src/components/SchemaDiagram/Navigator/types.tsnew file mode 100644index 0000000000..550fcf93f9--- /dev/null+++ b/frontend/src/components/SchemaDiagram/Navigator/types.ts@@ -0,0 +1,17 @@+import { SchemaMetadata, TableMetadata } from "@/types/proto/store/database";+import type { TreeOption } from "naive-ui";++export type NodeType = "schema" | "table";++type NodeTypeMapping = {+ schema: SchemaMetadata;+ table: TableMetadata;+};++export type TreeNode<T extends NodeType = NodeType> = TreeOption & {+ key: string;+ type: T;+ data: NodeTypeMapping[T];+ isLeaf: boolean;+ children: TreeNode<NodeType>[];+};diff --git a/frontend/src/components/SchemaDiagram/Navigator/utils.ts b/frontend/src/components/SchemaDiagram/Navigator/utils.tsnew file mode 100644index 0000000000..0072852c5f--- /dev/null+++ b/frontend/src/components/SchemaDiagram/Navigator/utils.ts@@ -0,0 +1,8 @@+import type { TreeNode, NodeType } from "./types";++export const isTypedNode = <T extends NodeType>(+ node: TreeNode,+ type: T+): node is TreeNode<T> => {+ return node.type === type;+};diff --git a/frontend/src/components/SchemaDiagram/SchemaDiagram.vue b/frontend/src/components/SchemaDiagram/SchemaDiagram.vueindex c73c7dda9c..ac83fcf2f5 100644--- a/frontend/src/components/SchemaDiagram/SchemaDiagram.vue+++ b/frontend/src/components/SchemaDiagram/SchemaDiagram.vue@@ -1,28 +1,32 @@<template>- <Canvas>- <template #desktop>- <template v-for="(schema, i) in schemaList" :key="`schema-${i}`">- <TableNode- v-for="table in schema.tables"- :key="idOfTable(table)"- :schema="schema"- :table="table"- :class="initialized ? '' : 'invisible'"- />+ <div class="w-full h-full relative overflow-hidden flex">+ <Navigator />++ <Canvas class="flex-1">+ <template #desktop>+ <template v-for="(schema, i) in schemaList" :key="`schema-${i}`">+ <TableNode+ v-for="table in schema.tables"+ :key="idOfTable(table)"+ :schema="schema"+ :table="table"+ :class="initialized ? '' : 'invisible'"+ />+ </template>++ <template v-if="initialized">+ <ForeignKeyLine v-for="(fk, i) in foreignKeys" :key="i" :fk="fk" />+ </template></template>- <template v-if="initialized">- <ForeignKeyLine v-for="(fk, i) in foreignKeys" :key="i" :fk="fk" />- </template>- </template>-- <div- v-if="busy || !initialized"- class="absolute inset-0 bg-white/40 flex items-center justify-center"- >- <BBSpin />- </div>- </Canvas>+ <div+ v-if="busy || !initialized"+ class="absolute inset-0 bg-white/40 flex items-center justify-center"+ >+ <BBSpin />+ </div>+ </Canvas>+ </div></template><script lang="ts" setup>@@ -47,6 +51,7 @@ import {Geometry,} from "./types";import Canvas from "./Canvas";+import Navigator from "./Navigator";import { TableNode, autoLayout, GraphNodeItem, GraphEdgeItem } from "./ER";import { provideSchemaDiagramContext } from "./common";diff --git a/frontend/src/components/SchemaDiagram/common/geometry.ts b/frontend/src/components/SchemaDiagram/common/geometry.tsindex f7d35164cc..2d1b60eb3e 100644--- a/frontend/src/components/SchemaDiagram/common/geometry.ts+++ b/frontend/src/components/SchemaDiagram/common/geometry.ts@@ -1,5 +1,5 @@import type { Geometry, Path, Point, Rect, Size } from "../types";-import { minmax } from "./utils";+import { minmax } from "@/utils";export const pointsOfRect = (rect: Rect): Point[] => {const { x, y, width, height } = rect;diff --git a/frontend/src/components/SchemaDiagram/common/index.ts b/frontend/src/components/SchemaDiagram/common/index.tsindex 852c71aac2..dcf15f1d86 100644--- a/frontend/src/components/SchemaDiagram/common/index.ts+++ b/frontend/src/components/SchemaDiagram/common/index.ts@@ -1,5 +1,4 @@export * from "./context";export * from "./useDraggable";-export * from "./utils";export * from "./geometry";export * from "./schema";diff --git a/frontend/src/components/SchemaDiagram/common/utils.ts b/frontend/src/components/SchemaDiagram/common/utils.tsdeleted file mode 100644index 35b27be1fe..0000000000--- a/frontend/src/components/SchemaDiagram/common/utils.ts+++ /dev/null@@ -1,5 +0,0 @@-export const minmax = (value: number, min: number, max: number) => {- if (value < min) return min;- if (value > max) return max;- return value;-};diff --git a/frontend/src/components/SchemaDiagram/types/context.ts b/frontend/src/components/SchemaDiagram/types/context.tsindex 62ebf4420c..a160393827 100644--- a/frontend/src/components/SchemaDiagram/types/context.ts+++ b/frontend/src/components/SchemaDiagram/types/context.ts@@ -51,5 +51,17 @@ export type SchemaDiagramContext = {column: ColumnMetadata;target: "name" | "type";};+ "set-center": CenterTarget;}>;};++export type CenterTargetType = "table" | "rect" | "point";+export type CenterTarget<T extends CenterTargetType = CenterTargetType> = {+ type: T;+ target: {+ table: TableMetadata;+ rect: Rect;+ point: Point;+ }[T];+ padding?: number[]; // [T,R,B,L]+};