Skip to content

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

fix: data tree re-render (#7173)

boojack50148881c859
diff --git a/frontend/src/components/SchemaDesigner/DatabaseTree.vue b/frontend/src/components/SchemaDesigner/DatabaseTree.vue
index e62f1deabe..c7d230b4af 100644
--- a/frontend/src/components/SchemaDesigner/DatabaseTree.vue
+++ b/frontend/src/components/SchemaDesigner/DatabaseTree.vue
@@ -22,8 +22,9 @@
</div>
<div ref="treeRef" class="schema-editor-database-tree pb-2 h-auto">
<NTree
+ :key="treeKeyRef"
:block-line="true"
- :data="treeDataRef"
+ :data="treeData"
:pattern="searchPattern"
:render-prefix="renderPrefix"
:render-label="renderLabel"
@@ -138,8 +139,53 @@ const treeRef = ref();
const searchPattern = ref("");
const expandedKeysRef = ref<string[]>([]);
const selectedKeysRef = ref<string[]>([]);
-const treeDataRef = ref<TreeNode[]>([]);
+// Trigger re-render when the tree data is changed.
+const treeKeyRef = ref<string>("");
+const treeData = computed(() => {
+ const treeNodeList: TreeNode[] = [];
+ if (engine.value === Engine.MYSQL) {
+ const schema = schemaList.value[0];
+ if (!schema) {
+ return;
+ }
+ for (const table of tableList.value) {
+ const tableTreeNode: TreeNodeForTable = {
+ type: "table",
+ key: `t-${table.id}`,
+ label: table.name,
+ isLeaf: true,
+ schemaId: schema.id,
+ tableId: table.id,
+ };
+ treeNodeList.push(tableTreeNode);
+ }
+ } else {
+ for (const schema of schemaList.value) {
+ const schemaTreeNode: TreeNodeForSchema = {
+ type: "schema",
+ key: `s-${schema.id}`,
+ label: schema.name,
+ isLeaf: false,
+ schemaId: schema.id,
+ };
+ treeNodeList.push(schemaTreeNode);
+ for (const table of schema.tableList) {
+ const tableTreeNode: TreeNodeForTable = {
+ type: "table",
+ key: `t-${schema.id}-${table.id}`,
+ label: table.name,
+ isLeaf: true,
+ schemaId: schema.id,
+ tableId: table.id,
+ };
+ schemaTreeNode.children?.push(tableTreeNode);
+ }
+ }
+ }
+
+ return treeNodeList;
+});
const schemaList = computed(() => editableSchemas.value);
const tableList = computed(() =>
schemaList.value.map((schema) => schema.tableList).flat()
@@ -152,7 +198,7 @@ const contextMenuOptions = computed(() => {
if (treeNode.type === "schema") {
const options = [];
- if (engine === Engine.POSTGRES) {
+ if (engine.value === Engine.POSTGRES) {
const schema = schemaList.value.find(
(schema) => schema.id === treeNode.schemaId
);
@@ -163,12 +209,12 @@ const contextMenuOptions = computed(() => {
options.push({
key: "create-table",
label: t("schema-editor.actions.create-table"),
- disabled: readonly,
+ disabled: readonly.value,
});
options.push({
key: "drop-schema",
label: t("schema-editor.actions.drop-schema"),
- disabled: readonly,
+ disabled: readonly.value,
});
}
return options;
@@ -191,7 +237,7 @@ const contextMenuOptions = computed(() => {
options.push({
key: "drop",
label: t("schema-editor.actions.drop-table"),
- disabled: readonly,
+ disabled: readonly.value,
});
return options;
}
@@ -200,54 +246,13 @@ const contextMenuOptions = computed(() => {
});
watch(
- () => [schemaList.value, tableList.value],
+ () => treeData.value,
() => {
- const treeNodeList: TreeNode[] = [];
- if (engine === Engine.MYSQL) {
- const schema = schemaList.value[0];
- if (!schema) {
- return;
- }
- for (const table of tableList.value) {
- const tableTreeNode: TreeNodeForTable = {
- type: "table",
- key: `t-${table.id}`,
- label: table.name,
- isLeaf: true,
- schemaId: schema.id,
- tableId: table.id,
- };
- treeNodeList.push(tableTreeNode);
- }
- } else {
- for (const schema of schemaList.value) {
- const schemaTreeNode: TreeNodeForSchema = {
- type: "schema",
- key: `s-${schema.id}`,
- label: schema.name,
- isLeaf: false,
- schemaId: schema.id,
- };
- treeNodeList.push(schemaTreeNode);
- for (const table of schema.tableList) {
- const tableTreeNode: TreeNodeForTable = {
- type: "table",
- key: `t-${schema.id}-${table.id}`,
- label: table.name,
- isLeaf: true,
- schemaId: schema.id,
- tableId: table.id,
- };
- schemaTreeNode.children?.push(tableTreeNode);
- }
- }
- }
-
- treeDataRef.value = treeNodeList;
+ treeKeyRef.value = Math.random().toString();
},
{
- immediate: true,
deep: true,
+ immediate: true,
}
);
@@ -341,7 +346,7 @@ const renderSuffix = ({ option: treeNode }: { option: TreeNode }) => {
},
});
if (treeNode.type === "schema") {
- if (engine === Engine.POSTGRES) {
+ if (engine.value === Engine.POSTGRES) {
return icon;
}
} else if (treeNode.type === "table") {
@@ -361,7 +366,7 @@ const handleShowDropdown = (e: MouseEvent, treeNode: TreeNode) => {
};
const handleCreateTable = () => {
- if (engine === Engine.MYSQL) {
+ if (engine.value === Engine.MYSQL) {
const schema = editableSchemas.value[0];
state.tableNameModalContext = {
schemaId: schema.id,
diff --git a/frontend/src/components/SchemaDesigner/Modals/EditColumnForeignKeyModal.vue b/frontend/src/components/SchemaDesigner/Modals/EditColumnForeignKeyModal.vue
index ad3cb3773b..a6a7a2737a 100644
--- a/frontend/src/components/SchemaDesigner/Modals/EditColumnForeignKeyModal.vue
+++ b/frontend/src/components/SchemaDesigner/Modals/EditColumnForeignKeyModal.vue
@@ -132,7 +132,7 @@ const foreignKeyList = computed(() => {
});
const shouldShowSchemaSelector = computed(() => {
- return engine === Engine.POSTGRES;
+ return engine.value === Engine.POSTGRES;
});
const selectedSchema = computed(() => {
diff --git a/frontend/src/components/SchemaDesigner/Modals/TableNameModal.vue b/frontend/src/components/SchemaDesigner/Modals/TableNameModal.vue
index bd6e442f53..ade567a5bd 100644
--- a/frontend/src/components/SchemaDesigner/Modals/TableNameModal.vue
+++ b/frontend/src/components/SchemaDesigner/Modals/TableNameModal.vue
@@ -95,7 +95,7 @@ const handleConfirmButtonClick = async () => {
table.name = state.tableName;
const column = ColumnMetadata.fromPartial({});
column.name = "id";
- if (engine === Engine.POSTGRES) {
+ if (engine.value === Engine.POSTGRES) {
column.type = "INTEGER";
} else {
column.type = "INT";
diff --git a/frontend/src/components/SchemaDesigner/Panels/TableEditor.vue b/frontend/src/components/SchemaDesigner/Panels/TableEditor.vue
index 30b6400bbd..f752716fb6 100644
--- a/frontend/src/components/SchemaDesigner/Panels/TableEditor.vue
+++ b/frontend/src/components/SchemaDesigner/Panels/TableEditor.vue
@@ -374,7 +374,7 @@ const columnHeaderList = computed(() => {
});
const dataTypeOptions = computed(() => {
- return getDataTypeSuggestionList(engine).map((dataType) => {
+ return getDataTypeSuggestionList(engine.value).map((dataType) => {
return {
label: dataType,
key: dataType,
@@ -440,7 +440,7 @@ const getReferencedForeignKeyName = (column: Column) => {
const referColumn = referencedTable.columnList.find(
(column) => column.id === fk.referencedColumnIdList[index]
);
- if (engine === Engine.MYSQL) {
+ if (engine.value === Engine.MYSQL) {
return `${referencedTable.name}(${referColumn?.name})`;
} else {
return `${referencedSchema?.name}.${referencedTable.name}(${referColumn?.name})`;
@@ -452,12 +452,12 @@ const isDroppedColumn = (column: Column): boolean => {
};
const disableChangeTable = computed(() => {
- return readonly || isDroppedSchema.value || isDroppedTable.value;
+ return readonly.value || isDroppedSchema.value || isDroppedTable.value;
});
const disableAlterColumn = (column: Column): boolean => {
return (
- readonly ||
+ readonly.value ||
isDroppedSchema.value ||
isDroppedTable.value ||
isDroppedColumn(column)
diff --git a/frontend/src/components/SchemaDesigner/PrepForm/index.vue b/frontend/src/components/SchemaDesigner/PrepForm/index.vue
index 1c359662c5..a723f0e243 100644
--- a/frontend/src/components/SchemaDesigner/PrepForm/index.vue
+++ b/frontend/src/components/SchemaDesigner/PrepForm/index.vue
@@ -109,7 +109,6 @@
<template v-if="state.selectedSchemaDesign">
<SchemaDesigner
ref="schemaDesignerRef"
- :key="schemaDesignId"
:readonly="isViewing"
:engine="state.selectedSchemaDesign.engine"
:schema-design="state.selectedSchemaDesign"
@@ -132,7 +131,7 @@
</template>
<script lang="ts" setup>
-import { isEqual, uniqueId } from "lodash-es";
+import { isEqual } from "lodash-es";
import { NButton, NInput } from "naive-ui";
import { computed, reactive, ref } from "vue";
import { useI18n } from "vue-i18n";
@@ -206,14 +205,6 @@ const isEditing = computed(
const project = computed(() => {
return projectStore.getProjectByUID(state.baselineSchema.projectId || "");
});
-const schemaDesignId = computed(() => {
- if (!state.selectedSchemaDesign || !state.selectedSchemaDesign.name) {
- return uniqueId();
- } else {
- // Force remount component.
- return state.selectedSchemaDesign.name + isViewing.value;
- }
-});
const handleSchemaDesignItemClick = async (schemaDesign: SchemaDesign) => {
state.schemaDesignName = schemaDesign.title;
diff --git a/frontend/src/components/SchemaDesigner/common/type.ts b/frontend/src/components/SchemaDesigner/common/type.ts
index 04b96560f0..42ebd35e2d 100644
--- a/frontend/src/components/SchemaDesigner/common/type.ts
+++ b/frontend/src/components/SchemaDesigner/common/type.ts
@@ -24,10 +24,9 @@ export interface SchemaDesignerTabState {
}
export interface SchemaDesignerContext {
- readonly: boolean;
- baselineMetadata: DatabaseMetadata;
- engine: Engine;
-
+ readonly: Ref<boolean>;
+ baselineMetadata: Ref<DatabaseMetadata>;
+ engine: Ref<Engine>;
metadata: Ref<DatabaseMetadata>;
tabState: Ref<SchemaDesignerTabState>;
diff --git a/frontend/src/components/SchemaDesigner/index.vue b/frontend/src/components/SchemaDesigner/index.vue
index 461fa00e47..51289f6224 100644
--- a/frontend/src/components/SchemaDesigner/index.vue
+++ b/frontend/src/components/SchemaDesigner/index.vue
@@ -15,7 +15,7 @@
<script lang="ts" setup>
import { Splitpanes, Pane } from "splitpanes";
-import { onMounted, reactive, ref } from "vue";
+import { onMounted, reactive, ref, watch } from "vue";
import { DatabaseMetadata } from "@/types/proto/v1/database_service";
import { SchemaDesign } from "@/types/proto/v1/schema_design_service";
import { Engine } from "@/types/proto/v1/common";
@@ -40,6 +40,8 @@ const state = reactive<LocalState>({
isLoading: true,
});
+const readonly = ref(props.readonly);
+const engine = ref(props.engine);
const metadata = ref<DatabaseMetadata>(DatabaseMetadata.fromPartial({}));
const editableSchemas = ref<Schema[]>([]);
const baselineMetadata = ref<DatabaseMetadata>(
@@ -61,15 +63,26 @@ onMounted(async () => {
});
provideSchemaDesignerContext({
- readonly: props.readonly,
- baselineMetadata: baselineMetadata.value,
- engine: props.engine,
+ readonly: readonly,
+ baselineMetadata: baselineMetadata,
+ engine: engine,
metadata: metadata,
tabState: tabState,
originalSchemas: cloneDeep(editableSchemas.value),
editableSchemas: editableSchemas,
});
+watch(
+ () => props,
+ () => {
+ readonly.value = props.readonly;
+ engine.value = props.engine;
+ },
+ {
+ deep: true,
+ }
+);
+
defineExpose({
metadata,
baselineMetadata,