Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: update table editor (#4148)
boojack8279f787f1d1
diff --git a/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vue b/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vueindex 274068e4e5..35edd2e342 100644--- a/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vue+++ b/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vue@@ -2,7 +2,6 @@<BBModal:title="$t('database.alter-schema')"class="schema-editor-modal-container !w-[96rem] h-auto overflow-auto !max-w-[calc(100%-40px)] !max-h-[calc(100%-40px)]"- :esc-closable="false"@close="dismissModal"><div@@ -227,6 +226,11 @@ const isTenantProject = project.tenantMode === "TENANT";onMounted(() => {if (databaseList.length === 0 || project.id === UNKNOWN_ID) {+ notificationStore.pushNotification({+ module: "bytebase",+ style: "CRITICAL",+ title: "Invalid database list",+ });emit("close");return;}diff --git a/frontend/src/components/SchemaEditor/DatabaseTree.vue b/frontend/src/components/SchemaEditor/DatabaseTree.vueindex 3858d19b6d..93d98ffd81 100644--- a/frontend/src/components/SchemaEditor/DatabaseTree.vue+++ b/frontend/src/components/SchemaEditor/DatabaseTree.vue@@ -187,6 +187,11 @@ const contextMenuOptions = computed(() => {} else if (treeNode.type === "schema") {const options = [];if (instanceEngine === "POSTGRES") {+ options.push({+ key: "create-table",+ label: t("schema-editor.actions.create-table"),+ });+const schema = editorStore.databaseSchemaById.get(treeNode.databaseId)?.schemaList.find((schema) => schema.name === treeNode.schemaName);@@ -196,11 +201,6 @@ const contextMenuOptions = computed(() => {label: t("schema-editor.actions.delete-schema"),});}-- options.push({- key: "create-table",- label: t("schema-editor.actions.create-table"),- });}return options;} else if (treeNode.type === "table") {@@ -277,17 +277,26 @@ onMounted(async () => {if (databaseTreeNodeList.length === 1) {const node = databaseTreeNodeList[0];await loadSubTree(node);- expandedKeysRef.value.push(node.key);- editorStore.addTab({- id: generateUniqueTabId(),- type: SchemaEditorTabType.TabForDatabase,- databaseId: node.databaseId,- });+ const schemaList = await editorStore.fetchSchemaListByDatabaseId(+ node.databaseId+ );+ if (schemaList.length !== 0) {+ expandedKeysRef.value.push(node.key);+ editorStore.addTab({+ id: generateUniqueTabId(),+ type: SchemaEditorTabType.TabForDatabase,+ databaseId: node.databaseId,+ });+ }}});watch(- [() => tableList.value, () => databaseDataLoadedSet.value],+ [+ () => schemaList.value,+ () => tableList.value,+ () => databaseDataLoadedSet.value,+ ],() => {const databaseTreeNodeList: TreeNodeForDatabase[] = [];for (const treeNode of treeDataRef.value) {@@ -615,6 +624,12 @@ const nodeProps = ({ option: treeNode }: { option: TreeNode }) => {} else {expandedKeysRef.value.push(treeNode.key);}+ editorStore.addTab({+ id: generateUniqueTabId(),+ type: SchemaEditorTabType.TabForDatabase,+ databaseId: treeNode.databaseId,+ selectedSchemaName: treeNode.schemaName,+ });} else if (treeNode.type === "table") {editorStore.addTab({id: generateUniqueTabId(),diff --git a/frontend/src/components/SchemaEditor/Panels/DatabaseEditor.vue b/frontend/src/components/SchemaEditor/Panels/DatabaseEditor.vueindex 9ad4f4bd36..2caa43649c 100644--- a/frontend/src/components/SchemaEditor/Panels/DatabaseEditor.vue+++ b/frontend/src/components/SchemaEditor/Panels/DatabaseEditor.vue@@ -49,7 +49,8 @@/></div><button- class="flex flex-row justify-center items-center border px-3 py-1 leading-6 rounded text-sm hover:bg-gray-100"+ class="flex flex-row justify-center items-center border px-3 py-1 leading-6 rounded text-sm hover:opacity-80 disabled:cursor-not-allowed disabled:opacity-60"+ :disabled="!allowCreateTable"@click="handleCreateNewTable"><heroicons-outline:plus class="w-4 h-auto mr-1 text-gray-400" />@@ -176,7 +177,7 @@<script lang="ts" setup>import { head } from "lodash-es";import { NEllipsis } from "naive-ui";-import { computed, onMounted, reactive, watch } from "vue";+import { computed, reactive, watch } from "vue";import { useI18n } from "vue-i18n";import {generateUniqueTabId,@@ -221,10 +222,10 @@ const state = reactive<LocalState>({isFetchingDDL: false,statement: "",});-const currentTab = editorStore.currentTab as DatabaseTabContext;+const currentTab = computed(() => editorStore.currentTab as DatabaseTabContext);const databaseSchema = computed(() => {return editorStore.databaseSchemaById.get(- currentTab.databaseId+ currentTab.value.databaseId) as DatabaseSchema;});const database = databaseSchema.value.database;@@ -241,6 +242,13 @@ const shouldShowSchemaSelector = computed(() => {return databaseEngine === "POSTGRES";});+const allowCreateTable = computed(() => {+ if (databaseEngine === "POSTGRES") {+ return schemaList.length > 0 && state.selectedSchema !== "";+ }+ return true;+});+const schemaSelectorOptionList = computed(() => {const optionList = [];for (const schema of schemaList) {@@ -281,9 +289,19 @@ const tableHeaderList = computed(() => {];});-onMounted(() => {- state.selectedSchema = head(schemaList)?.name || "";-});+watch(+ [() => currentTab.value.selectedSchemaName],+ () => {+ if (currentTab.value.selectedSchemaName) {+ state.selectedSchema = currentTab.value.selectedSchemaName;+ } else {+ state.selectedSchema = head(schemaList)?.name || "";+ }+ },+ {+ immediate: true,+ }+);watch(() => state.selectedTab,diff --git a/frontend/src/components/SchemaEditor/Panels/TableEditor.vue b/frontend/src/components/SchemaEditor/Panels/TableEditor.vueindex 3f3f726fb1..2588688038 100644--- a/frontend/src/components/SchemaEditor/Panels/TableEditor.vue+++ b/frontend/src/components/SchemaEditor/Panels/TableEditor.vue@@ -52,6 +52,7 @@<!-- column table --><div+ ref="tableEditorContainerRef"class="w-full h-auto grid auto-rows-auto border-y relative overflow-y-auto"><!-- column table header -->@@ -73,17 +74,18 @@v-for="(column, index) in table.columnList":key="`${index}-${column.id}`"class="grid grid-cols-[repeat(4,_minmax(0,_1fr))_repeat(2,_96px)_minmax(0,_1fr)_32px] gr text-sm even:bg-gray-50"- :class="+ :class="[isDroppedColumn(column) &&- 'text-red-700 cursor-not-allowed !bg-red-50 opacity-70'- "+ 'text-red-700 cursor-not-allowed !bg-red-50 opacity-70',+ `column-${column.id}`,+ ]"><div class="table-body-item-container"><inputv-model="column.name":disabled="disableAlterColumn(column)"placeholder="column name"- class="column-field-input"+ class="column-field-input column-name-input"type="text"/></div>@@ -251,7 +253,7 @@<script lang="ts" setup>import { cloneDeep, isUndefined, flatten } from "lodash-es";-import { computed, reactive, ref, watch } from "vue";+import { computed, nextTick, reactive, ref, watch } from "vue";import { useI18n } from "vue-i18n";import { useNotificationStore, useSchemaEditorStore } from "@/store/modules";import { TableTabContext } from "@/types";@@ -306,6 +308,7 @@ const foreignKeyList = computed(() => {) as ForeignKey[];});+const tableEditorContainerRef = ref<HTMLDivElement>();const editForeignKeyColumn = ref<Column>();const isDroppedTable = computed(() => {@@ -506,6 +509,13 @@ const handleAddColumn = () => {const column = convertColumnMetadataToColumn(ColumnMetadata.fromPartial({}));column.status = "created";table.value.columnList.push(column);+ nextTick(() => {+ (+ tableEditorContainerRef.value?.querySelector(+ `.column-${column.id} .column-name-input`+ ) as HTMLInputElement+ )?.focus();+ });};const handleColumnDefaultFieldChange = (diff --git a/frontend/src/store/modules/schemaEditor.ts b/frontend/src/store/modules/schemaEditor.tsindex d18c586fe7..ff63fd6244 100644--- a/frontend/src/store/modules/schemaEditor.ts+++ b/frontend/src/store/modules/schemaEditor.ts@@ -85,10 +85,13 @@ export const useSchemaEditorStore = defineStore("SchemaEditor", {});if (tabCache !== undefined) {- tab = tabCache;- } else {- this.tabState.tabMap.set(tab.id, tab);+ tab = {+ ...tabCache,+ ...tab,+ id: tabCache.id,+ };}+ this.tabState.tabMap.set(tab.id, tab);if (setAsCurrentTab) {this.setCurrentTab(tab.id);diff --git a/frontend/src/types/schemaEditor/atomType.ts b/frontend/src/types/schemaEditor/atomType.tsindex bc9b136443..a9b7db86eb 100644--- a/frontend/src/types/schemaEditor/atomType.ts+++ b/frontend/src/types/schemaEditor/atomType.ts@@ -1,3 +1,4 @@+import { isGhostTable } from "@/utils";import { v1 as uuidv1 } from "uuid";import {ColumnMetadata,@@ -114,6 +115,11 @@ export const convertSchemaMetadataToSchema = (const foreignKeyList: ForeignKey[] = [];for (const tableMetadata of schemaMetadata.tables) {+ // Don't display ghost table in Schema Editor.+ if (isGhostTable(tableMetadata)) {+ continue;+ }+const table = convertTableMetadataToTable(tableMetadata);tableList.push(table);}diff --git a/frontend/src/types/schemaEditor/index.ts b/frontend/src/types/schemaEditor/index.tsindex 79c0d226e5..a5d3115e7b 100644--- a/frontend/src/types/schemaEditor/index.ts+++ b/frontend/src/types/schemaEditor/index.ts@@ -11,6 +11,7 @@ export interface DatabaseTabContext {id: string;type: SchemaEditorTabType.TabForDatabase;databaseId: DatabaseId;+ selectedSchemaName?: string;}// Tab context for editing table.