Skip to content

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

feat: update layout of schema editor (#4636)

boojackcdc3f6c94434
diff --git a/frontend/src/components/SchemaDiagram/SchemaDiagramIcon.vue b/frontend/src/components/SchemaDiagram/SchemaDiagramIcon.vue
index c8b0293b02..bc3ad409b2 100644
--- a/frontend/src/components/SchemaDiagram/SchemaDiagramIcon.vue
+++ b/frontend/src/components/SchemaDiagram/SchemaDiagramIcon.vue
@@ -1,3 +1,7 @@
<template>
- <img src="../../assets/schema-diagram.svg" class="text-gray-400 w-4 h-4" />
+ <img
+ src="../../assets/schema-diagram.svg"
+ class="w-4 h-auto"
+ v-bind="$attrs"
+ />
</template>
diff --git a/frontend/src/components/SchemaEditor/DatabaseTree.vue b/frontend/src/components/SchemaEditor/DatabaseTree.vue
index da857d303e..977f1c4456 100644
--- a/frontend/src/components/SchemaEditor/DatabaseTree.vue
+++ b/frontend/src/components/SchemaEditor/DatabaseTree.vue
@@ -3,7 +3,7 @@
<div class="w-full sticky top-0 pt-2 h-12 bg-white z-10">
<NInput
v-model:value="searchPattern"
- :placeholder="$t('sql-editor.search-databases')"
+ :placeholder="$t('schema-editor.search-database-and-table')"
>
<template #prefix>
<heroicons-outline:search class="w-4 h-auto text-gray-300" />
diff --git a/frontend/src/components/SchemaEditor/Panels/DatabaseEditor.vue b/frontend/src/components/SchemaEditor/Panels/DatabaseEditor.vue
index eeff955767..a100b7499a 100644
--- a/frontend/src/components/SchemaEditor/Panels/DatabaseEditor.vue
+++ b/frontend/src/components/SchemaEditor/Panels/DatabaseEditor.vue
@@ -1,62 +1,86 @@
<template>
<div class="flex flex-col w-full h-full overflow-y-auto">
- <div
- class="pt-3 pl-1 w-full flex justify-start items-center border-b border-b-gray-300"
- >
- <span
- class="-mb-px px-3 leading-9 rounded-t-md text-sm text-gray-500 border border-b-0 border-transparent cursor-pointer select-none"
- :class="
- state.selectedSubtab === 'table-list' &&
- 'bg-white border-gray-300 text-gray-800'
- "
- @click="handleChangeTab('table-list')"
- >{{ $t("schema-editor.table-list") }}</span
- >
- <span
- class="-mb-px px-3 leading-9 rounded-t-md text-sm text-gray-500 border border-b-0 border-transparent cursor-pointer select-none"
- :class="
- state.selectedSubtab === 'raw-sql' &&
- 'bg-white border-gray-300 text-gray-800'
- "
- @click="handleChangeTab('raw-sql')"
- >{{ $t("schema-editor.raw-sql") }}</span
- >
- <span
- class="-mb-px px-3 leading-9 rounded-t-md text-sm text-gray-500 border border-b-0 border-transparent cursor-pointer select-none"
- :class="
- state.selectedSubtab === 'schema-diagram' &&
- 'bg-white border-gray-300 text-gray-800'
- "
- @click="handleChangeTab('schema-diagram')"
- >{{ $t("schema-diagram.self") }}</span
- >
- </div>
-
- <!-- List view -->
- <template v-if="state.selectedSubtab === 'table-list'">
- <div class="py-2 w-full flex justify-between items-center space-x-2">
- <div class="flex flex-row justify-start items-center">
- <div
- v-if="shouldShowSchemaSelector"
- class="ml-2 flex flex-row justify-start items-center mr-3 text-sm"
- >
- <span class="mr-1">Schema:</span>
- <n-select
- v-model:value="state.selectedSchemaId"
- class="min-w-[8rem]"
- :options="schemaSelectorOptionList"
- />
+ <div class="py-2 w-full flex flex-row justify-between items-center">
+ <div>
+ <div
+ v-if="state.selectedSubtab === 'table-list'"
+ class="w-full flex justify-between items-center space-x-2"
+ >
+ <div class="flex flex-row justify-start items-center">
+ <div
+ v-if="shouldShowSchemaSelector"
+ class="ml-2 flex flex-row justify-start items-center mr-3 text-sm"
+ >
+ <span class="mr-1">Schema:</span>
+ <n-select
+ v-model:value="state.selectedSchemaId"
+ class="min-w-[8rem]"
+ :options="schemaSelectorOptionList"
+ />
+ </div>
+ <button
+ class="flex flex-row justify-center items-center border px-3 py-1 leading-6 rounded text-sm hover:opacity-80 disabled:cursor-not-allowed disabled:opacity-60"
+ :disabled="!allowCreateTable"
+ @click="handleCreateNewTable"
+ >
+ <heroicons-outline:plus class="w-4 h-auto mr-1 text-gray-400" />
+ {{ $t("schema-editor.actions.create-table") }}
+ </button>
</div>
+ </div>
+ </div>
+ <div class="flex justify-end items-center">
+ <NInput
+ v-if="state.selectedSubtab === 'table-list'"
+ v-model:value="searchPattern"
+ class="!w-48 mr-3"
+ :placeholder="$t('schema-editor.search-table')"
+ >
+ <template #prefix>
+ <heroicons-outline:search class="w-4 h-auto text-gray-300" />
+ </template>
+ </NInput>
+ <div
+ class="flex flex-row justify-end items-center bg-gray-100 p-1 rounded"
+ >
<button
- class="flex flex-row justify-center items-center border px-3 py-1 leading-6 rounded text-sm hover:opacity-80 disabled:cursor-not-allowed disabled:opacity-60"
- :disabled="!allowCreateTable"
- @click="handleCreateNewTable"
+ class="px-2 leading-7 text-sm text-gray-500 cursor-pointer select-none rounded flex justify-center items-center"
+ :class="
+ state.selectedSubtab === 'table-list' &&
+ 'bg-gray-200 text-gray-800'
+ "
+ @click="handleChangeTab('table-list')"
+ >
+ <heroicons-outline:queue-list class="inline w-4 h-auto mr-1" />
+ {{ $t("schema-editor.tables") }}
+ </button>
+ <button
+ class="px-2 leading-7 text-sm text-gray-500 cursor-pointer select-none rounded flex justify-center items-center"
+ :class="
+ state.selectedSubtab === 'raw-sql' && 'bg-gray-200 text-gray-800'
+ "
+ @click="handleChangeTab('raw-sql')"
+ >
+ <heroicons-outline:clipboard class="inline w-4 h-auto mr-1" />
+ {{ $t("schema-editor.raw-sql") }}
+ </button>
+ <button
+ class="px-2 leading-7 text-sm text-gray-500 cursor-pointer select-none rounded flex justify-center items-center"
+ :class="
+ state.selectedSubtab === 'schema-diagram' &&
+ 'bg-gray-200 text-gray-800'
+ "
+ @click="handleChangeTab('schema-diagram')"
>
- <heroicons-outline:plus class="w-4 h-auto mr-1 text-gray-400" />
- {{ $t("schema-editor.actions.create-table") }}
+ <SchemaDiagramIcon class="mr-1" />
+ {{ $t("schema-diagram.self") }}
</button>
</div>
</div>
+ </div>
+
+ <!-- List view -->
+ <template v-if="state.selectedSubtab === 'table-list'">
<!-- table list -->
<div
class="w-full h-auto grid auto-rows-auto border-y relative overflow-y-auto"
@@ -76,7 +100,7 @@
<!-- table body -->
<div class="w-full">
<div
- v-for="(table, index) in tableList"
+ v-for="(table, index) in shownTableList"
:key="`${index}-${table.name}`"
class="grid grid-cols-[repeat(6,_minmax(0,_1fr))_32px] text-sm even:bg-gray-50"
:class="
@@ -181,7 +205,7 @@
import { head } from "lodash-es";
import { NEllipsis } from "naive-ui";
import scrollIntoView from "scroll-into-view-if-needed";
-import { computed, nextTick, reactive, watch } from "vue";
+import { computed, nextTick, reactive, ref, watch } from "vue";
import { useI18n } from "vue-i18n";
import {
generateUniqueTabId,
@@ -204,7 +228,7 @@ import {
} from "@/utils/schemaEditor/diffSchema";
import HighlightCodeBlock from "@/components/HighlightCodeBlock";
import TableNameModal from "../Modals/TableNameModal.vue";
-import SchemaDiagram from "@/components/SchemaDiagram";
+import { SchemaDiagram, SchemaDiagramIcon } from "@/components/SchemaDiagram";
import { useMetadataForDiagram } from "../utils/useMetadataForDiagram";
import {
ColumnMetadata,
@@ -229,6 +253,7 @@ interface LocalState {
const { t } = useI18n();
const editorStore = useSchemaEditorStore();
const notificationStore = useNotificationStore();
+const searchPattern = ref("");
const currentTab = computed(() => editorStore.currentTab as DatabaseTabContext);
const state = reactive<LocalState>({
selectedSubtab:
@@ -255,6 +280,11 @@ const selectedSchema = computed(() => {
const tableList = computed(() => {
return selectedSchema.value?.tableList ?? [];
});
+const shownTableList = computed(() => {
+ return tableList.value.filter((table) =>
+ table.name.includes(searchPattern.value.trim())
+ );
+});
const shouldShowSchemaSelector = computed(() => {
return databaseEngine === "POSTGRES";
diff --git a/frontend/src/components/SchemaEditor/Panels/TableEditor.vue b/frontend/src/components/SchemaEditor/Panels/TableEditor.vue
index de4e41d344..b69e26a394 100644
--- a/frontend/src/components/SchemaEditor/Panels/TableEditor.vue
+++ b/frontend/src/components/SchemaEditor/Panels/TableEditor.vue
@@ -1,31 +1,11 @@
<template>
<div class="flex flex-col w-full h-full overflow-y-auto">
- <div
- class="pt-3 pl-1 w-full flex justify-start items-center border-b border-b-gray-300"
- >
- <span
- class="-mb-px px-3 leading-9 rounded-t-md text-sm text-gray-500 border border-b-0 border-transparent cursor-pointer select-none"
- :class="
- state.selectedSubtab === 'column-list' &&
- 'bg-white border-gray-300 text-gray-800'
- "
- @click="handleChangeTab('column-list')"
- >{{ $t("schema-editor.column-list") }}</span
- >
- <span
- class="-mb-px px-3 leading-9 rounded-t-md text-sm text-gray-500 border border-b-0 border-transparent cursor-pointer select-none"
- :class="
- state.selectedSubtab === 'raw-sql' &&
- 'bg-white border-gray-300 text-gray-800'
- "
- @click="handleChangeTab('raw-sql')"
- >{{ $t("schema-editor.raw-sql") }}</span
- >
- </div>
-
- <template v-if="state.selectedSubtab === 'column-list'">
- <div class="w-full py-2 flex flex-row justify-between items-center">
- <div>
+ <div class="py-2 w-full flex flex-row justify-between items-center">
+ <div>
+ <div
+ v-if="state.selectedSubtab === 'column-list'"
+ class="w-full flex justify-between items-center space-x-2"
+ >
<button
class="flex flex-row justify-center items-center border px-3 py-1 leading-6 text-sm text-gray-700 rounded cursor-pointer hover:opacity-80 disabled:cursor-not-allowed disabled:opacity-60"
:disabled="disableChangeTable"
@@ -34,8 +14,6 @@
<heroicons-outline:plus class="w-4 h-auto mr-1 text-gray-400" />
{{ $t("schema-editor.actions.add-column") }}
</button>
- </div>
- <div class="w-auto flex flex-row justify-end items-center space-x-3">
<button
v-if="table.status !== 'created'"
class="flex flex-row justify-center items-center border px-3 py-1 leading-6 text-sm text-gray-700 rounded cursor-pointer hover:opacity-80 disabled:cursor-not-allowed disabled:opacity-60"
@@ -49,7 +27,46 @@
</button>
</div>
</div>
+ <div class="flex justify-end items-center">
+ <NInput
+ v-if="state.selectedSubtab === 'column-list'"
+ v-model:value="searchPattern"
+ class="!w-48 mr-3"
+ :placeholder="$t('schema-editor.search-column')"
+ >
+ <template #prefix>
+ <heroicons-outline:search class="w-4 h-auto text-gray-300" />
+ </template>
+ </NInput>
+ <div
+ class="flex flex-row justify-end items-center bg-gray-100 p-1 rounded"
+ >
+ <button
+ class="px-2 leading-7 text-sm text-gray-500 cursor-pointer select-none rounded flex justify-center items-center"
+ :class="
+ state.selectedSubtab === 'column-list' &&
+ 'bg-gray-200 text-gray-800'
+ "
+ @click="handleChangeTab('column-list')"
+ >
+ <heroicons-outline:queue-list class="inline w-4 h-auto mr-1" />
+ {{ $t("schema-editor.columns") }}
+ </button>
+ <button
+ class="px-2 leading-7 text-sm text-gray-500 cursor-pointer select-none rounded flex justify-center items-center"
+ :class="
+ state.selectedSubtab === 'raw-sql' && 'bg-gray-200 text-gray-800'
+ "
+ @click="handleChangeTab('raw-sql')"
+ >
+ <heroicons-outline:clipboard class="inline w-4 h-auto mr-1" />
+ {{ $t("schema-editor.raw-sql") }}
+ </button>
+ </div>
+ </div>
+ </div>
+ <template v-if="state.selectedSubtab === 'column-list'">
<!-- column table -->
<div
id="table-editor-container"
@@ -59,7 +76,7 @@
<!-- column table header -->
<div
class="sticky top-0 z-10 grid grid-cols-[repeat(4,_minmax(0,_1fr))_repeat(2,_96px)_minmax(0,_1fr)_32px] w-full text-sm leading-6 select-none bg-gray-50 text-gray-400"
- :class="table.columnList.length > 0 && 'border-b'"
+ :class="shownColumnList.length > 0 && 'border-b'"
>
<span
v-for="header in columnHeaderList"
@@ -72,7 +89,7 @@
<!-- column table body -->
<div class="w-full">
<div
- v-for="(column, index) in table.columnList"
+ v-for="(column, index) in shownColumnList"
:key="`${index}-${column.id}`"
class="grid grid-cols-[repeat(4,_minmax(0,_1fr))_repeat(2,_96px)_minmax(0,_1fr)_32px] gr text-sm even:bg-gray-50"
:class="[
@@ -317,9 +334,15 @@ const foreignKeyList = computed(() => {
) as ForeignKey[];
});
+const searchPattern = ref("");
const tableEditorContainerRef = ref<HTMLDivElement>();
const editForeignKeyColumn = ref<Column>();
+const shownColumnList = computed(() => {
+ return table.value.columnList.filter((column) =>
+ column.name.includes(searchPattern.value.trim())
+ );
+});
const isDroppedSchema = computed(() => {
return schema.value.status === "dropped";
});
diff --git a/frontend/src/components/SchemaEditor/TabsContainer.vue b/frontend/src/components/SchemaEditor/TabsContainer.vue
index f52ffb248c..8e6198941d 100644
--- a/frontend/src/components/SchemaEditor/TabsContainer.vue
+++ b/frontend/src/components/SchemaEditor/TabsContainer.vue
@@ -7,7 +7,7 @@
<div
v-for="tab in tabList"
:key="tab.id"
- class="tab-container px-1 pl-2 py-2 rounded w-40 flex flex-row justify-between items-center shrink-0 border border-transparent cursor-pointer"
+ class="relative px-1 pl-2 py-2 rounded w-40 flex flex-row justify-between items-center shrink-0 border border-transparent cursor-pointer"
:class="[
`tab-${tab.id}`,
tab.id === currentTab?.id && 'bg-white border-gray-200',
@@ -37,6 +37,10 @@
@click.stop.prevent="handleCloseTab(tab)"
/>
</span>
+ <div
+ v-if="tab.id === currentTab?.id"
+ class="absolute -bottom-px left-0 w-full h-[3px] bg-accent rounded"
+ ></div>
</div>
</div>
</div>
@@ -124,9 +128,3 @@ const handleCloseTab = (tab: TabContext) => {
editorStore.closeTab(tab.id);
};
</script>
-
-<style scoped>
-.tab-container:hover > .tab-close-button {
- @apply flex;
-}
-</style>
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index ad39207a59..7c40c76516 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1476,6 +1476,9 @@
"preview-issue": "Preview issue",
"sync-sql-from-schema-editor": "Sync SQL from Schema Editor",
"raw-sql": "Raw SQL",
+ "search-database-and-table": "Search database and table",
+ "search-table": "Search table",
+ "search-column": "Search column",
"actions": {
"create-schema": "Create schema",
"drop-schema": "Drop schema",
@@ -1501,12 +1504,12 @@
"select": "Select schema",
"name": "Schema Name"
},
- "table-list": "Table List",
+ "tables": "Tables",
"table": {
"select": "Select table",
"name": "Table Name"
},
- "column-list": "Column List",
+ "columns": "Columns",
"column": {
"select": "Select column",
"name": "Name",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index ca1d6f0fca..34ffe614ee 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1476,6 +1476,9 @@
"preview-issue": "预览工单",
"sync-sql-from-schema-editor": "从 Schema 编辑器中同步 SQL",
"raw-sql": "SQL 语句",
+ "search-database-and-table": "搜索数据库和表",
+ "search-table": "搜索表",
+ "search-column": "搜索列",
"actions": {
"create-schema": "新建 Schema",
"drop-schema": "删除 Schema",
@@ -1502,12 +1505,12 @@
"select": "选择 schema",
"name": "Schema 名称"
},
- "table-list": "表",
+ "tables": "表",
"table": {
"select": "选择表",
"name": "表名"
},
- "column-list": "列",
+ "columns": "列",
"column": {
"select": "选择列",
"name": "名称",