Skip to content

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

chore(frontend): SchemaEditorV1 performance improvements (#9423)

Liu Jica597267617d
diff --git a/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vue b/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vue
index b8eda786a3..9d3b42e94e 100644
--- a/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vue
+++ b/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vue
@@ -2,7 +2,7 @@
<BBModal
:title="$t('database.edit-schema')"
:trap-focus="false"
- class="schema-editor-modal-container !w-[96rem] h-auto overflow-auto !max-w-[calc(100%-40px)] !max-h-[calc(100%-40px)]"
+ class="schema-editor-modal-container !w-[96rem] h-auto overflow-auto !max-w-[calc(100vw-40px)] !max-h-[calc(100vh-40px)]"
@close="dismissModal"
>
<div
diff --git a/frontend/src/components/Branch/BaselineSchemaSelector.vue b/frontend/src/components/Branch/BaselineSchemaSelector.vue
index 059e76ee21..9df5c7a9b9 100644
--- a/frontend/src/components/Branch/BaselineSchemaSelector.vue
+++ b/frontend/src/components/Branch/BaselineSchemaSelector.vue
@@ -1,7 +1,5 @@
<template>
- <div
- class="w-full mx-auto flex flex-col justify-start items-start space-y-3 mb-6"
- >
+ <div class="w-full mx-auto flex flex-col justify-start items-start gap-y-3">
<div class="w-full flex flex-row justify-start items-center">
<span class="flex w-40 items-center shrink-0 text-sm">
{{ $t("common.database") }}
@@ -55,7 +53,7 @@
</template>
<script lang="ts" setup>
-import { head, isNull, isUndefined } from "lodash-es";
+import { debounce, head, isNull, isUndefined } from "lodash-es";
import { NEllipsis, SelectOption } from "naive-ui";
import { computed, h, reactive, watch } from "vue";
import { useI18n } from "vue-i18n";
@@ -330,15 +328,11 @@ const databaseChangeHistoryList = (databaseId: string) => {
return list;
};
-watch(
- () => state,
- () => {
- emit("update", {
- ...state,
- });
- },
- { deep: true }
-);
+const debouncedUpdate = debounce((state: LocalState) => {
+ emit("update", { ...state });
+}, 200);
+
+watch(() => state, debouncedUpdate, { deep: true });
</script>
<style lang="postcss">
.bb-baseline-schema-select-option .n-base-select-option__content {
diff --git a/frontend/src/components/Branch/BranchCreateView.vue b/frontend/src/components/Branch/BranchCreateView.vue
index d1b00ba3f7..6c698b7b19 100644
--- a/frontend/src/components/Branch/BranchCreateView.vue
+++ b/frontend/src/components/Branch/BranchCreateView.vue
@@ -1,5 +1,7 @@
<template>
- <div class="space-y-3 w-full overflow-x-auto px-4 pb-8 pt-4">
+ <div
+ class="w-full h-full flex flex-col gap-y-3 overflow-y-hidden overflow-x-auto px-4 py-4"
+ >
<div
v-if="showProjectSelector"
class="w-full flex flex-row justify-start items-center"
@@ -13,7 +15,7 @@
@update:project="handleProjectSelect"
/>
</div>
- <div class="w-full flex flex-row justify-start items-center mt-1">
+ <div class="w-full flex flex-row justify-start items-center">
<span class="flex w-40 items-center text-sm">{{
$t("database.branch-name")
}}</span>
@@ -34,8 +36,8 @@
@update:branch="(branch) => (state.parentBranchName = branch ?? '')"
/>
</div>
- <NDivider />
- <div class="w-full flex flex-row justify-start items-center mt-1">
+ <NDivider class="!my-0" />
+ <div class="w-full flex flex-row justify-start items-center">
<span class="flex w-full items-center text-sm font-medium">{{
state.parentBranchName
? $t("schema-designer.baseline-version-from-parent")
@@ -49,28 +51,24 @@
:readonly="disallowToChangeBaseline"
@update="handleBaselineSchemaChange"
/>
- <div class="!mt-6 w-full h-[32rem]">
+ <div class="w-full flex-1 overflow-y-hidden">
<SchemaEditorV1
:key="refreshId"
:project="project"
:resource-type="'branch'"
- :branches="[state.schemaDesign]"
+ :branches="branches"
:readonly="true"
/>
</div>
- <div class="w-full flex items-center justify-between mt-4">
- <div></div>
-
- <div class="flex items-center justify-end gap-x-3">
- <NButton
- type="primary"
- :disabled="!allowConfirm"
- :loading="state.isCreating"
- @click.prevent="handleConfirm"
- >
- {{ confirmText }}
- </NButton>
- </div>
+ <div class="w-full flex items-center justify-end">
+ <NButton
+ type="primary"
+ :disabled="!allowConfirm"
+ :loading="state.isCreating"
+ @click.prevent="handleConfirm"
+ >
+ {{ confirmText }}
+ </NButton>
</div>
</div>
</template>
@@ -165,6 +163,9 @@ const disallowToChangeBaseline = computed(() => {
return !!state.parentBranchName;
});
+// Avoid to create array or object literals in template to improve performance
+const branches = computed(() => [state.schemaDesign]);
+
onMounted(async () => {
if (props.projectId) {
state.projectId = props.projectId;
diff --git a/frontend/src/components/Branch/BranchDataTable.vue b/frontend/src/components/Branch/BranchDataTable.vue
index bac64b8b30..ad124cf609 100644
--- a/frontend/src/components/Branch/BranchDataTable.vue
+++ b/frontend/src/components/Branch/BranchDataTable.vue
@@ -7,6 +7,7 @@
:data="dataTableRows"
:row-key="rowKey"
:row-props="rowProps"
+ class="bb-branch-data-table"
/>
</template>
@@ -207,14 +208,14 @@ const getUpdatedTimeStr = (branch: SchemaDesign) => {
};
</script>
-<style lang="postcss">
-.n-data-table-expand-trigger {
+<style lang="postcss" scoped>
+.bb-branch-data-table :deep(.n-data-table-expand-trigger) {
@apply !w-5 !h-5 inline-flex justify-center items-center translate-y-0.5 rounded hover:bg-white hover:shadow;
}
-.n-data-table-expand-trigger > .n-base-icon {
+.bb-branch-data-table :deep(.n-data-table-expand-trigger > .n-base-icon) {
@apply !w-5 !h-5 flex flex-row justify-center items-center;
}
-.n-data-table .n-data-table-td {
+.bb-branch-data-table :deep(.n-data-table-td) {
background-color: transparent !important;
}
</style>
diff --git a/frontend/src/components/Branch/SchemaDesignEditor.vue b/frontend/src/components/Branch/SchemaDesignEditor.vue
index 5e4baf005b..281955f2ea 100644
--- a/frontend/src/components/Branch/SchemaDesignEditor.vue
+++ b/frontend/src/components/Branch/SchemaDesignEditor.vue
@@ -41,7 +41,7 @@
:project="project"
:readonly="readonly"
:resource-type="'branch'"
- :branches="[branch]"
+ :branches="branches"
/>
</div>
<div
@@ -106,6 +106,9 @@ const baselineDatabase = computed(() => {
return databaseStore.getDatabaseByName(props.branch.baselineDatabase);
});
+// Avoid to create array or object literals in template to improve performance
+const branches = computed(() => [props.branch]);
+
const handleChangeTab = async (tab: TabType) => {
state.selectedTab = tab;
if (tab === "raw-sql-preview") {
diff --git a/frontend/src/components/SchemaEditorV1/Aside/BranchTree.vue b/frontend/src/components/SchemaEditorV1/Aside/BranchTree.vue
index 188bfaa03e..79417c7850 100644
--- a/frontend/src/components/SchemaEditorV1/Aside/BranchTree.vue
+++ b/frontend/src/components/SchemaEditorV1/Aside/BranchTree.vue
@@ -1,6 +1,8 @@
<template>
- <div class="w-full h-full px-2 space-y-2 relative overflow-y-hidden">
- <div class="w-full flex sticky top-0 pt-2 bg-white z-10 space-x-2">
+ <div
+ class="w-full h-full px-2 flex flex-col gap-y-2 relative overflow-y-hidden"
+ >
+ <div class="w-full flex pt-2 bg-white z-10 space-x-2">
<NInput
v-model:value="searchPattern"
size="small"
@@ -19,14 +21,18 @@
</button>
</div>
<div
- class="schema-designer-database-tree pb-2 overflow-y-auto h-full text-sm"
+ ref="treeContainerElRef"
+ class="schema-designer-database-tree flex-1 pb-1 text-sm overflow-hidden select-none"
+ :data-height="treeContainerHeight"
>
<NTree
:key="treeKeyRef"
ref="treeRef"
block-line
virtual-scroll
- style="height: 100%"
+ :style="{
+ height: `${treeContainerHeight}px`,
+ }"
:data="treeData"
:pattern="searchPattern"
:render-prefix="renderPrefix"
@@ -68,6 +74,7 @@
</template>
<script lang="ts" setup>
+import { useElementSize } from "@vueuse/core";
import { escape, head, isUndefined } from "lodash-es";
import { TreeOption, NEllipsis, NInput, NDropdown, NTree } from "naive-ui";
import { v1 as uuidv1 } from "uuid";
@@ -135,6 +142,14 @@ const state = reactive<LocalState>({
const readonly = computed(() => schemaEditorV1Store.readonly);
const currentTab = computed(() => schemaEditorV1Store.currentTab);
+const treeContainerElRef = ref<HTMLElement>();
+const { height: treeContainerHeight } = useElementSize(
+ treeContainerElRef,
+ undefined,
+ {
+ box: "content-box",
+ }
+);
const treeRef = ref<InstanceType<typeof NTree>>();
const searchPattern = ref("");
const expandedKeysRef = ref<string[]>([]);
@@ -670,37 +685,30 @@ const handleExpandedKeysChange = (expandedKeys: string[]) => {
};
</script>
-<style>
-.schema-designer-database-tree .n-tree-node-wrapper {
+<style lang="postcss" scoped>
+.schema-designer-database-tree :deep(.n-tree-node-wrapper) {
@apply !p-0;
}
-.schema-designer-database-tree .n-tree-node-content {
+.schema-designer-database-tree :deep(.n-tree-node-content) {
@apply !pl-2 text-sm;
}
-.schema-designer-database-tree .n-tree-node-indent {
+.schema-designer-database-tree :deep(.n-tree-node-indent) {
width: 0.25rem;
}
-.schema-designer-database-tree .n-tree-node-content__suffix {
+.schema-designer-database-tree :deep(.n-tree-node-content__suffix) {
@apply rounded-sm !hidden hover:opacity-80;
}
.schema-designer-database-tree
- .n-tree-node-wrapper:hover
- .n-tree-node-content__suffix {
+ :deep(.n-tree-node-wrapper:hover .n-tree-node-content__suffix) {
@apply !flex;
}
.schema-designer-database-tree
- .n-tree-node-wrapper
- .n-tree-node--selected
- .n-tree-node-content__suffix {
+ :deep(.n-tree-node-wrapper
+ .n-tree-node--selected
+ .n-tree-node-content__suffix) {
@apply !flex;
}
-.schema-designer-database-tree .n-tree-node-switcher {
+.schema-designer-database-tree :deep(.n-tree-node-switcher) {
@apply px-0 !w-4 !h-7;
}
</style>
-
-<style scoped>
-.schema-designer-database-tree {
- max-height: calc(100% - 80px);
-}
-</style>
diff --git a/frontend/src/components/SchemaEditorV1/Aside/DatabaseTree.vue b/frontend/src/components/SchemaEditorV1/Aside/DatabaseTree.vue
index bc26d47715..e1660f96c4 100644
--- a/frontend/src/components/SchemaEditorV1/Aside/DatabaseTree.vue
+++ b/frontend/src/components/SchemaEditorV1/Aside/DatabaseTree.vue
@@ -1,5 +1,7 @@
<template>
- <div class="w-full h-full pl-1 pr-2 relative overflow-y-hidden">
+ <div
+ class="w-full h-full pl-1 pr-2 flex flex-col gap-y-2 relative overflow-y-hidden"
+ >
<div class="w-full sticky top-0 pt-2 h-12 bg-white z-10">
<NInput
v-model:value="searchPattern"
@@ -11,7 +13,9 @@
</NInput>
</div>
<div
- class="schema-editor-database-tree pb-2 overflow-y-auto h-full text-sm"
+ ref="treeContainerElRef"
+ class="schema-editor-database-tree flex-1 pb-1 text-sm overflow-hidden select-none"
+ :data-height="treeContainerHeight"
>
<NTree
ref="treeRef"
@@ -61,6 +65,7 @@
</template>
<script lang="ts" setup>
+import { useElementSize } from "@vueuse/core";
import { escape, head, isUndefined } from "lodash-es";
import { TreeOption, NEllipsis, NInput, NDropdown, NTree } from "naive-ui";
import { computed, onMounted, watch, ref, h, reactive, nextTick } from "vue";
@@ -161,6 +166,14 @@ const contextMenu = reactive<TreeContextMenu>({
clientY: 0,
treeNode: undefined,
});
+const treeContainerElRef = ref<HTMLElement>();
+const { height: treeContainerHeight } = useElementSize(
+ treeContainerElRef,
+ undefined,
+ {
+ box: "content-box",
+ }
+);
const treeRef = ref<InstanceType<typeof NTree>>();
const searchPattern = ref("");
const expandedKeysRef = ref<string[]>([]);
@@ -800,37 +813,30 @@ const handleExpandedKeysChange = (expandedKeys: string[]) => {
};
</script>
-<style lang="postcss">
-.schema-editor-database-tree .n-tree-node-wrapper {
+<style lang="postcss" scoped>
+.schema-editor-database-tree :deep(.n-tree-node-wrapper) {
@apply !p-0;
}
-.schema-editor-database-tree .n-tree-node-content {
+.schema-editor-database-tree :deep(.n-tree-node-content) {
@apply !pl-2 text-sm;
}
-.schema-editor-database-tree .n-tree-node-indent {
+.schema-editor-database-tree :deep(.n-tree-node-indent) {
width: 0.25rem;
}
-.schema-editor-database-tree .n-tree-node-content__prefix {
+.schema-editor-database-tree :deep(.n-tree-node-content__prefix) {
@apply shrink-0 !mr-1;
}
.schema-editor-database-tree
- .n-tree-node-wrapper:hover
- .n-tree-node-content__suffix {
+ :deep(.n-tree-node-wrapper:hover .n-tree-node-content__suffix) {
@apply !flex;
}
.schema-editor-database-tree
- .n-tree-node-wrapper
- .n-tree-node--selected
- .n-tree-node-content__suffix {
+ :deep(.n-tree-node-wrapper
+ .n-tree-node--selected
+ .n-tree-node-content__suffix) {
@apply !flex;
}
-.schema-editor-database-tree .n-tree-node-switcher {
+.schema-editor-database-tree :deep(.n-tree-node-switcher) {
@apply px-0 !w-4 !h-7;
}
</style>
-
-<style scoped>
-.schema-editor-database-tree {
- max-height: calc(100% - 48px);
-}
-</style>
diff --git a/frontend/src/components/SchemaEditorV1/Editor.vue b/frontend/src/components/SchemaEditorV1/Editor.vue
index 704c49e25c..6cc47e7dc9 100644
--- a/frontend/src/components/SchemaEditorV1/Editor.vue
+++ b/frontend/src/components/SchemaEditorV1/Editor.vue
@@ -1,11 +1,11 @@
<template>
- <main class="px-2 pt-2 w-full h-full flex flex-col overflow-y-auto">
+ <main class="px-2 py-2 w-full h-full flex flex-col overflow-y-hidden">
<template v-if="currentTab">
<TabsContainer
@on-table-search-pattern="handleTableSearchPattern"
@on-column-search-pattern="handleColumnSearchPattern"
/>
- <div :key="currentTab.id" class="w-full h-full relative overflow-y-auto">
+ <div :key="currentTab.id" class="w-full flex-1 relative overflow-hidden">
<DatabaseEditor
v-if="currentTab.type === SchemaEditorTabType.TabForDatabase"
:search-pattern="state.tableSearchPattern"
diff --git a/frontend/src/components/SchemaEditorV1/Modals/ColumnDefaultValueExpressionModal.vue b/frontend/src/components/SchemaEditorV1/Modals/ColumnDefaultValueExpressionModal.vue
index f4dbd8bc56..55516e545a 100644
--- a/frontend/src/components/SchemaEditorV1/Modals/ColumnDefaultValueExpressionModal.vue
+++ b/frontend/src/components/SchemaEditorV1/Modals/ColumnDefaultValueExpressionModal.vue
@@ -5,25 +5,27 @@
@close="dismissModal"
>
<div class="w-72">
- <BBTextField
- class="my-2 w-full"
- :value="state.expression"
- @input="handleExpressionChange"
+ <NInput
+ ref="inputRef"
+ v-model:value="state.expression"
+ class="my-2"
+ :autofocus="true"
/>
</div>
- <div class="w-full flex items-center justify-end mt-2 space-x-3 pr-1 pb-1">
- <button type="button" class="btn-normal" @click="dismissModal">
+ <div class="w-full flex items-center justify-end mt-2 space-x-3">
+ <NButton @click="dismissModal">
{{ $t("common.cancel") }}
- </button>
- <button class="btn-primary" @click="handleConfirmButtonClick">
+ </NButton>
+ <NButton type="primary" @click="handleConfirmButtonClick">
{{ $t("common.save") }}
- </button>
+ </NButton>
</div>
</BBModal>
</template>
<script lang="ts" setup>
-import { reactive } from "vue";
+import { InputInst, NButton, NInput } from "naive-ui";
+import { onMounted, reactive, ref } from "vue";
import { useNotificationStore } from "@/store";
interface LocalState {
@@ -39,15 +41,12 @@ const emit = defineEmits<{
(event: "update:expression", value: string): void;
}>();
+const inputRef = ref<InputInst>();
const notificationStore = useNotificationStore();
const state = reactive<LocalState>({
expression: props.expression || "",
});
-const handleExpressionChange = (event: Event) => {
- state.expression = (event.target as HTMLInputElement).value;
-};
-
const handleConfirmButtonClick = async () => {
if (!state.expression) {
notificationStore.pushNotification({
@@ -65,4 +64,8 @@ const handleConfirmButtonClick = async () => {
const dismissModal = () => {
emit("close");
};
+
+onMounted(() => {
+ inputRef.value?.focus();
+});
</script>
diff --git a/frontend/src/components/SchemaEditorV1/Modals/TableNameModal.vue b/frontend/src/components/SchemaEditorV1/Modals/TableNameModal.vue
index 722b7e5b39..5a66d0449a 100644
--- a/frontend/src/components/SchemaEditorV1/Modals/TableNameModal.vue
+++ b/frontend/src/components/SchemaEditorV1/Modals/TableNameModal.vue
@@ -10,27 +10,27 @@
>
<div class="w-72">
<p>{{ $t("schema-editor.table.name") }}</p>
- <BBTextField
- class="my-2 w-full"
- :required="true"
- :focus-on-mount="true"
- :value="state.tableName"
- @input="handleTableNameChange"
+ <NInput
+ ref="inputRef"
+ v-model:value="state.tableName"
+ class="my-2"
+ :autofocus="true"
/>
</div>
- <div class="w-full flex items-center justify-end mt-2 space-x-3 pr-1 pb-1">
- <button type="button" class="btn-normal" @click="dismissModal">
+ <div class="w-full flex items-center justify-end mt-2 space-x-3">
+ <NButton @click="dismissModal">
{{ $t("common.cancel") }}
- </button>
- <button class="btn-primary" @click="handleConfirmButtonClick">
+ </NButton>
+ <NButton type="primary" @click="handleConfirmButtonClick">
{{ isCreatingTable ? $t("common.create") : $t("common.save") }}
- </button>
+ </NButton>
</div>
</BBModal>
</template>
<script lang="ts" setup>
-import { computed, reactive } from "vue";
+import { InputInst, NButton, NInput } from "naive-ui";
+import { computed, onMounted, reactive, ref } from "vue";
import { useI18n } from "vue-i18n";
import {
generateUniqueTabId,
@@ -65,6 +65,7 @@ const emit = defineEmits<{
}>();
const { t } = useI18n();
+const inputRef = ref<InputInst>();
const schemaEditorV1Store = useSchemaEditorV1Store();
const notificationStore = useNotificationStore();
const state = reactive<LocalState>({
@@ -79,10 +80,6 @@ const isCreatingTable = computed(() => {
return props.tableId === undefined;
});
-const handleTableNameChange = (event: Event) => {
- state.tableName = (event.target as HTMLInputElement).value;
-};
-
const handleConfirmButtonClick = async () => {
if (!tableNameFieldRegexp.test(state.tableName)) {
notificationStore.pushNotification({
@@ -153,4 +150,8 @@ const handleConfirmButtonClick = async () => {
const dismissModal = () => {
emit("close");
};
+
+onMounted(() => {
+ inputRef.value?.focus();
+});
</script>
diff --git a/frontend/src/components/SchemaEditorV1/Panels/DatabaseEditor.vue b/frontend/src/components/SchemaEditorV1/Panels/DatabaseEditor.vue
index 1f6aaa8d4c..88a789b78d 100644
--- a/frontend/src/components/SchemaEditorV1/Panels/DatabaseEditor.vue
+++ b/frontend/src/components/SchemaEditorV1/Panels/DatabaseEditor.vue
@@ -1,5 +1,5 @@
<template>
- <div class="flex flex-col w-full h-full overflow-y-auto">
+ <div class="flex flex-col w-full h-full overflow-y-hidden">
<div class="py-2 w-full flex flex-row justify-between items-center">
<div>
<div
@@ -70,26 +70,28 @@
</div>
</div>
- <!-- List view -->
- <template v-if="state.selectedSubtab === 'table-list'">
- <TableList
- :schema-id="selectedSchema?.id || ''"
- :table-list="shownTableList"
- />
- </template>
- <template v-else-if="state.selectedSubtab === 'schema-diagram'">
- <SchemaDiagram
- :key="currentTab.parentName"
- :database="databaseV1"
- :database-metadata="databaseMetadata"
- :schema-status="schemaStatus"
- :table-status="tableStatus"
- :column-status="columnStatus"
- :editable="true"
- @edit-table="tryEditTable"
- @edit-column="tryEditColumn"
- />
- </template>
+ <div class="flex-1 overflow-y-hidden">
+ <!-- List view -->
+ <template v-if="state.selectedSubtab === 'table-list'">
+ <TableList
+ :schema-id="selectedSchema?.id || ''"
+ :table-list="shownTableList"
+ />
+ </template>
+ <template v-else-if="state.selectedSubtab === 'schema-diagram'">
+ <SchemaDiagram
+ :key="currentTab.parentName"
+ :database="databaseV1"
+ :database-metadata="databaseMetadata"
+ :schema-status="schemaStatus"
+ :table-status="tableStatus"
+ :column-status="columnStatus"
+ :editable="true"
+ @edit-table="tryEditTable"
+ @edit-column="tryEditColumn"
+ />
+ </template>
+ </div>
</div>
<TableNameModal
@@ -151,7 +153,7 @@ import {
import TableTemplates from "@/views/SchemaTemplate/TableTemplates.vue";
import TableNameModal from "../Modals/TableNameModal.vue";
import { useMetadataForDiagram } from "../utils/useMetadataForDiagram";
-import TableList from "./TableList.vue";
+import TableList from "./TableList";
const props = withDefaults(
defineProps<{
diff --git a/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor.vue b/frontend/src/components/SchemaEditorV1/Panels/LegacyTableColumnEditor.vue
similarity index 100%
rename from frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor.vue
rename to frontend/src/components/SchemaEditorV1/Panels/LegacyTableColumnEditor.vue
diff --git a/frontend/src/components/SchemaEditorV1/Panels/TableList.vue b/frontend/src/components/SchemaEditorV1/Panels/LegacyTableList.vue
similarity index 99%
rename from frontend/src/components/SchemaEditorV1/Panels/TableList.vue
rename to frontend/src/components/SchemaEditorV1/Panels/LegacyTableList.vue
index 80f9d0c76c..d8abebc9f2 100644
--- a/frontend/src/components/SchemaEditorV1/Panels/TableList.vue
+++ b/frontend/src/components/SchemaEditorV1/Panels/LegacyTableList.vue
@@ -1,6 +1,7 @@
<template>
<div class="w-full h-full">
<BBGrid
+ v-if="false"
class="border"
:column-list="tableHeaderList"
:data-source="tableList"
diff --git a/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/TableColumnEditor.vue b/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/TableColumnEditor.vue
new file mode 100644
index 0000000000..e29427923e
--- /dev/null
+++ b/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/TableColumnEditor.vue
@@ -0,0 +1,537 @@
+<template>
+ <div
+ ref="containerElRef"
+ class="w-full h-full"
+ :data-height="containerHeight"
+ :data-table-header-height="tableHeaderHeight"
+ :data-table-body-height="tableBodyHeight"
+ >
+ <NDataTable
+ v-bind="$attrs"
+ size="small"
+ :row-key="(column: Column) => column.id"
+ :columns="columns"
+ :data="shownColumnList"
+ :row-class-name="classesForRow"
+ :max-height="tableBodyHeight"
+ :virtual-scroll="true"
+ :striped="true"
+ class="schema-editor-table-column-editor"
+ />
+ </div>
+
+ <ColumnDefaultValueExpressionModal
+ v-if="editColumnDefaultValueExpressionContext"
+ :expression="editColumnDefaultValueExpressionContext.defaultExpression"
+ @close="editColumnDefaultValueExpressionContext = undefined"
+ @update:expression="handleSelectColumnDefaultValueExpression"
+ />
+
+ <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 { useElementSize } from "@vueuse/core";
+import { flatten } from "lodash-es";
+import { DataTableColumn, NCheckbox, NDataTable } from "naive-ui";
+import { computed, h, reactive, ref } from "vue";
+import { useI18n } from "vue-i18n";
+import LabelEditorDrawer from "@/components/LabelEditorDrawer.vue";
+import SelectClassificationDrawer from "@/components/SchemaTemplate/SelectClassificationDrawer.vue";
+import SemanticTypesDrawer from "@/components/SensitiveData/components/SemanticTypesDrawer.vue";
+import { InlineInput } from "@/components/v2";
+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 ColumnDefaultValueExpressionModal from "../../Modals/ColumnDefaultValueExpressionModal.vue";
+import {
+ getDefaultValueByKey,
+ isTextOfColumnType,
+} from "../../utils/columnDefaultValue";
+import {
+ ClassificationCell,
+ DataTypeCell,
+ ForeignKeyCell,
+ OperationCell,
+ SemanticTypeCell,
+} from "./components";
+import DefaultValueCell from "./components/DefaultValueCell.vue";
+import LabelsCell from "./components/LabelsCell.vue";
+
+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) => "",
+ }
+);
+
+const emit = defineEmits<{
+ (event: "drop", column: Column): void;
+ (event: "restore", column: Column): void;
+ (event: "edit", index: number): void;
+ (event: "foreign-key-edit", column: Column): void;
+ (event: "foreign-key-click", column: Column): void;
+ (event: "primary-key-set", column: Column, isPrimaryKey: boolean): void;
+}>();
+
+const state = reactive<LocalState>({
+ showClassificationDrawer: false,
+ showSemanticTypesDrawer: false,
+ showLabelsDrawer: false,
+});
+
+const containerElRef = ref<HTMLElement>();
+const tableHeaderElRef = computed(
+ () =>
+ containerElRef.value?.querySelector("thead.n-data-table-thead") as
+ | HTMLElement
+ | undefined
+);
+const { height: containerHeight } = useElementSize(containerElRef);
+const { height: tableHeaderHeight } = useElementSize(tableHeaderElRef);
+const tableBodyHeight = computed(() => {
+ return containerHeight.value - tableHeaderHeight.value - 2;
+});
+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 showSemanticTypeColumn = computed(() => {
+ return subscriptionV1Store.hasFeature("bb.feature.sensitive-data");
+});
+
+const columns = computed(() => {
+ const columns: (DataTableColumn<Column> & { hide?: boolean })[] = [
+ {
+ key: "name",
+ title: t("schema-editor.column.name"),
+ resizable: true,
+ width: 140,
+ className: "input-cell",
+ render: (column) => {
+ return h(InlineInput, {
+ value: column.name,
+ disabled: props.readonly || props.disableAlterColumn(column),
+ placeholder: "column name",
+ style: {
+ "--n-padding-left": "6px",
+ "--n-padding-right": "4px",
+ "--n-text-color-disabled": "rgb(var(--color-main))",
+ },
+ "onUpdate:value": (value) => (column.name = value),
+ });
+ },
+ },
+ {
+ key: "semantic-types",
+ title: t("settings.sensitive-data.semantic-types.self"),
+ resizable: true,
+ width: 140,
+ hide: !showSemanticTypeColumn.value,
+ render: (column) => {
+ return h(SemanticTypeCell, {
+ column,
+ readonly: props.readonly,
+ disabled: props.disableChangeTable,
+ semanticTypeList: semanticTypeList.value,
+ disableAlterColumn: props.disableAlterColumn,
+ onRemove: () => onSemanticTypeRemove(column),
+ onEdit: () => openSemanticTypeDrawer(column),
+ });
+ },
+ },
+ {
+ key: "classification",
+ title: t("schema-editor.column.classification"),
+ hide: !classificationConfig.value,
+ resizable: true,
+ width: 140,
+ render: (column) => {
+ return h(ClassificationCell, {
+ column,
+ readonly: props.readonly,
+ disabled: props.disableChangeTable,
+ classificationConfig: classificationConfig.value,
+ onEdit: () => openClassificationDrawer(column),
+ onRemove: () => (column.classification = ""),
+ });
+ },
+ },
+ {
+ key: "type",
+ title: t("schema-editor.column.type"),
+ resizable: true,
+ width: 140,
+ className: "input-cell",
+ render: (column) => {
+ return h(DataTypeCell, {
+ column,
+ disabled: props.readonly || props.disableAlterColumn(column),
+ schemaTemplateColumnTypes: schemaTemplateColumnTypes.value,
+ engine: props.engine,
+ "onUpdate:value": (value) => (column.type = value),
+ });
+ },
+ },
+ {
+ key: "default-value",
+ title: t("schema-editor.column.default"),
+ resizable: true,
+ width: 140,
+ className: "input-cell",
+ render: (column) => {
+ return h(DefaultValueCell, {
+ column,
+ disabled: props.readonly || props.disableAlterColumn(column),
+ schemaTemplateColumnTypes: schemaTemplateColumnTypes.value,
+ engine: props.engine,
+ onInput: (value) => handleColumnDefaultInput(column, value),
+ onSelect: (option) => handleColumnDefaultSelect(column, option.key),
+ });
+ },
+ },
+ {
+ key: "comment",
+ title: t("schema-editor.column.comment"),
+ resizable: true,
+ width: 140,
+ className: "input-cell",
+ render: (column) => {
+ return h(InlineInput, {
+ value: column.userComment,
+ disabled: props.readonly || props.disableAlterColumn(column),
+ placeholder: "comment",
+ style: {
+ "--n-padding-left": "6px",
+ "--n-padding-right": "4px",
+ "--n-text-color-disabled": "rgb(var(--color-main))",
+ },
+ "onUpdate:value": (value) => (column.userComment = value),
+ });
+ },
+ },
+ {
+ key: "not-null",
+ title: t("schema-editor.column.not-null"),
+ resizable: true,
+ width: 80,
+ className: "checkbox-cell",
+ render: (column) => {
+ return h(NCheckbox, {
+ checked: !column.nullable,
+ disabled:
+ props.readonly ||
+ props.disableAlterColumn(column) ||
+ isColumnPrimaryKey(column),
+ "onUpdate:checked": (checked: boolean) =>
+ (column.nullable = !checked),
+ });
+ },
+ },
+ {
+ key: "primary",
+ title: t("schema-editor.column.primary"),
+ resizable: true,
+ width: 80,
+ className: "checkbox-cell",
+ render: (column) => {
+ return h(NCheckbox, {
+ checked: isColumnPrimaryKey(column),
+ disabled: props.readonly || props.disableAlterColumn(column),
+ "onUpdate:checked": (checked: boolean) =>
+ emit("primary-key-set", column, checked),
+ });
+ },
+ },
+ {
+ key: "foreign-key",
+ title: t("schema-editor.column.foreign-key"),
+ hide: !props.showForeignKey,
+ resizable: true,
+ width: 140,
+ className: "text-cell",
+ render: (column) => {
+ return h(ForeignKeyCell, {
+ column,
+ readonly: props.readonly,
+ disabled: props.readonly || props.disableAlterColumn(column),
+ hasForeignKey: checkColumnHasForeignKey(column),
+ referencedForeignKeyName: props.getReferencedForeignKeyName(column),
+ onClick: () => emit("foreign-key-click", column),
+ onEdit: () => emit("foreign-key-edit", column),
+ });
+ },
+ },
+ {
+ key: "labels",
+ title: t("common.labels"),
+ resizable: true,
+ width: 140,
+ render: (column) => {
+ return h(LabelsCell, {
+ column,
+ readonly: props.readonly,
+ disabled: props.disableChangeTable,
+ onEdit: () => openLabelsDrawer(column),
+ });
+ },
+ },
+ {
+ key: "operations",
+ title: "",
+ resizable: false,
+ width: 30,
+ hide: props.readonly,
+ className: "!px-0",
+ render: (column) => {
+ return h(OperationCell, {
+ column,
+ readonly: props.readonly || !isDroppedColumn(column),
+ disabled: props.disableChangeTable,
+ onDrop: () => emit("drop", column),
+ onRestore: () => emit("restore", column),
+ });
+ },
+ },
+ ];
+ return columns.filter((header) => !header.hide);
+});
+
+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 handleColumnDefaultInput = (column: Column, value: string) => {
+ 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 handleColumnDefaultSelect = (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 handleSelectColumnDefaultValueExpression = (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: "",
+ });
+};
+
+const classesForRow = (column: Column, index: number) => {
+ return props.getColumnItemComputedClassList(column);
+};
+
+const isDroppedColumn = (column: Column): boolean => {
+ return column.status === "dropped";
+};
+</script>
+
+<style lang="postcss" scoped>
+.schema-editor-table-column-editor
+ :deep(.n-data-table-th .n-data-table-resize-button::after) {
+ @apply bg-control-bg h-2/3;
+}
+.schema-editor-table-column-editor :deep(.n-data-table-td.input-cell) {
+ @apply pl-0.5 pr-1 py-0;
+}
+.schema-editor-table-column-editor
+ :deep(.n-data-table-td.input-cell .n-input__placeholder),
+.schema-editor-table-column-editor
+ :deep(.n-data-table-td.input-cell .n-base-selection-placeholder) {
+ @apply italic;
+}
+.schema-editor-table-column-editor :deep(.n-data-table-td.checkbox-cell) {
+ @apply pr-1 py-0;
+}
+.schema-editor-table-column-editor :deep(.n-data-table-td.text-cell) {
+ @apply pr-1 py-0;
+}
+.schema-editor-table-column-editor
+ :deep(.n-data-table-tr.created .n-data-table-td) {
+ @apply text-green-700 !bg-green-50;
+}
+.schema-editor-table-column-editor
+ :deep(.n-data-table-tr.dropped .n-data-table-td) {
+ @apply text-red-700 cursor-not-allowed !bg-red-50 opacity-70;
+}
+.schema-editor-table-column-editor
+ :deep(.n-data-table-tr.updated .n-data-table-td) {
+ @apply text-yellow-700 !bg-yellow-50;
+}
+</style>
diff --git a/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/components/ClassificationCell.vue b/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/components/ClassificationCell.vue
new file mode 100644
index 0000000000..c0813c417d
--- /dev/null
+++ b/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/components/ClassificationCell.vue
@@ -0,0 +1,41 @@
+<template>
+ <div class="flex flex-row items-center">
+ <ClassificationLevelBadge
+ :classification="column.classification"
+ :classification-config="classificationConfig"
+ />
+ <template v-if="!readonly && !disabled">
+ <MiniActionButton
+ v-if="column.classification"
+ @click.prevent="$emit('remove')"
+ >
+ <XIcon class="w-3 h-3" />
+ </MiniActionButton>
+ <MiniActionButton
+ class="w-4 h-4 p-0.5 hover:bg-control-bg-hover rounded cursor-pointer"
+ @click.prevent="$emit('edit')"
+ >
+ <PencilIcon class="w-3 h-3" />
+ </MiniActionButton>
+ </template>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { PencilIcon, XIcon } from "lucide-vue-next";
+import ClassificationLevelBadge from "@/components/SchemaTemplate/ClassificationLevelBadge.vue";
+import { MiniActionButton } from "@/components/v2";
+import { DataClassificationSetting_DataClassificationConfig as DataClassificationConfig } from "@/types/proto/v1/setting_service";
+import { Column } from "@/types/v1/schemaEditor";
+
+defineProps<{
+ column: Column;
+ readonly?: boolean;
+ disabled?: boolean;
+ classificationConfig: DataClassificationConfig;
+}>();
+defineEmits<{
+ (event: "edit"): void;
+ (event: "remove"): void;
+}>();
+</script>
diff --git a/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/components/DataTypeCell.vue b/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/components/DataTypeCell.vue
new file mode 100644
index 0000000000..a064a499a9
--- /dev/null
+++ b/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/components/DataTypeCell.vue
@@ -0,0 +1,90 @@
+<template>
+ <DropdownInput
+ :value="column.type || null"
+ :allow-input-value="allowInputValue"
+ :options="columnTypeOptions"
+ :consistent-menu-width="false"
+ :style="style"
+ suffix-style="right: 3px"
+ placeholder="column type"
+ class="bb-schema-editor--column-data-type-select"
+ @focus="focused = true"
+ @blur="focused = false"
+ @update:value="$emit('update:value', $event)"
+ />
+</template>
+
+<script lang="ts" setup>
+import { SelectOption } from "naive-ui";
+import { CSSProperties, computed, ref } from "vue";
+import { DropdownInput } from "@/components/v2";
+import { Engine } from "@/types/proto/v1/common";
+import { Column } from "@/types/v1/schemaEditor";
+import { getDataTypeSuggestionList } from "@/utils";
+
+const props = defineProps<{
+ column: Column;
+ readonly?: boolean;
+ engine: Engine;
+ schemaTemplateColumnTypes: string[];
+}>();
+defineEmits<{
+ (event: "update:value", value: string): void;
+}>();
+
+const focused = ref(false);
+
+const allowInputValue = computed(() => {
+ return props.schemaTemplateColumnTypes.length === 0;
+});
+
+const columnTypeOptions = computed(() => {
+ const { schemaTemplateColumnTypes, engine } = props;
+ if (allowInputValue.value) {
+ return getDataTypeSuggestionList(engine).map<SelectOption>((dataType) => {
+ return {
+ value: dataType,
+ label: dataType,
+ };
+ });
+ }
+ return schemaTemplateColumnTypes.map<SelectOption>((columnType) => {
+ return {
+ value: columnType,
+ label: columnType,
+ };
+ });
+});
+
+const style = computed(() => {
+ const style: CSSProperties = {
+ "--n-padding-left": "6px",
+ "--n-padding-right": "16px",
+ "--n-color": "transparent",
+ "--n-color-disabled": "transparent",
+ "--n-text-color-disabled": "rgb(var(--color-main))",
+ cursor: "default",
+ };
+ const border = focused.value
+ ? "1px solid rgb(var(--color-control-border))"
+ : "none";
+ style["--n-border"] = border;
+ style["--n-border-disabled"] = border;
+
+ return style;
+});
+</script>
+
+<style lang="postcss" scoped>
+.bb-schema-editor--column-data-type-select :deep(.n-base-selection) {
+ --n-padding-single: 0 16px 0 6px !important;
+ --n-color: transparent !important;
+ --n-color-disabled: transparent !important;
+ --n-border: none !important;
+ --n-text-color-disabled: rgb(var(--color-main)) !important;
+}
+.bb-schema-editor--column-data-type-select
+ :deep(.n-base-selection .n-base-suffix) {
+ right: 4px;
+}
+</style>
diff --git a/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/components/DefaultValueCell.vue b/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/components/DefaultValueCell.vue
new file mode 100644
index 0000000000..665692b1fc
--- /dev/null
+++ b/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/components/DefaultValueCell.vue
@@ -0,0 +1,100 @@
+<template>
+ <DropdownInput
+ :value="value"
+ :options="options"
+ :placeholder="placeholder"
+ :consistent-menu-width="false"
+ :style="style"
+ suffix-style="right: 3px"
+ class="bb-schema-editor--column-default-value-select"
+ @focus="focused = true"
+ @blur="focused = false"
+ @update:value="handleUpdateValue"
+ />
+</template>
+
+<script lang="ts" setup>
+import { SelectOption } from "naive-ui";
+import { CSSProperties, computed, ref } from "vue";
+import {
+ DefaultValueOption,
+ getColumnDefaultDisplayString,
+ getColumnDefaultValueOptions,
+ getColumnDefaultValuePlaceholder,
+ getDefaultValueByKey,
+} from "@/components/SchemaEditorV1/utils/columnDefaultValue";
+import { DropdownInput } from "@/components/v2";
+import { Engine } from "@/types/proto/v1/common";
+import { Column } from "@/types/v1/schemaEditor";
+
+const props = defineProps<{
+ column: Column;
+ engine: Engine;
+}>();
+const emit = defineEmits<{
+ (event: "input", value: string): void;
+ (event: "select", option: DefaultValueOption): void;
+}>();
+const focused = ref(false);
+
+const value = computed(() => {
+ return getColumnDefaultDisplayString(props.column) ?? null;
+});
+
+const placeholder = computed(() => {
+ return getColumnDefaultValuePlaceholder(props.column);
+});
+
+const options = computed(() => {
+ return getColumnDefaultValueOptions(
+ props.engine,
+ props.column.type
+ ).map<SelectOption>((opt) => ({
+ value: opt.key,
+ label: opt.label as string,
+ defaultValue: opt.value,
+ }));
+});
+
+const handleUpdateValue = (key: string) => {
+ const value = getDefaultValueByKey(key);
+ if (value) {
+ emit("select", { key, value });
+ return;
+ }
+
+ emit("input", key);
+};
+
+const style = computed(() => {
+ const style: CSSProperties = {
+ "--n-padding-left": "6px",
+ "--n-padding-right": "16px",
+ "--n-color": "transparent",
+ "--n-color-disabled": "transparent",
+ "--n-text-color-disabled": "rgb(var(--color-main))",
+ cursor: "default",
+ };
+ const border = focused.value
+ ? "1px solid rgb(var(--color-control-border))"
+ : "none";
+ style["--n-border"] = border;
+ style["--n-border-disabled"] = border;
+
+ return style;
+});
+</script>
+
+<style lang="postcss" scoped>
+.bb-schema-editor--column-default-value-select :deep(.n-base-selection) {
+ --n-padding-single: 0 16px 0 6px !important;
+ --n-color: transparent !important;
+ --n-color-disabled: transparent !important;
+ --n-border: none !important;
+ --n-text-color-disabled: rgb(var(--color-main)) !important;
+}
+.bb-schema-editor--column-default-value-select
+ :deep(.n-base-selection .n-base-suffix) {
+ right: 4px;
+}
+</style>
diff --git a/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/components/ForeignKeyCell.vue b/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/components/ForeignKeyCell.vue
new file mode 100644
index 0000000000..7b64e510ba
--- /dev/null
+++ b/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/components/ForeignKeyCell.vue
@@ -0,0 +1,34 @@
+<template>
+ <div class="flex flex-row flex-wrap items-center break-all">
+ <span v-if="hasForeignKey" @click="$emit('click')">
+ {{ referencedForeignKeyName }}
+ </span>
+ <span v-else class="italic text-control-placeholder">EMPTY</span>
+
+ <MiniActionButton
+ v-if="!readonly"
+ :disabled="disabled"
+ @click="$emit('edit')"
+ >
+ <PenSquareIcon class="w-4 h-4" />
+ </MiniActionButton>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { PenSquareIcon } from "lucide-vue-next";
+import { MiniActionButton } from "@/components/v2";
+import { Column } from "@/types/v1/schemaEditor";
+
+defineProps<{
+ column: Column;
+ readonly?: boolean;
+ disabled: boolean;
+ hasForeignKey: boolean;
+ referencedForeignKeyName: string;
+}>();
+defineEmits<{
+ (event: "click"): void;
+ (event: "edit"): void;
+}>();
+</script>
diff --git a/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/components/LabelsCell.vue b/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/components/LabelsCell.vue
new file mode 100644
index 0000000000..f9307a07eb
--- /dev/null
+++ b/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/components/LabelsCell.vue
@@ -0,0 +1,24 @@
+<template>
+ <div class="flex justify-start items-center">
+ <LabelsColumn :labels="column.config.labels" :show-count="1" />
+ <MiniActionButton v-if="!readonly && !disabled" @click="$emit('edit')">
+ <PencilIcon class="w-3 h-3" />
+ </MiniActionButton>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { PencilIcon } from "lucide-vue-next";
+import { MiniActionButton } from "@/components/v2";
+import LabelsColumn from "@/components/v2/Model/DatabaseV1Table/LabelsColumn.vue";
+import { Column } from "@/types/v1/schemaEditor";
+
+defineProps<{
+ column: Column;
+ readonly?: boolean;
+ disabled?: boolean;
+}>();
+defineEmits<{
+ (event: "edit"): void;
+}>();
+</script>
diff --git a/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/components/OperationCell.vue b/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/components/OperationCell.vue
new file mode 100644
index 0000000000..656cd4e8c9
--- /dev/null
+++ b/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/components/OperationCell.vue
@@ -0,0 +1,41 @@
+<template>
+ <div class="flex justify-start items-center">
+ <NTooltip v-if="!readonly" trigger="hover" to="body">
+ <template #trigger>
+ <MiniActionButton tag="div" :disabled="disabled" @click="$emit('drop')">
+ <TrashIcon class="w-4 h-4" />
+ </MiniActionButton>
+ </template>
+ <span>{{ $t("schema-editor.actions.drop-table") }}</span>
+ </NTooltip>
+ <NTooltip v-else trigger="hover" to="body">
+ <template #trigger>
+ <MiniActionButton
+ tag="div"
+ :disabled="disabled"
+ @click="$emit('restore')"
+ >
+ <Undo2Icon class="w-4 h-4" />
+ </MiniActionButton>
+ </template>
+ <span>{{ $t("schema-editor.actions.restore") }}</span>
+ </NTooltip>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { TrashIcon } from "lucide-vue-next";
+import { Undo2Icon } from "lucide-vue-next";
+import { MiniActionButton } from "@/components/v2";
+import { Column } from "@/types/v1/schemaEditor";
+
+defineProps<{
+ column: Column;
+ readonly?: boolean;
+ disabled?: boolean;
+}>();
+defineEmits<{
+ (event: "drop"): void;
+ (event: "restore"): void;
+}>();
+</script>
diff --git a/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/components/SemanticTypeCell.vue b/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/components/SemanticTypeCell.vue
new file mode 100644
index 0000000000..a8a9432efc
--- /dev/null
+++ b/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/components/SemanticTypeCell.vue
@@ -0,0 +1,50 @@
+<template>
+ <div class="flex flex-row flex-wrap whitespace-nowrap">
+ {{ semanticType?.title }}
+ <template v-if="!readonly && !disabled">
+ <MiniActionButton
+ v-if="semanticType"
+ :disabled="disableAlterColumn(column)"
+ @click.prevent="$emit('remove')"
+ >
+ <XIcon class="w-3 h-3" />
+ </MiniActionButton>
+ <MiniActionButton
+ :disabled="disableAlterColumn(column)"
+ @click.prevent="$emit('edit')"
+ >
+ <PencilIcon class="w-3 h-3" />
+ </MiniActionButton>
+ </template>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { PencilIcon, XIcon } from "lucide-vue-next";
+import { computed } from "vue";
+import { MiniActionButton } from "@/components/v2";
+import { SemanticTypeSetting_SemanticType as SemanticType } from "@/types/proto/v1/setting_service";
+import { Column } from "@/types/v1/schemaEditor";
+
+const props = defineProps<{
+ column: Column;
+ readonly?: boolean;
+ disabled?: boolean;
+ semanticTypeList: SemanticType[];
+ disableAlterColumn: (column: Column) => boolean;
+}>();
+defineEmits<{
+ (event: "edit"): void;
+ (event: "remove"): void;
+}>();
+
+const semanticType = computed(() => {
+ const { column, semanticTypeList } = props;
+ if (!column.config.semanticTypeId) {
+ return;
+ }
+ return semanticTypeList.find(
+ (data) => data.id === column.config.semanticTypeId
+ );
+});
+</script>
diff --git a/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/components/index.ts b/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/components/index.ts
new file mode 100644
index 0000000000..9ba9cc56bd
--- /dev/null
+++ b/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/components/index.ts
@@ -0,0 +1,15 @@
+import ClassificationCell from "./ClassificationCell.vue";
+import DataTypeCell from "./DataTypeCell.vue";
+import DefaultValueCell from "./DefaultValueCell.vue";
+import ForeignKeyCell from "./ForeignKeyCell.vue";
+import OperationCell from "./OperationCell.vue";
+import SemanticTypeCell from "./SemanticTypeCell.vue";
+
+export {
+ ClassificationCell,
+ DataTypeCell,
+ DefaultValueCell,
+ ForeignKeyCell,
+ OperationCell,
+ SemanticTypeCell,
+};
diff --git a/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/index.ts b/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/index.ts
new file mode 100644
index 0000000000..17ba45a252
--- /dev/null
+++ b/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/index.ts
@@ -0,0 +1,3 @@
+import TableColumnEditor from "./TableColumnEditor.vue";
+
+export default TableColumnEditor;
diff --git a/frontend/src/components/SchemaEditorV1/Panels/TableEditor.vue b/frontend/src/components/SchemaEditorV1/Panels/TableEditor.vue
index ac4bf782f6..17d2247478 100644
--- a/frontend/src/components/SchemaEditorV1/Panels/TableEditor.vue
+++ b/frontend/src/components/SchemaEditorV1/Panels/TableEditor.vue
@@ -1,11 +1,11 @@
<template>
- <div class="flex flex-col w-full h-full overflow-y-auto">
- <div class="py-2 w-full flex flex-row justify-between items-center">
+ <div class="flex flex-col pt-2 gap-y-2 w-full h-full overflow-y-hidden">
+ <div
+ v-if="!readonly"
+ class="w-full flex flex-row justify-between items-center"
+ >
<div>
- <div
- v-if="!readonly"
- class="w-full flex justify-between items-center space-x-2"
- >
+ <div class="w-full flex justify-between items-center space-x-2">
<NButton
size="small"
:disabled="disableChangeTable"
@@ -27,24 +27,26 @@
</div>
</div>
- <TableColumnEditor
- :readonly="readonly"
- :show-foreign-key="true"
- :table="table"
- :engine="engine"
- :foreign-key-list="foreignKeyList"
- :classification-config-id="project.dataClassificationConfigId"
- :disable-change-table="disableChangeTable"
- :filter-column="(column: Column) => column.name.includes(props.searchPattern.trim())"
- :disable-alter-column="disableAlterColumn"
- :get-referenced-foreign-key-name="getReferencedForeignKeyName"
- :get-column-item-computed-class-list="getColumnItemComputedClassList"
- @on-drop="handleDropColumn"
- @on-restore="handleRestoreColumn"
- @on-primary-key-set="setColumnPrimaryKey"
- @on-foreign-key-edit="handleEditColumnForeignKey"
- @on-foreign-key-click="gotoForeignKeyReferencedTable"
- />
+ <div class="flex-1 overflow-y-hidden">
+ <TableColumnEditor
+ :readonly="readonly"
+ :show-foreign-key="true"
+ :table="table"
+ :engine="engine"
+ :foreign-key-list="foreignKeyList"
+ :classification-config-id="project.dataClassificationConfigId"
+ :disable-change-table="disableChangeTable"
+ :filter-column="(column: Column) => column.name.includes(props.searchPattern.trim())"
+ :disable-alter-column="disableAlterColumn"
+ :get-referenced-foreign-key-name="getReferencedForeignKeyName"
+ :get-column-item-computed-class-list="getColumnItemComputedClassList"
+ @drop="handleDropColumn"
+ @restore="handleRestoreColumn"
+ @primary-key-set="setColumnPrimaryKey"
+ @foreign-key-edit="handleEditColumnForeignKey"
+ @foreign-key-click="gotoForeignKeyReferencedTable"
+ />
+ </div>
</div>
<EditColumnForeignKeyModal
@@ -104,7 +106,7 @@ import { TableTabContext } from "@/types/v1/schemaEditor";
import FieldTemplates from "@/views/SchemaTemplate/FieldTemplates.vue";
import EditColumnForeignKeyModal from "../Modals/EditColumnForeignKeyModal.vue";
import { isColumnChanged } from "../utils";
-import TableColumnEditor from "./TableColumnEditor.vue";
+import TableColumnEditor from "./TableColumnEditor";
const props = withDefaults(
defineProps<{
@@ -171,11 +173,11 @@ const isDroppedTable = computed(() => {
return table.value.status === "dropped";
});
-const getColumnItemComputedClassList = (column: Column) => {
+const getColumnItemComputedClassList = (column: Column): string => {
if (column.status === "dropped") {
- return ["text-red-700", "cursor-not-allowed", "!bg-red-50", "opacity-70"];
+ return "dropped";
} else if (column.status === "created") {
- return ["text-green-700", "!bg-green-50"];
+ return "created";
} else if (
isColumnChanged(
currentTab.value.parentName,
@@ -184,9 +186,9 @@ const getColumnItemComputedClassList = (column: Column) => {
column.id
)
) {
- return ["text-yellow-700", "!bg-yellow-50"];
+ return "updated";
}
- return [];
+ return "";
};
const checkColumnHasForeignKey = (column: Column): boolean => {
diff --git a/frontend/src/components/SchemaEditorV1/Panels/TableList/TableList.vue b/frontend/src/components/SchemaEditorV1/Panels/TableList/TableList.vue
new file mode 100644
index 0000000000..5811f02708
--- /dev/null
+++ b/frontend/src/components/SchemaEditorV1/Panels/TableList/TableList.vue
@@ -0,0 +1,351 @@
+<template>
+ <div
+ ref="containerElRef"
+ class="w-full h-full"
+ :data-height="containerHeight"
+ :data-table-header-height="tableHeaderHeight"
+ :data-table-body-height="tableBodyHeight"
+ >
+ <NDataTable
+ v-bind="$attrs"
+ size="small"
+ :row-key="(table: Table) => table.id"
+ :columns="columns"
+ :data="tableList"
+ :row-class-name="classesForRow"
+ :max-height="tableBodyHeight"
+ :virtual-scroll="true"
+ :striped="true"
+ :bordered="true"
+ :bottom-bordered="true"
+ class="schema-editor-table-list"
+ />
+ </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 { useElementSize } from "@vueuse/core";
+import { DataTableColumn, NDataTable } from "naive-ui";
+import { computed, h, reactive, ref } from "vue";
+import { useI18n } from "vue-i18n";
+import FeatureModal from "@/components/FeatureGuard/FeatureModal.vue";
+import SelectClassificationDrawer from "@/components/SchemaTemplate/SelectClassificationDrawer.vue";
+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";
+import { NameCell, ClassificationCell, OperationCell } from "./components";
+
+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 containerElRef = ref<HTMLElement>();
+const tableHeaderElRef = computed(
+ () =>
+ containerElRef.value?.querySelector("thead.n-data-table-thead") as
+ | HTMLElement
+ | undefined
+);
+const { height: containerHeight } = useElementSize(containerElRef);
+const { height: tableHeaderHeight } = useElementSize(tableHeaderElRef);
+const tableBodyHeight = computed(() => {
+ return containerHeight.value - tableHeaderHeight.value - 2;
+});
+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 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 columns = computed(() => {
+ const columns: (DataTableColumn<Table> & { hide?: boolean })[] = [
+ {
+ key: "name",
+ title: t("schema-editor.database.name"),
+ resizable: true,
+ width: 140,
+ className: "truncate",
+ render: (table) => {
+ return h(NameCell, {
+ table,
+ onClick: () => handleTableItemClick(table),
+ });
+ },
+ },
+ {
+ key: "classification",
+ title: t("schema-editor.column.classification"),
+ resizable: true,
+ width: 140,
+ hide: !classificationConfig.value,
+ render: (table) => {
+ return h(ClassificationCell, {
+ table,
+ readonly: readonly.value,
+ disabled: !disableChangeTable(table),
+ classificationConfig: classificationConfig.value,
+ onEdit: () => showClassificationDrawer(table),
+ onRemove: () => (table.classification = ""),
+ });
+ },
+ },
+ {
+ key: "rowCount",
+ title: t("schema-editor.database.row-count"),
+ resizable: true,
+ width: 120,
+ render: (table) => {
+ return table.rowCount.toString();
+ },
+ },
+ {
+ key: "dataSize",
+ title: t("schema-editor.database.data-size"),
+ resizable: true,
+ width: 120,
+ render: (table) => {
+ return bytesToString(table.dataSize.toNumber());
+ },
+ },
+ {
+ key: "engine",
+ title: t("schema-editor.database.engine"),
+ resizable: true,
+ width: 120,
+ render: (table) => {
+ return table.engine;
+ },
+ },
+ {
+ key: "collation",
+ title: t("schema-editor.database.collation"),
+ resizable: true,
+ width: 120,
+ ellipsis: true,
+ },
+ {
+ key: "comment",
+ title: t("schema-editor.database.comment"),
+ resizable: true,
+ width: 140,
+ ellipsis: true,
+ },
+ {
+ key: "operations",
+ title: "",
+ resizable: false,
+ width: 30,
+ hide: readonly.value,
+ className: "!px-0",
+ render: (table) => {
+ return h(OperationCell, {
+ table,
+ readonly: !isDroppedTable(table),
+ onDrop: () => handleDropTable(table),
+ onRestore: () => handleRestoreTable(table),
+ });
+ },
+ },
+ ];
+ return columns.filter((header) => !header.hide);
+});
+
+const classesForRow = (table: Table, index: number) => {
+ if (table.status === "dropped") {
+ return "dropped";
+ } else if (table.status === "created") {
+ return "created";
+ } else if (
+ isTableChanged(currentTab.value.parentName, props.schemaId, table.id)
+ ) {
+ return "updated";
+ }
+};
+
+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,
+ });
+ }
+};
+
+const disableChangeTable = (table: Table): boolean => {
+ return table.status === "dropped";
+};
+const isDroppedTable = (table: Table) => {
+ return table.status === "dropped";
+};
+</script>
+
+<style lang="postcss" scoped>
+.schema-editor-table-list
+ :deep(.n-data-table-th .n-data-table-resize-button::after) {
+ @apply bg-control-bg h-2/3;
+}
+.schema-editor-table-list :deep(.n-data-table-tr.created .n-data-table-td) {
+ @apply text-green-700 !bg-green-50;
+}
+.schema-editor-table-list :deep(.n-data-table-tr.dropped .n-data-table-td) {
+ @apply text-red-700 !bg-red-50 opacity-70;
+}
+
+.schema-editor-table-list :deep(.n-data-table-tr.updated .n-data-table-td) {
+ @apply text-yellow-700 !bg-yellow-50;
+}
+</style>
diff --git a/frontend/src/components/SchemaEditorV1/Panels/TableList/components/ClassificationCell.vue b/frontend/src/components/SchemaEditorV1/Panels/TableList/components/ClassificationCell.vue
new file mode 100644
index 0000000000..139e5188a9
--- /dev/null
+++ b/frontend/src/components/SchemaEditorV1/Panels/TableList/components/ClassificationCell.vue
@@ -0,0 +1,39 @@
+<template>
+ <div class="flex flex-row items-center">
+ <ClassificationLevelBadge
+ :classification="table.classification"
+ :classification-config="classificationConfig"
+ />
+ <template v-if="!readonly && !disabled">
+ <MiniActionButton
+ v-if="table.classification"
+ @click.prevent="$emit('remove')"
+ >
+ <XIcon class="w-3 h-3" />
+ </MiniActionButton>
+ <MiniActionButton
+ class="w-4 h-4 p-0.5 hover:bg-control-bg-hover rounded cursor-pointer"
+ @click.prevent="$emit('edit')"
+ >
+ <PencilIcon class="w-3 h-3" />
+ </MiniActionButton>
+ </template>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import ClassificationLevelBadge from "@/components/SchemaTemplate/ClassificationLevelBadge.vue";
+import { DataClassificationSetting_DataClassificationConfig as DataClassificationConfig } from "@/types/proto/v1/setting_service";
+import { Table } from "@/types/v1/schemaEditor";
+
+defineProps<{
+ table: Table;
+ readonly?: boolean;
+ disabled?: boolean;
+ classificationConfig: DataClassificationConfig;
+}>();
+defineEmits<{
+ (event: "edit"): void;
+ (event: "remove"): void;
+}>();
+</script>
diff --git a/frontend/src/components/SchemaEditorV1/Panels/TableList/components/NameCell.vue b/frontend/src/components/SchemaEditorV1/Panels/TableList/components/NameCell.vue
new file mode 100644
index 0000000000..7b7876fe52
--- /dev/null
+++ b/frontend/src/components/SchemaEditorV1/Panels/TableList/components/NameCell.vue
@@ -0,0 +1,19 @@
+<template>
+ <NEllipsis class="w-full cursor-pointer leading-6 hover:text-accent">
+ <span @click="$emit('click')">
+ {{ table.name }}
+ </span>
+ </NEllipsis>
+</template>
+
+<script lang="ts" setup>
+import { NEllipsis } from "naive-ui";
+import { Table } from "@/types/v1/schemaEditor";
+
+defineProps<{
+ table: Table;
+}>();
+defineEmits<{
+ (event: "click"): void;
+}>();
+</script>
diff --git a/frontend/src/components/SchemaEditorV1/Panels/TableList/components/OperationCell.vue b/frontend/src/components/SchemaEditorV1/Panels/TableList/components/OperationCell.vue
new file mode 100644
index 0000000000..6007776027
--- /dev/null
+++ b/frontend/src/components/SchemaEditorV1/Panels/TableList/components/OperationCell.vue
@@ -0,0 +1,34 @@
+<template>
+ <div class="flex justify-start items-center">
+ <NTooltip v-if="!readonly" trigger="hover" to="body">
+ <template #trigger>
+ <heroicons:trash
+ class="w-4 h-auto text-gray-500 cursor-pointer hover:opacity-80"
+ @click="$emit('drop')"
+ />
+ </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="$emit('restore')"
+ />
+ </template>
+ <span>{{ $t("schema-editor.actions.restore") }}</span>
+ </NTooltip>
+ </div>
+</template>
+<script lang="ts" setup>
+import { Table } from "@/types/v1/schemaEditor";
+
+defineProps<{
+ table: Table;
+ readonly?: boolean;
+}>();
+defineEmits<{
+ (event: "drop"): void;
+ (event: "restore"): void;
+}>();
+</script>
diff --git a/frontend/src/components/SchemaEditorV1/Panels/TableList/components/index.ts b/frontend/src/components/SchemaEditorV1/Panels/TableList/components/index.ts
new file mode 100644
index 0000000000..d93cfe3de4
--- /dev/null
+++ b/frontend/src/components/SchemaEditorV1/Panels/TableList/components/index.ts
@@ -0,0 +1,5 @@
+import ClassificationCell from "./ClassificationCell.vue";
+import NameCell from "./NameCell.vue";
+import OperationCell from "./OperationCell.vue";
+
+export { NameCell, ClassificationCell, OperationCell };
diff --git a/frontend/src/components/SchemaEditorV1/Panels/TableList/index.ts b/frontend/src/components/SchemaEditorV1/Panels/TableList/index.ts
new file mode 100644
index 0000000000..71642de4c4
--- /dev/null
+++ b/frontend/src/components/SchemaEditorV1/Panels/TableList/index.ts
@@ -0,0 +1,3 @@
+import TableList from "./TableList.vue";
+
+export default TableList;
diff --git a/frontend/src/components/SchemaEditorV1/utils/columnDefaultValue.ts b/frontend/src/components/SchemaEditorV1/utils/columnDefaultValue.ts
index d9462d3e6a..5debf934e5 100644
--- a/frontend/src/components/SchemaEditorV1/utils/columnDefaultValue.ts
+++ b/frontend/src/components/SchemaEditorV1/utils/columnDefaultValue.ts
@@ -1,3 +1,4 @@
+import { DropdownOption } from "naive-ui";
import { useI18n } from "vue-i18n";
import { Engine } from "@/types/proto/v1/common";
import { ColumnDefaultValue } from "@/types/v1/schemaEditor";
@@ -150,7 +151,7 @@ export const getColumnDefaultValuePlaceholder = (
export const getColumnDefaultValueOptions = (
engine: Engine,
columnType: string
-): DefaultValueOption[] => {
+): (DefaultValueOption & DropdownOption)[] => {
const { t } = useI18n();
return getColumnTypeDefaultValueOptions(engine, columnType).map((option) => {
return {
diff --git a/frontend/src/components/SchemaEditorV1/utils/metadata.ts b/frontend/src/components/SchemaEditorV1/utils/metadata.ts
index 2b3829783c..180e4f9ff8 100644
--- a/frontend/src/components/SchemaEditorV1/utils/metadata.ts
+++ b/frontend/src/components/SchemaEditorV1/utils/metadata.ts
@@ -19,7 +19,7 @@ import {
convertSchemaMetadataToSchema,
convertTableMetadataToTable,
} from "@/types/v1/schemaEditor";
-import { randomString } from "@/utils";
+import { keyBy, randomString } from "@/utils";
export const mergeSchemaEditToMetadata = (
schemaEdits: Schema[],
@@ -363,21 +363,30 @@ export const rebuildEditableSchemas = (
schemas: SchemaMetadata[],
schemaConfigList: SchemaConfig[]
): Schema[] => {
+ const tag = [
+ "rebuildEditableSchemas",
+ `[${originalSchemas.map((s) => s.tableList.length)}]`,
+ `[${schemas.map((s) => s.tables.length)}]`,
+ `[${schemaConfigList.map((sc) => sc.tableConfigs.length)}]`,
+ ].join("--");
+ console.log("go!", tag);
+ console.time(tag);
const editableSchemas = cloneDeep(originalSchemas);
- for (const editableSchema of editableSchemas) {
- const schema = schemas.find(
- (schema) => schema.name === editableSchema.name
- );
+ console.time("loop-1");
+ const schemaMetadataByName = keyBy(schemas, (s) => s.name);
+ const schemaConfigByName = keyBy(schemaConfigList, (sc) => sc.name);
+ for (let i = 0; i < editableSchemas.length; i++) {
+ const editableSchema = editableSchemas[i];
+ const schema = schemaMetadataByName.get(editableSchema.name);
if (!schema) {
editableSchema.status = "dropped";
continue;
}
const schemaConfig =
- schemaConfigList.find(
- (schemaConfig) => schemaConfig.name === editableSchema.name
- ) ?? SchemaConfig.fromPartial({});
+ schemaConfigByName.get(editableSchema.name) ??
+ SchemaConfig.fromPartial({});
for (const editableTable of editableSchema.tableList) {
const table = schema.tables.find(
@@ -480,7 +489,9 @@ export const rebuildEditableSchemas = (
}
}
}
+ console.timeEnd("loop-1");
+ console.time("loop-2");
for (const schema of schemas) {
const editableSchema = editableSchemas.find(
(item) => item.name === schema.name
@@ -496,7 +507,9 @@ export const rebuildEditableSchemas = (
editableSchemas.push(newSchema);
}
}
+ console.timeEnd("loop-2");
+ console.time("loop-3");
// Build foreign keys for schema and referenced schema.
for (const schema of schemas) {
const editableSchema = editableSchemas.find(
@@ -556,7 +569,9 @@ export const rebuildEditableSchemas = (
editableTable.foreignKeyList = foreignKeyList;
}
}
+ console.timeEnd("loop-3");
+ console.timeEnd(tag);
return editableSchemas;
};
diff --git a/frontend/src/components/v2/Button/MiniActionButton.vue b/frontend/src/components/v2/Button/MiniActionButton.vue
new file mode 100644
index 0000000000..ce0700edb2
--- /dev/null
+++ b/frontend/src/components/v2/Button/MiniActionButton.vue
@@ -0,0 +1,14 @@
+<template>
+ <NButton quaternary size="tiny" style="--n-padding: 4px">
+ <template #icon>
+ <slot />
+ </template>
+ <template #default>
+ <slot name="text" />
+ </template>
+ </NButton>
+</template>
+
+<script setup lang="ts">
+import { NButton } from "naive-ui";
+</script>
diff --git a/frontend/src/components/v2/Button/index.ts b/frontend/src/components/v2/Button/index.ts
index 61617576d8..ed7e331992 100644
--- a/frontend/src/components/v2/Button/index.ts
+++ b/frontend/src/components/v2/Button/index.ts
@@ -1,6 +1,7 @@
import ContextMenuButton from "./ContextMenuButton.vue";
import ErrorTipsButton from "./ErrorTipsButton.vue";
+import MiniActionButton from "./MiniActionButton.vue";
import TooltipButton from "./TooltipButton.vue";
-export { ContextMenuButton, TooltipButton, ErrorTipsButton };
+export { ContextMenuButton, TooltipButton, ErrorTipsButton, MiniActionButton };
export * from "./types";
diff --git a/frontend/src/components/v2/Form/DropdownInput.vue b/frontend/src/components/v2/Form/DropdownInput.vue
new file mode 100644
index 0000000000..b0a7fbd99c
--- /dev/null
+++ b/frontend/src/components/v2/Form/DropdownInput.vue
@@ -0,0 +1,88 @@
+<template>
+ <NDropdown
+ v-if="allowInputValue"
+ trigger="click"
+ placement="bottom-start"
+ :options="dropdownOptions"
+ :width="$attrs.consistentMenuWidth ? 'trigger' : undefined"
+ v-bind="dropdownProps"
+ @select="$emit('update:value', $event as string)"
+ >
+ <NInput
+ :value="value"
+ v-bind="$attrs"
+ @update:value="$emit('update:value', $event)"
+ >
+ <template #suffix>
+ <!-- use the same icon and style with NSelect -->
+ <NElement
+ tag="button"
+ style="color: var(--placeholder-color)"
+ class="absolute top-1/2 right-[9px] -translate-y-1/2 cursor-pointer"
+ :class="suffixClass"
+ :style="suffixStyle"
+ >
+ <svg
+ viewBox="0 0 16 16"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+ class="w-4 h-4"
+ >
+ <path
+ d="M3.14645 5.64645C3.34171 5.45118 3.65829 5.45118 3.85355 5.64645L8 9.79289L12.1464 5.64645C12.3417 5.45118 12.6583 5.45118 12.8536 5.64645C13.0488 5.84171 13.0488 6.15829 12.8536 6.35355L8.35355 10.8536C8.15829 11.0488 7.84171 11.0488 7.64645 10.8536L3.14645 6.35355C2.95118 6.15829 2.95118 5.84171 3.14645 5.64645Z"
+ fill="currentColor"
+ ></path>
+ </svg>
+ </NElement>
+ </template>
+ </NInput>
+ </NDropdown>
+ <NSelect
+ v-else
+ :value="value"
+ :options="options"
+ v-bind="$attrs"
+ @update:value="$emit('update:value', $event as string)"
+ />
+</template>
+
+<script setup lang="ts">
+import {
+ DropdownOption,
+ DropdownProps,
+ NDropdown,
+ NElement,
+ NInput,
+ NSelect,
+ SelectOption,
+} from "naive-ui";
+import { computed } from "vue";
+import { VueClass, VueStyle } from "@/utils";
+
+const props = withDefaults(
+ defineProps<{
+ value: string | undefined | null;
+ allowInputValue?: boolean;
+ options: SelectOption[];
+ dropdownProps?: DropdownProps;
+ suffixClass?: VueClass;
+ suffixStyle?: VueStyle;
+ }>(),
+ {
+ allowInputValue: true,
+ dropdownProps: undefined,
+ suffixClass: undefined,
+ suffixStyle: undefined,
+ }
+);
+defineEmits<{
+ (event: "update:value", value: string): void;
+}>();
+
+const dropdownOptions = computed(() => {
+ return props.options.map<DropdownOption>((opt) => ({
+ key: opt.value,
+ ...opt,
+ }));
+});
+</script>
diff --git a/frontend/src/components/v2/Form/InlineInput.vue b/frontend/src/components/v2/Form/InlineInput.vue
new file mode 100644
index 0000000000..d63afd9a06
--- /dev/null
+++ b/frontend/src/components/v2/Form/InlineInput.vue
@@ -0,0 +1,38 @@
+<template>
+ <NInput
+ :value="value"
+ :style="style"
+ @focus="focused = true"
+ @blur="focused = false"
+ @update:value="$emit('update:value', $event)"
+ />
+</template>
+
+<script setup lang="ts">
+import { NInput } from "naive-ui";
+import { CSSProperties, computed, ref } from "vue";
+
+defineProps<{
+ value: string | undefined | null;
+}>();
+defineEmits<{
+ (event: "update:value", value: string): void;
+}>();
+
+const focused = ref(false);
+
+const style = computed(() => {
+ const style: CSSProperties = {
+ cursor: "default",
+ "--n-color": "transparent",
+ "--n-color-disabled": "transparent",
+ };
+ const border = focused.value
+ ? "1px solid rgb(var(--color-control-border))"
+ : "none";
+ style["--n-border"] = border;
+ style["--n-border-disabled"] = border;
+
+ return style;
+});
+</script>
diff --git a/frontend/src/components/v2/Form/index.ts b/frontend/src/components/v2/Form/index.ts
index fe3e880ed8..d01e0221bd 100644
--- a/frontend/src/components/v2/Form/index.ts
+++ b/frontend/src/components/v2/Form/index.ts
@@ -1,6 +1,15 @@
+import DropdownInput from "./DropdownInput.vue";
+import InlineInput from "./InlineInput.vue";
import ResourceIdField from "./ResourceIdField.vue";
import SearchBox from "./SearchBox.vue";
import SpinnerButton from "./SpinnerButton.vue";
import SpinnerSwitch from "./SpinnerSwitch.vue";
-export { SpinnerSwitch, SpinnerButton, SearchBox, ResourceIdField };
+export {
+ DropdownInput,
+ InlineInput,
+ SpinnerSwitch,
+ SpinnerButton,
+ SearchBox,
+ ResourceIdField,
+};