Skip to content

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

chore: fix database tree watch refs (#9603)

boojackb206e89818f6
diff --git a/frontend/src/components/SchemaEditorV1/Aside/DatabaseTree.vue b/frontend/src/components/SchemaEditorV1/Aside/DatabaseTree.vue
index f17767f7e7..a8abe42e41 100644
--- a/frontend/src/components/SchemaEditorV1/Aside/DatabaseTree.vue
+++ b/frontend/src/components/SchemaEditorV1/Aside/DatabaseTree.vue
@@ -69,7 +69,7 @@
<script lang="ts" setup>
import { useElementSize } from "@vueuse/core";
-import { escape, head, isUndefined } from "lodash-es";
+import { escape, head, isUndefined, pick } from "lodash-es";
import { TreeOption, NEllipsis, NInput, NDropdown, NTree } from "naive-ui";
import { computed, onMounted, watch, ref, h, reactive, nextTick } from "vue";
import { useI18n } from "vue-i18n";
@@ -189,9 +189,15 @@ const schemaList = computed(() =>
Array.from(schemaEditorV1Store.resourceMap["database"].values())
.map((item) => item.schemaList)
.flat()
-);
-const tableList = computed(() =>
- schemaList.value.map((schema) => schema.tableList).flat()
+ .map((schema) => {
+ return {
+ ...schema,
+ tableList: schema.tableList.map((table) => {
+ // Don't watch column changes in database tree.
+ return pick(table, ["id", "name", "status"]);
+ }),
+ };
+ })
);
const contextMenuOptions = computed(() => {
const treeNode = contextMenu.treeNode;
@@ -323,11 +329,7 @@ onMounted(async () => {
});
watch(
- [
- () => schemaList.value,
- () => tableList.value,
- () => databaseDataLoadedSet.value,
- ],
+ [() => schemaList.value],
() => {
const databaseTreeNodeList: TreeNodeForDatabase[] = [];
for (const treeNode of treeDataRef.value) {
@@ -472,17 +474,20 @@ 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);
+watch(
+ () => searchPattern.value,
+ () => {
+ 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 }: { option: TreeOption }) => {
diff --git a/frontend/src/components/SchemaEditorV1/Panels/DatabaseEditor.vue b/frontend/src/components/SchemaEditorV1/Panels/DatabaseEditor.vue
index 88a789b78d..b8ae6c9c19 100644
--- a/frontend/src/components/SchemaEditorV1/Panels/DatabaseEditor.vue
+++ b/frontend/src/components/SchemaEditorV1/Panels/DatabaseEditor.vue
@@ -244,7 +244,7 @@ const schemaSelectorOptionList = computed(() => {
});
watch(
- [() => currentTab.value, () => schemaList],
+ [() => currentTab.value],
() => {
const schemaIdList = schemaList.value.map((schema) => schema.id);
if (
diff --git a/frontend/src/components/SchemaEditorV1/Panels/LegacyTableColumnEditor.vue b/frontend/src/components/SchemaEditorV1/Panels/LegacyTableColumnEditor.vue
deleted file mode 100644
index 9bb9b4109a..0000000000
--- a/frontend/src/components/SchemaEditorV1/Panels/LegacyTableColumnEditor.vue
+++ /dev/null
@@ -1,618 +0,0 @@
-<template>
- <!-- column table -->
- <BBGrid
- id="table-editor-container"
- class="border"
- :column-list="columnHeaderList"
- :data-source="shownColumnList"
- :custom-header="true"
- :row-clickable="false"
- >
- <template #header>
- <div role="table-row" class="bb-grid-row bb-grid-header-row group">
- <div
- v-for="(column, index) in columnHeaderList"
- :key="index"
- role="table-cell"
- class="bb-grid-header-cell"
- >
- {{ column.title }}
- </div>
- </div>
- </template>
- <template #item="{ item: column, row }: { item: Column, row: number }">
- <div
- row="table-row"
- class="bb-grid-row group"
- :class="`column-${column.id}`"
- >
- <div
- class="bb-grid-cell !pl-0.5 column-cell"
- :class="getColumnClassList(column, row)"
- >
- <input
- v-model="column.name"
- :disabled="readonly || disableAlterColumn(column)"
- placeholder="column name"
- class="column-field-input column-name-input"
- type="text"
- />
- </div>
- <div
- v-if="showSemanticTypeColumn"
- class="bb-grid-cell flex items-center"
- :class="getColumnClassList(column, row)"
- >
- {{ getColumnSemanticType(column)?.title }}
- <div v-if="!readonly && !disableChangeTable" class="flex">
- <button
- v-if="getColumnSemanticType(column)"
- :disabled="disableAlterColumn(column)"
- class="w-4 h-4 p-0.5 hover:bg-control-bg-hover rounded cursor-pointer"
- @click.prevent="onSemanticTypeRemove(column)"
- >
- <heroicons-outline:x class="w-3 h-3" />
- </button>
- <button
- :disabled="disableAlterColumn(column)"
- class="w-4 h-4 p-0.5 hover:bg-control-bg-hover rounded cursor-pointer"
- @click.prevent="openSemanticTypeDrawer(column)"
- >
- <heroicons-outline:pencil class="w-3 h-3" />
- </button>
- </div>
- </div>
- <div
- v-if="classificationConfig"
- class="bb-grid-cell flex items-center gap-x-2 text-sm"
- :class="getColumnClassList(column, row)"
- >
- <ClassificationLevelBadge
- :classification="column.classification"
- :classification-config="classificationConfig"
- />
- <div v-if="!readonly && !disableChangeTable" class="flex">
- <button
- v-if="column.classification"
- class="w-4 h-4 p-0.5 hover:bg-control-bg-hover rounded cursor-pointer"
- @click.prevent="column.classification = ''"
- >
- <heroicons-outline:x class="w-3 h-3" />
- </button>
- <button
- class="w-4 h-4 p-0.5 hover:bg-control-bg-hover rounded cursor-pointer"
- @click.prevent="openClassificationDrawer(column)"
- >
- <heroicons-outline:pencil class="w-3 h-3" />
- </button>
- </div>
- </div>
- <div
- class="bb-grid-cell flex flex-row justify-between items-center relative column-cell"
- :class="getColumnClassList(column, row)"
- >
- <input
- v-model="column.type"
- :disabled="
- readonly ||
- disableAlterColumn(column) ||
- schemaTemplateColumnTypes.length > 0
- "
- placeholder="column type"
- class="column-field-input column-type-input !pr-8"
- type="text"
- />
- <NDropdown
- v-if="!readonly"
- trigger="click"
- :disabled="readonly || disableAlterColumn(column)"
- :options="columnTypeOptions"
- @select="(dataType: string) => (column.type = dataType)"
- >
- <button class="absolute right-5">
- <heroicons-solid:chevron-up-down
- class="w-4 h-auto text-gray-400"
- />
- </button>
- </NDropdown>
- </div>
- <div
- class="bb-grid-cell flex flex-row justify-between items-center relative column-cell"
- :class="getColumnClassList(column, row)"
- >
- <input
- class="column-field-input !pr-8"
- type="text"
- :value="getColumnDefaultDisplayString(column)"
- :disabled="readonly || disableAlterColumn(column)"
- :placeholder="getColumnDefaultValuePlaceholder(column)"
- @change="(e) => handleColumnDefaultInputChange(e, column)"
- />
- <NDropdown
- v-if="!readonly"
- trigger="click"
- :disabled="readonly || disableAlterColumn(column)"
- :options="getColumnDefaultValueOptions(engine, column.type)"
- @select="(key: string) => handleColumnDefaultFieldChange(column, key)"
- >
- <button class="absolute right-5">
- <heroicons-solid:chevron-up-down
- class="w-4 h-auto text-gray-400"
- />
- </button>
- </NDropdown>
- </div>
- <div
- class="bb-grid-cell column-cell"
- :class="getColumnClassList(column, row)"
- >
- <input
- v-model="column.userComment"
- :disabled="readonly || disableAlterColumn(column)"
- placeholder="comment"
- class="column-field-input"
- type="text"
- />
- </div>
- <div
- class="bb-grid-cell flex justify-start items-center column-cell"
- :class="getColumnClassList(column, row)"
- >
- <BBCheckbox
- class="ml-3"
- :value="!column.nullable"
- :disabled="
- readonly ||
- disableAlterColumn(column) ||
- isColumnPrimaryKey(column)
- "
- @toggle="(value) => (column.nullable = !value)"
- />
- </div>
- <div
- class="bb-grid-cell flex justify-start items-center column-cell"
- :class="getColumnClassList(column, row)"
- >
- <BBCheckbox
- class="ml-3"
- :value="isColumnPrimaryKey(column)"
- :disabled="readonly || disableAlterColumn(column)"
- @toggle="(value) => $emit('onPrimaryKeySet', column, value)"
- />
- </div>
- <div
- v-if="showForeignKey"
- class="bb-grid-cell foreign-key-field flex justify-start items-center column-cell"
- :class="getColumnClassList(column, row)"
- >
- <span
- v-if="checkColumnHasForeignKey(column)"
- class="column-field-text cursor-pointer !w-auto hover:opacity-80"
- @click="$emit('onForeignKeyClick', column)"
- >
- {{ getReferencedForeignKeyName(column) }}
- </span>
- <span v-else class="column-field-text italic text-gray-400 !w-auto"
- >EMPTY</span
- >
- <button
- v-if="!readonly"
- class="foreign-key-edit-button hidden cursor-pointer hover:opacity-80 disabled:cursor-not-allowed disabled:opacity-60"
- :disabled="disableAlterColumn(column)"
- @click="$emit('onForeignKeyEdit', column)"
- >
- <heroicons:pencil-square class="w-4 h-auto text-gray-400" />
- </button>
- </div>
- <div
- class="bb-grid-cell flex items-center column-cell"
- :class="getColumnClassList(column, row)"
- >
- <LabelsColumn :labels="column.config.labels" :show-count="1" />
- <button
- v-if="!readonly && !disableChangeTable"
- class="w-4 h-4 p-0.5 hover:bg-control-bg-hover rounded cursor-pointer"
- @click.prevent="openLabelsDrawer(column)"
- >
- <heroicons-outline:pencil class="w-3 h-3" />
- </button>
- </div>
- <div
- v-if="!readonly"
- class="bb-grid-cell flex justify-end items-center"
- :class="getColumnClassList(column, row)"
- >
- <n-tooltip v-if="!isDroppedColumn(column)" trigger="hover">
- <template #trigger>
- <button
- :disabled="disableChangeTable"
- class="text-gray-500 cursor-pointer hover:opacity-80 disabled:cursor-not-allowed disabled:opacity-60"
- @click="$emit('onDrop', column)"
- >
- <heroicons:trash class="w-4 h-auto" />
- </button>
- </template>
- <span>{{ $t("schema-editor.actions.drop-column") }}</span>
- </n-tooltip>
- <n-tooltip v-else trigger="hover">
- <template #trigger>
- <button
- class="text-gray-500 cursor-pointer hover:opacity-80 disabled:cursor-not-allowed disabled:opacity-60"
- :disabled="disableChangeTable"
- @click="$emit('onRestore', column)"
- >
- <heroicons:arrow-uturn-left class="w-4 h-auto" />
- </button>
- </template>
- <span>{{ $t("schema-editor.actions.restore") }}</span>
- </n-tooltip>
- </div>
- </div>
- </template>
- </BBGrid>
-
- <ColumnDefaultValueExpressionModal
- v-if="editColumnDefaultValueExpressionContext"
- :expression="editColumnDefaultValueExpressionContext.defaultExpression"
- @close="editColumnDefaultValueExpressionContext = undefined"
- @update:expression="handleSelectedColumnDefaultValueExpressionChange"
- />
-
- <SelectClassificationDrawer
- v-if="classificationConfig && state.pendingUpdateColumn"
- :show="state.showClassificationDrawer"
- :classification-config="classificationConfig"
- @dismiss="state.showClassificationDrawer = false"
- @apply="onClassificationSelect"
- />
-
- <SemanticTypesDrawer
- v-if="state.pendingUpdateColumn"
- :show="state.showSemanticTypesDrawer"
- :semantic-type-list="semanticTypeList"
- @dismiss="state.showSemanticTypesDrawer = false"
- @apply="onSemanticTypeApply($event)"
- />
-
- <LabelEditorDrawer
- v-if="state.pendingUpdateColumn"
- :show="state.showLabelsDrawer"
- :readonly="false"
- :title="
- $t('db.labels-for-resource', {
- resource: `'${state.pendingUpdateColumn.name}'`,
- })
- "
- :labels="[state.pendingUpdateColumn.config.labels]"
- @dismiss="state.showLabelsDrawer = false"
- @apply="onLabelsApply"
- />
-</template>
-
-<script lang="ts" setup>
-import { flatten } from "lodash-es";
-import { NDropdown } from "naive-ui";
-import { computed, reactive, ref } from "vue";
-import { useI18n } from "vue-i18n";
-import { BBCheckbox } from "@/bbkit";
-import { useSettingV1Store, useSubscriptionV1Store } from "@/store/modules";
-import { Engine } from "@/types/proto/v1/common";
-import { ColumnConfig } from "@/types/proto/v1/database_service";
-import { Table, Column, ForeignKey } from "@/types/v1/schemaEditor";
-import { getDataTypeSuggestionList } from "@/utils";
-import ColumnDefaultValueExpressionModal from "../Modals/ColumnDefaultValueExpressionModal.vue";
-import {
- getColumnDefaultDisplayString,
- getColumnDefaultValuePlaceholder,
- getDefaultValueByKey,
- getColumnDefaultValueOptions,
- isTextOfColumnType,
-} from "../utils/columnDefaultValue";
-
-interface LocalState {
- pendingUpdateColumn?: Column;
- showClassificationDrawer: boolean;
- showSemanticTypesDrawer: boolean;
- showLabelsDrawer: boolean;
-}
-
-const props = withDefaults(
- defineProps<{
- readonly: boolean;
- showForeignKey?: boolean;
- table: Table;
- engine: Engine;
- foreignKeyList?: ForeignKey[];
- classificationConfigId?: string;
- disableChangeTable?: boolean;
- filterColumn?: (column: Column) => boolean;
- disableAlterColumn?: (column: Column) => boolean;
- getReferencedForeignKeyName?: (column: Column) => string;
- getColumnItemComputedClassList?: (column: Column) => string[];
- }>(),
- {
- showForeignKey: true,
- disableChangeTable: false,
- foreignKeyList: () => [],
- classificationConfigId: "",
- filterColumn: (_: Column) => true,
- disableAlterColumn: (_: Column) => false,
- getReferencedForeignKeyName: (_: Column) => "",
- getColumnItemComputedClassList: (_: Column) => [],
- }
-);
-
-defineEmits<{
- (event: "onDrop", column: Column): void;
- (event: "onRestore", column: Column): void;
- (event: "onEdit", index: number): void;
- (event: "onForeignKeyEdit", column: Column): void;
- (event: "onForeignKeyClick", column: Column): void;
- (event: "onPrimaryKeySet", column: Column, isPrimaryKey: boolean): void;
-}>();
-
-const state = reactive<LocalState>({
- showClassificationDrawer: false,
- showSemanticTypesDrawer: false,
- showLabelsDrawer: false,
-});
-
-const { t } = useI18n();
-const subscriptionV1Store = useSubscriptionV1Store();
-const settingStore = useSettingV1Store();
-const editColumnDefaultValueExpressionContext = ref<Column>();
-
-const classificationConfig = computed(() => {
- if (!props.classificationConfigId) {
- return;
- }
- return settingStore.getProjectClassification(props.classificationConfigId);
-});
-
-const semanticTypeList = computed(() => {
- return (
- settingStore.getSettingByName("bb.workspace.semantic-types")?.value
- ?.semanticTypeSettingValue?.types ?? []
- );
-});
-
-const getColumnSemanticType = (column: Column) => {
- if (!column.config.semanticTypeId) {
- return;
- }
- return semanticTypeList.value.find(
- (data) => data.id === column.config.semanticTypeId
- );
-};
-
-const showSemanticTypeColumn = computed(() => {
- return subscriptionV1Store.hasFeature("bb.feature.sensitive-data");
-});
-
-const columnHeaderList = computed(() => {
- return [
- {
- title: t("schema-editor.column.name"),
- width: "6rem",
- },
- {
- title: t("settings.sensitive-data.semantic-types.self"),
- width: "minmax(auto, 0.8fr)",
- hide: !showSemanticTypeColumn.value,
- },
- {
- title: t("schema-editor.column.classification"),
- width: "minmax(auto, 1.5fr)",
- hide: !classificationConfig.value,
- },
- {
- title: t("schema-editor.column.type"),
- width: "minmax(auto, 0.8fr)",
- },
- {
- title: t("schema-editor.column.default"),
- width: "minmax(auto, 0.8fr)",
- },
- {
- title: t("schema-editor.column.comment"),
- width: "minmax(auto, 0.8fr)",
- },
- {
- title: t("schema-editor.column.not-null"),
- width: "80px",
- },
- {
- title: t("schema-editor.column.primary"),
- width: "80px",
- },
- {
- title: t("schema-editor.column.foreign-key"),
- width: "minmax(auto, 7rem)",
- hide: !props.showForeignKey,
- },
- {
- title: t("common.labels"),
- width: "minmax(auto, 1fr)",
- },
- {
- title: "",
- width: "30px",
- hide: props.readonly,
- },
- ].filter((header) => !header.hide);
-});
-
-const getColumnClassList = (column: Column, index: number): string[] => {
- const classList = props.getColumnItemComputedClassList(column);
- if (index % 2 === 1) {
- classList.push("bg-gray-50");
- }
- return classList;
-};
-
-const shownColumnList = computed(() => {
- return props.table.columnList.filter(props.filterColumn);
-});
-
-const isColumnPrimaryKey = (column: Column): boolean => {
- return props.table.primaryKey.columnIdList.includes(column.id);
-};
-
-const checkColumnHasForeignKey = (column: Column): boolean => {
- const columnIdList = flatten(
- props.foreignKeyList.map((fk) => fk.columnIdList)
- );
- return columnIdList.includes(column.id);
-};
-
-const schemaTemplateColumnTypes = computed(() => {
- const setting = settingStore.getSettingByName("bb.workspace.schema-template");
- const columnTypes = setting?.value?.schemaTemplateSettingValue?.columnTypes;
- if (columnTypes && columnTypes.length > 0) {
- const columnType = columnTypes.find(
- (columnType) => columnType.engine === props.engine
- );
- if (columnType && columnType.enabled) {
- return columnType.types;
- }
- }
- return [];
-});
-
-const columnTypeOptions = computed(() => {
- if (schemaTemplateColumnTypes.value.length > 0) {
- return schemaTemplateColumnTypes.value.map((columnType) => {
- return {
- label: columnType,
- key: columnType,
- };
- });
- }
-
- return getDataTypeSuggestionList(props.engine).map((dataType) => {
- return {
- label: dataType,
- key: dataType,
- };
- });
-});
-
-const isDroppedColumn = (column: Column): boolean => {
- return column.status === "dropped";
-};
-
-const handleColumnDefaultInputChange = (event: Event, column: Column) => {
- const value = (event.target as HTMLInputElement).value;
- column.hasDefault = true;
- column.defaultNull = undefined;
- // If column is text type or has default string, we will treat user's input as string.
- if (
- isTextOfColumnType(props.engine, column.type) ||
- column.defaultString !== undefined
- ) {
- column.defaultString = value;
- column.defaultExpression = undefined;
- return;
- }
- // Otherwise we will treat user's input as expression.
- column.defaultExpression = value;
-};
-
-const handleColumnDefaultFieldChange = (column: Column, key: string) => {
- if (key === "expression") {
- editColumnDefaultValueExpressionContext.value = column;
- return;
- }
-
- const defaultValue = getDefaultValueByKey(key);
- if (!defaultValue) {
- return;
- }
-
- column.hasDefault = defaultValue.hasDefault;
- column.defaultNull = defaultValue.defaultNull;
- column.defaultString = defaultValue.defaultString;
- column.defaultExpression = defaultValue.defaultExpression;
- if (column.hasDefault && column.defaultNull) {
- column.nullable = true;
- }
-};
-
-const handleSelectedColumnDefaultValueExpressionChange = (
- expression: string
-) => {
- const column = editColumnDefaultValueExpressionContext.value;
- if (!column) {
- return;
- }
- column.hasDefault = true;
- column.defaultNull = undefined;
- column.defaultString = undefined;
- column.defaultExpression = expression;
-};
-
-const openClassificationDrawer = (column: Column) => {
- state.pendingUpdateColumn = column;
- state.showClassificationDrawer = true;
-};
-
-const openSemanticTypeDrawer = (column: Column) => {
- state.pendingUpdateColumn = column;
- state.showSemanticTypesDrawer = true;
-};
-
-const openLabelsDrawer = (column: Column) => {
- state.pendingUpdateColumn = column;
- state.showLabelsDrawer = true;
-};
-
-const onClassificationSelect = (classificationId: string) => {
- if (!state.pendingUpdateColumn) {
- return;
- }
- state.pendingUpdateColumn.classification = classificationId;
-};
-
-const onSemanticTypeApply = async (semanticTypeId: string) => {
- if (!state.pendingUpdateColumn) {
- return;
- }
-
- state.pendingUpdateColumn.config = ColumnConfig.fromPartial({
- ...state.pendingUpdateColumn.config,
- semanticTypeId,
- });
-};
-
-const onLabelsApply = (labelsList: { [key: string]: string }[]) => {
- if (!state.pendingUpdateColumn) {
- return;
- }
- state.pendingUpdateColumn.config = ColumnConfig.fromPartial({
- ...state.pendingUpdateColumn.config,
- labels: labelsList[0],
- });
-};
-
-const onSemanticTypeRemove = async (column: Column) => {
- column.config = ColumnConfig.fromPartial({
- ...column.config,
- semanticTypeId: "",
- });
-};
-</script>
-
-<style scoped>
-.column-cell {
- @apply !py-0.5 !px-0.5;
-}
-.column-field-input {
- @apply w-full pr-1 box-border border-transparent truncate select-none rounded bg-transparent text-sm placeholder:italic placeholder:text-gray-400 focus:bg-white focus:text-black;
-}
-.column-field-text {
- @apply w-full pl-3 pr-1 box-border border-transparent truncate select-none rounded bg-transparent text-sm placeholder:italic placeholder:text-gray-400 focus:bg-white focus:text-black;
-}
-.foreign-key-field:hover .foreign-key-edit-button {
- @apply block;
-}
-</style>
diff --git a/frontend/src/components/SchemaEditorV1/Panels/LegacyTableList.vue b/frontend/src/components/SchemaEditorV1/Panels/LegacyTableList.vue
deleted file mode 100644
index d8abebc9f2..0000000000
--- a/frontend/src/components/SchemaEditorV1/Panels/LegacyTableList.vue
+++ /dev/null
@@ -1,356 +0,0 @@
-<template>
- <div class="w-full h-full">
- <BBGrid
- v-if="false"
- class="border"
- :column-list="tableHeaderList"
- :data-source="tableList"
- :custom-header="true"
- :row-clickable="false"
- >
- <template #header>
- <div role="table-row" class="bb-grid-row bb-grid-header-row group">
- <div
- v-for="(header, index) in tableHeaderList"
- :key="index"
- role="table-cell"
- class="bb-grid-header-cell"
- >
- {{ header.title }}
- </div>
- </div>
- </template>
- <template #item="{ item: table, row }: { item: Table, row: number }">
- <div class="bb-grid-cell" :class="getTableClassList(table, row)">
- <NEllipsis
- class="w-full cursor-pointer leading-6 my-2 hover:text-accent"
- >
- <span @click="handleTableItemClick(table)">
- {{ table.name }}
- </span>
- </NEllipsis>
- </div>
- <div
- v-if="supportClassification"
- class="bb-grid-cell flex items-center gap-x-2 text-sm"
- :class="getTableClassList(table, row)"
- >
- <ClassificationLevelBadge
- :classification="table.classification"
- :classification-config="classificationConfig"
- />
- <div v-if="!readonly && !disableChangeTable(table)" class="flex">
- <button
- v-if="table.classification"
- class="w-4 h-4 p-0.5 hover:bg-control-bg-hover rounded cursor-pointer"
- @click.prevent="table.classification = ''"
- >
- <heroicons-outline:x class="w-3 h-3" />
- </button>
- <button
- class="w-4 h-4 p-0.5 hover:bg-control-bg-hover rounded cursor-pointer"
- @click.prevent="showClassificationDrawer(table)"
- >
- <heroicons-outline:pencil class="w-3 h-3" />
- </button>
- </div>
- </div>
- <div class="bb-grid-cell" :class="getTableClassList(table, row)">
- {{ table.rowCount }}
- </div>
- <div class="bb-grid-cell" :class="getTableClassList(table, row)">
- {{ bytesToString(table.dataSize.toNumber()) }}
- </div>
- <div class="bb-grid-cell" :class="getTableClassList(table, row)">
- {{ table.engine }}
- </div>
- <div class="bb-grid-cell" :class="getTableClassList(table, row)">
- {{ table.collation }}
- </div>
- <div class="bb-grid-cell" :class="getTableClassList(table, row)">
- {{ table.userComment }}
- </div>
- <div
- v-if="!readonly"
- class="bb-grid-cell !px-0.5 flex justify-start items-center"
- :class="getTableClassList(table, row)"
- >
- <NTooltip v-if="!isDroppedTable(table)" trigger="hover" to="body">
- <template #trigger>
- <heroicons:trash
- class="w-4 h-auto text-gray-500 cursor-pointer hover:opacity-80"
- @click="handleDropTable(table)"
- />
- </template>
- <span>{{ $t("schema-editor.actions.drop-table") }}</span>
- </NTooltip>
- <NTooltip v-else trigger="hover" to="body">
- <template #trigger>
- <heroicons:arrow-uturn-left
- class="w-4 h-auto text-gray-500 cursor-pointer hover:opacity-80"
- @click="handleRestoreTable(table)"
- />
- </template>
- <span>{{ $t("schema-editor.actions.restore") }}</span>
- </NTooltip>
- </div>
- </template>
- </BBGrid>
- </div>
-
- <TableNameModal
- v-if="state.tableNameModalContext !== undefined"
- :parent-name="state.tableNameModalContext.parentName"
- :schema-id="state.tableNameModalContext.schemaId"
- :table-name="state.tableNameModalContext.tableName"
- @close="state.tableNameModalContext = undefined"
- />
-
- <Drawer
- :show="state.showSchemaTemplateDrawer"
- @close="state.showSchemaTemplateDrawer = false"
- >
- <DrawerContent :title="$t('schema-template.table-template.self')">
- <div class="w-[calc(100vw-36rem)] min-w-[64rem] max-w-[calc(100vw-8rem)]">
- <TableTemplates
- :engine="engine"
- :readonly="true"
- @apply="handleApplyTemplate"
- />
- </div>
- </DrawerContent>
- </Drawer>
-
- <SelectClassificationDrawer
- v-if="classificationConfig"
- :show="state.showClassificationDrawer"
- :classification-config="classificationConfig"
- @dismiss="state.showClassificationDrawer = false"
- @apply="onClassificationSelect"
- />
-
- <FeatureModal
- feature="bb.feature.schema-template"
- :open="state.showFeatureModal"
- @cancel="state.showFeatureModal = false"
- />
-</template>
-
-<script lang="ts" setup>
-import { NEllipsis, NTooltip } from "naive-ui";
-import { computed, reactive } from "vue";
-import { useI18n } from "vue-i18n";
-import { Drawer, DrawerContent } from "@/components/v2";
-import {
- hasFeature,
- generateUniqueTabId,
- useSettingV1Store,
- useSchemaEditorV1Store,
-} from "@/store";
-import { SchemaTemplateSetting_TableTemplate } from "@/types/proto/v1/setting_service";
-import {
- Table,
- DatabaseTabContext,
- SchemaEditorTabType,
- convertTableMetadataToTable,
-} from "@/types/v1/schemaEditor";
-import { bytesToString } from "@/utils";
-import TableTemplates from "@/views/SchemaTemplate/TableTemplates.vue";
-import TableNameModal from "../Modals/TableNameModal.vue";
-import { isTableChanged } from "../utils";
-
-const props = defineProps<{
- schemaId: string;
- tableList: Table[];
-}>();
-
-interface LocalState {
- showFeatureModal: boolean;
- showSchemaTemplateDrawer: boolean;
- showClassificationDrawer: boolean;
- tableNameModalContext?: {
- parentName: string;
- schemaId: string;
- tableName: string | undefined;
- };
- activeTableId?: string;
-}
-
-const { t } = useI18n();
-const editorStore = useSchemaEditorV1Store();
-const settingStore = useSettingV1Store();
-const currentTab = computed(
- () => (editorStore.currentTab || {}) as DatabaseTabContext
-);
-const state = reactive<LocalState>({
- showFeatureModal: false,
- showSchemaTemplateDrawer: false,
- showClassificationDrawer: false,
-});
-
-const engine = computed(() => {
- return editorStore.getCurrentEngine(currentTab.value.parentName);
-});
-const readonly = computed(() => editorStore.readonly);
-
-const schemaList = computed(() => {
- return editorStore.currentSchemaList;
-});
-const tableList = computed(() => {
- return props.tableList;
-});
-
-const classificationConfig = computed(() => {
- if (!editorStore.project.dataClassificationConfigId) {
- return;
- }
- return settingStore.getProjectClassification(
- editorStore.project.dataClassificationConfigId
- );
-});
-const disableChangeTable = (table: Table): boolean => {
- return table.status === "dropped";
-};
-
-const getTableClassList = (table: Table, index: number): string[] => {
- const classList = [];
- if (table.status === "dropped") {
- classList.push("text-red-700 !bg-red-50 opacity-70");
- } else if (table.status === "created") {
- classList.push("text-green-700 !bg-green-50");
- } else if (
- isTableChanged(currentTab.value.parentName, props.schemaId, table.id)
- ) {
- classList.push("text-yellow-700 !bg-yellow-50");
- }
- if (index % 2 === 1) {
- classList.push("bg-gray-50");
- }
- return classList;
-};
-
-const showClassificationDrawer = (table: Table) => {
- state.activeTableId = table.id;
- state.showClassificationDrawer = true;
-};
-
-const onClassificationSelect = (classificationId: string) => {
- const table = tableList.value.find(
- (table) => table.id === state.activeTableId
- );
- if (!table) {
- return;
- }
- table.classification = classificationId;
- state.activeTableId = undefined;
-};
-
-const supportClassification = computed(() => {
- return classificationConfig.value;
-});
-
-const tableHeaderList = computed(() => {
- return [
- {
- key: "name",
- title: t("schema-editor.database.name"),
- width: "minmax(auto, 1fr)",
- },
- {
- key: "classification",
- title: t("schema-editor.column.classification"),
- hide: !supportClassification.value,
- width: "minmax(auto, 1.5fr)",
- },
- {
- key: "raw-count",
- title: t("schema-editor.database.row-count"),
- width: "minmax(auto, 0.7fr)",
- },
- {
- key: "data-size",
- title: t("schema-editor.database.data-size"),
- width: "minmax(auto, 0.7fr)",
- },
- {
- key: "engine",
- title: t("schema-editor.database.engine"),
- width: "minmax(auto, 0.7fr)",
- },
- {
- key: "collation",
- title: t("schema-editor.database.collation"),
- width: "minmax(auto, 1fr)",
- },
- {
- key: "comment",
- title: t("schema-editor.database.comment"),
- width: "minmax(auto, 1fr)",
- },
- {
- title: "",
- width: "30px",
- hide: readonly.value,
- },
- ].filter((header) => !header.hide);
-});
-
-const isDroppedTable = (table: Table) => {
- return table.status === "dropped";
-};
-
-const handleTableItemClick = (table: Table) => {
- editorStore.addTab({
- id: generateUniqueTabId(),
- type: SchemaEditorTabType.TabForTable,
- parentName: currentTab.value.parentName,
- schemaId: props.schemaId,
- tableId: table.id,
- name: table.name,
- });
-};
-
-const handleDropTable = (table: Table) => {
- editorStore.dropTable(currentTab.value.parentName, props.schemaId, table.id);
-};
-
-const handleRestoreTable = (table: Table) => {
- editorStore.restoreTable(
- currentTab.value.parentName,
- props.schemaId,
- table.id
- );
-};
-
-const handleApplyTemplate = (template: SchemaTemplateSetting_TableTemplate) => {
- state.showSchemaTemplateDrawer = false;
- if (!hasFeature("bb.feature.schema-template")) {
- state.showFeatureModal = true;
- return;
- }
- if (!template.table || template.engine !== engine.value) {
- return;
- }
-
- const tableEdit = convertTableMetadataToTable(
- template.table,
- "created",
- template.config
- );
-
- const selectedSchema = schemaList.value.find(
- (schema) => schema.id === props.schemaId
- );
- if (selectedSchema) {
- selectedSchema.tableList.push(tableEdit);
- editorStore.addTab({
- id: generateUniqueTabId(),
- type: SchemaEditorTabType.TabForTable,
- parentName: currentTab.value.parentName,
- schemaId: props.schemaId,
- tableId: tableEdit.id,
- name: template.table.name,
- });
- }
-};
-</script>
diff --git a/frontend/src/components/SchemaEditorV1/index.vue b/frontend/src/components/SchemaEditorV1/index.vue
index 78933bcf03..5b7634d759 100644
--- a/frontend/src/components/SchemaEditorV1/index.vue
+++ b/frontend/src/components/SchemaEditorV1/index.vue
@@ -138,7 +138,6 @@ const initialSchemaEditorState = async () => {
onMounted(async () => {
await settingStore.getOrFetchSettingByName("bb.workspace.schema-template");
await prepareBranchContext();
-
await initialSchemaEditorState();
state.initialized = true;
});
diff --git a/frontend/src/types/v1/schemaEditor/atomType.ts b/frontend/src/types/v1/schemaEditor/atomType.ts
index 5bcb8d0018..ee162eccfe 100644
--- a/frontend/src/types/v1/schemaEditor/atomType.ts
+++ b/frontend/src/types/v1/schemaEditor/atomType.ts
@@ -181,15 +181,7 @@ export const convertSchemaMetadataList = (
schemaMetadataList: SchemaMetadata[],
schemaConfigList: SchemaConfig[]
): Schema[] => {
- const tag = [
- "convertSchemaMetadataList",
- `[${schemaMetadataList.map((s) => s.tables.length)}]`,
- `[${schemaConfigList.map((sc) => sc.tableConfigs.length)}]`,
- ].join("--");
- console.debug("go!", tag);
- console.time(tag);
// Compose all tables of each schema.
- console.time("loop-1");
const schemaConfigByName = keyBy(schemaConfigList, (sc) => sc.name);
const schemaList: Schema[] = schemaMetadataList.map((schemaMetadata) =>
convertSchemaMetadataToSchema(
@@ -198,9 +190,7 @@ export const convertSchemaMetadataList = (
schemaConfigByName.get(schemaMetadata.name)
)
);
- console.timeEnd("loop-1");
- console.time("loop-2");
// Build foreign keys for schema and referenced schema.
const schemaByName = keyBy(schemaList, (s) => s.name);
for (const schemaMetadata of schemaMetadataList) {
@@ -259,8 +249,6 @@ export const convertSchemaMetadataList = (
table.foreignKeyList = foreignKeyList;
}
}
- console.timeEnd("loop-2");
- console.timeEnd(tag);
return schemaList;
};