Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix: database tree in UI editor (#3712)
boojackbe1c77e3a5f9
diff --git a/frontend/src/components/UIEditor/DatabaseTree.vue b/frontend/src/components/UIEditor/DatabaseTree.vueindex 946a466634..ad51b3e5e7 100644--- a/frontend/src/components/UIEditor/DatabaseTree.vue+++ b/frontend/src/components/UIEditor/DatabaseTree.vue@@ -1,5 +1,5 @@<template>- <div class="w-full h-full pr-2 relative overflow-y-hidden">+ <div class="w-full h-full pl-1 pr-2 relative overflow-y-hidden"><div class="w-full sticky top-0 pt-2 h-12 bg-white z-10"><NInputv-model:value="searchPattern"@@ -10,11 +10,7 @@</template></NInput></div>- <div- ref="treeRef"- class="ui-editor-database-tree pb-2 h-auto"- v-bind="$attrs"- >+ <div ref="treeRef" class="ui-editor-database-tree pb-2 h-auto"><n-treeblock-line:data="treeDataRef"@@ -126,6 +122,7 @@ const searchPattern = ref("");const expandedKeysRef = ref<string[]>([]);const selectedKeysRef = ref<string[]>([]);const treeDataRef = ref<TreeNode[]>([]);+const databaseDataLoadedSet = ref<Set<DatabaseId>>(new Set());const databaseList = computed(() => editorStore.databaseList);const tableList = computed(() => editorStore.tableList);@@ -162,9 +159,10 @@ const contextMenuOptions = computed(() => {return [];});-onMounted(() => {+onMounted(async () => {const treeNodeList: TreeNode[] = [];const instanceTreeNodeMap: Map<InstanceId, TreeNodeForInstance> = new Map();+ const databaseTreeNodeList: TreeNodeForDatabase[] = [];for (const database of databaseList.value) {const instance = instanceStore.getInstanceById(database.instanceId);let instanceTreeNode: TreeNodeForInstance;@@ -196,8 +194,16 @@ onMounted(() => {databaseId: database.id,};instanceTreeNode.children?.push(databaseTreeNode);+ databaseTreeNodeList.push(databaseTreeNode);}treeDataRef.value = treeNodeList;++ // When the user selects only one database, it is expanded by default.+ if (databaseTreeNodeList.length === 1) {+ const node = databaseTreeNodeList[0];+ await loadSubTree(node);+ expandedKeysRef.value.push(node.key);+ }});watch(tableList.value, () => {@@ -212,7 +218,9 @@ watch(tableList.value, () => {for (const database of databaseList.value) {const databaseTreeNode = databaseTreeNodeList.find(- (treeNode) => treeNode.databaseId === database.id+ (treeNode) =>+ treeNode.databaseId === database.id &&+ databaseDataLoadedSet.value.has(treeNode.databaseId));if (isUndefined(databaseTreeNode)) {continue;@@ -280,6 +288,18 @@ watch(});+watch(searchPattern, () => {+ for (const treeNode of treeDataRef.value) {+ if (treeNode.type === "instance" && treeNode.children) {+ for (const databaseTreeNode of treeNode.children) {+ if (databaseTreeNode.children === undefined) {+ loadSubTree(databaseTreeNode);+ }+ }+ }+ }+});+// Render prefix icons before label text.const renderPrefix = ({ option: treeNode }: { option: TreeNode }) => {if (treeNode.type === "instance") {@@ -380,30 +400,20 @@ const handleShowDropdown = (e: MouseEvent, treeNode: TreeNode) => {// Dynamic fetching table list when database tree node clicking.const loadSubTree = async (treeNode: TreeNode) => {if (treeNode.type === "database") {- const instanceId = treeNode.instanceId;const databaseId = treeNode.databaseId;+ if (databaseDataLoadedSet.value.has(databaseId)) {+ return;+ }++ databaseDataLoadedSet.value.add(databaseId);const tableList = await editorStore.getOrFetchTableListByDatabaseId(databaseId);- const knownTableList = tableList.filter((table) => table.id !== UNKNOWN_ID);- if (knownTableList.length === 0) {+ if (tableList.length === 0) {treeNode.isLeaf = true;} else {treeNode.isLeaf = false;- treeNode.children = knownTableList.map((table) => {- return {- type: "table",- key: `t-${table.database.id}-${table.id}-${table.name}`,- label: table.name,- children: [],- isLeaf: true,- instanceId: instanceId,- databaseId: databaseId,- tableId: table.id,- table: table,- };- });}}};@@ -411,7 +421,7 @@ const loadSubTree = async (treeNode: TreeNode) => {// Set event handler to tree nodes.const nodeProps = ({ option: treeNode }: { option: TreeNode }) => {return {- async onClick(e: MouseEvent) {+ async onclick(e: MouseEvent) {// Check if clicked on the content part.// And ignore the fold/unfold arrow.if (isDescendantOf(e.target as Element, ".n-tree-node-content")) {@@ -463,7 +473,19 @@ const nodeProps = ({ option: treeNode }: { option: TreeNode }) => {});}},- onContextmenu(e: MouseEvent) {+ ondblclick(e: MouseEvent) {+ e.preventDefault();+ e.stopImmediatePropagation();+ const index = expandedKeysRef.value.findIndex(+ (key) => key === treeNode.key+ );+ if (index >= 0) {+ expandedKeysRef.value.splice(index, 1);+ } else {+ expandedKeysRef.value.push(treeNode.key);+ }+ },+ oncontextmenu(e: MouseEvent) {handleShowDropdown(e, treeNode);},};@@ -473,7 +495,7 @@ const handleContextMenuDropdownSelect = async (key: string) => {const treeNode = contextMenu.treeNode;if (treeNode?.type === "database") {if (key === "create-table") {- await editorStore.getOrFetchTableListByDatabaseId(treeNode.databaseId);+ await loadSubTree(treeNode);const table = editorStore.createNewTable(treeNode.databaseId);editorStore.addTab({id: generateUniqueTabId(),diff --git a/frontend/src/components/UIEditor/TabsContainer.vue b/frontend/src/components/UIEditor/TabsContainer.vueindex c34fc93d05..0cbce2c151 100644--- a/frontend/src/components/UIEditor/TabsContainer.vue+++ b/frontend/src/components/UIEditor/TabsContainer.vue@@ -27,7 +27,7 @@</span><NEllipsisclass="text-sm w-24"- :class="checkTabSaved(tab) ? '' : 'text-yellow-700 italic'"+ :class="getTabComputedClassList(tab)">{{ getTabName(tab) }}</NEllipsis></div>@@ -47,10 +47,11 @@ import { isEqual } from "lodash-es";import { NEllipsis, useDialog } from "naive-ui";import { computed, nextTick, ref, watch } from "vue";import scrollIntoView from "scroll-into-view-if-needed";-import { useUIEditorStore } from "@/store";-import { TabContext, UIEditorTabType } from "@/types";+import { useTableStore, useUIEditorStore } from "@/store";+import { TabContext, UIEditorTabType, UNKNOWN_ID } from "@/types";const editorStore = useUIEditorStore();+const tableStore = useTableStore();const dialog = useDialog();const tabsContainerRef = ref();const tabList = computed(() => {@@ -76,17 +77,25 @@ watch(});-const checkTabSaved = (tab: TabContext) => {- if (tab.type === UIEditorTabType.TabForDatabase) {- // Edit database metadata is not allowed.- return true;- } else if (tab.type === UIEditorTabType.TabForTable) {- if (!isEqual(tab.tableCache, tab.table)) {- return false;+const getTabComputedClassList = (tab: TabContext) => {+ if (tab.type === UIEditorTabType.TabForTable) {+ if (editorStore.droppedTableList.includes(tab.table)) {+ return ["text-red-700", "line-through"];+ }+ if (tab.table.id === UNKNOWN_ID) {+ return ["text-green-700"];+ }++ const originTable = tableStore.getTableByDatabaseIdAndTableId(+ tab.databaseId,+ tab.tableId+ );+ if (!isEqual(tab.table, originTable)) {+ return ["text-yellow-700"];}}- return true;+ return [];};const getTabName = (tab: TabContext) => {diff --git a/frontend/src/store/modules/UIEditor.ts b/frontend/src/store/modules/UIEditor.tsindex cd5470e28b..319e8e1691 100644--- a/frontend/src/store/modules/UIEditor.ts+++ b/frontend/src/store/modules/UIEditor.ts@@ -72,13 +72,6 @@ export const useUIEditorStore = defineStore("UIEditor", {if (tabCache !== undefined) {tab = tabCache;} else {- // Don't show tab for dropped table.- if (tab.type === UIEditorTabType.TabForTable) {- if (this.droppedTableList.includes(tab.table)) {- return;- }- }-this.tabState.tabMap.set(tab.id, tab);}