Skip to content

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

chore(frontend): settings -> schema template using naive-ui (#9462)

Liu Ji8f95bded8021
diff --git a/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/TableColumnEditor.vue b/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/TableColumnEditor.vue
index fd69960408..84cea89860 100644
--- a/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/TableColumnEditor.vue
+++ b/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/TableColumnEditor.vue
@@ -107,6 +107,7 @@ const props = withDefaults(
classificationConfigId?: string;
disableChangeTable?: boolean;
allowReorderColumns?: boolean;
+ maxBodyHeight?: number;
filterColumn?: (column: Column) => boolean;
disableAlterColumn?: (column: Column) => boolean;
getReferencedForeignKeyName?: (column: Column) => string;
@@ -116,6 +117,7 @@ const props = withDefaults(
showForeignKey: true,
disableChangeTable: false,
allowReorderColumns: false,
+ maxBodyHeight: undefined,
foreignKeyList: () => [],
classificationConfigId: "",
filterColumn: (_: Column) => true,
@@ -150,7 +152,12 @@ const tableHeaderElRef = computed(
const { height: containerHeight } = useElementSize(containerElRef);
const { height: tableHeaderHeight } = useElementSize(tableHeaderElRef);
const tableBodyHeight = computed(() => {
- return containerHeight.value - tableHeaderHeight.value - 2;
+ const bodyHeight = containerHeight.value - tableHeaderHeight.value - 2;
+ const { maxBodyHeight = 0 } = props;
+ if (maxBodyHeight > 0) {
+ return Math.min(maxBodyHeight, bodyHeight);
+ }
+ return bodyHeight;
});
// Use this to avoid unnecessary initial rendering
const layoutReady = computed(() => tableHeaderHeight.value > 0);
diff --git a/frontend/src/components/SchemaTemplate/FieldTemplateForm.vue b/frontend/src/components/SchemaTemplate/FieldTemplateForm.vue
index 22d5bab2fe..49918fc02e 100644
--- a/frontend/src/components/SchemaTemplate/FieldTemplateForm.vue
+++ b/frontend/src/components/SchemaTemplate/FieldTemplateForm.vue
@@ -11,27 +11,13 @@
{{ $t("schema-template.form.category-desc") }}
</p>
<div class="relative flex flex-row justify-between items-center mt-1">
- <input
- v-model="state.category"
- required
- name="category"
- type="text"
+ <DropdownInput
+ v-model:value="state.category"
+ :options="categoryOptions"
:placeholder="$t('schema-template.form.unclassified')"
- class="textfield w-full"
:disabled="!allowEdit"
+ :consistent-menu-width="true"
/>
- <NDropdown
- trigger="click"
- :options="categoryOptions"
- :disabled="!allowEdit"
- @select="(category: string) => (state.category = category)"
- >
- <button class="absolute right-5">
- <heroicons-solid:chevron-up-down
- class="w-4 h-auto text-gray-400"
- />
- </button>
- </NDropdown>
</div>
</div>
@@ -40,34 +26,30 @@
{{ $t("database.engine") }}
</label>
<div class="grid grid-cols-4 gap-2">
- <template v-for="engine in engineList" :key="engine">
- <div
- class="flex relative justify-start p-2 border rounded"
- :class="[
- state.engine === engine && 'font-medium bg-control-bg-hover',
- allowEdit
- ? 'cursor-pointer hover:bg-control-bg-hover'
- : 'cursor-not-allowed',
- ]"
- @click.capture="changeEngine(engine)"
- >
- <div class="flex flex-row justify-start items-center">
- <input
- type="radio"
- class="btn mr-2"
- :checked="state.engine === engine"
- :disabled="!allowEdit"
- />
- <EngineIcon
- :engine="engine"
- custom-class="w-5 h-auto max-h-[20px] object-contain mr-1"
- />
- <p class="text-center text-sm">
- {{ engineNameV1(engine) }}
- </p>
- </div>
- </div>
- </template>
+ <NButton
+ v-for="engine in engineList"
+ :key="engine"
+ size="large"
+ ghost
+ class="column-template-engine-button"
+ :type="state.engine === engine ? 'primary' : 'default'"
+ @click="changeEngine(engine)"
+ >
+ <NRadio
+ :checked="state.engine === engine"
+ size="large"
+ class="btn mr-2 pointer-events-none"
+ />
+ <EngineIcon
+ :engine="engine"
+ class="w-5 h-auto max-h-[20px] object-contain mr-1 ml-0"
+ />
+ <RichEngineName
+ :engine="engine"
+ tag="p"
+ class="text-center text-sm !text-main"
+ />
+ </NButton>
</div>
</div>
</div>
@@ -79,13 +61,9 @@
{{ $t("schema-template.form.column-name") }}
<span class="text-red-600 mr-2">*</span>
</label>
- <input
- v-model="state.column!.name"
- required
- name="column-name"
- type="text"
+ <NInput
+ v-model:value="state.column!.name"
placeholder="column name"
- class="textfield mt-1 w-full"
:disabled="!allowEdit"
/>
</div>
@@ -94,22 +72,20 @@
<label for="semantic-types" class="textlabel">
{{ $t("settings.sensitive-data.semantic-types.self") }}
</label>
- <div class="flex items-center gap-x-2 mt-3">
+ <div class="flex items-center gap-x-2 mt-3 text-sm">
{{ columnSemanticType?.title }}
<div v-if="allowEdit" class="flex items-center">
- <button
+ <MiniActionButton
v-if="columnSemanticType"
- class="w-6 h-6 p-1 hover:bg-control-bg-hover rounded cursor-pointer disabled:cursor-not-allowed disabled:hover:bg-white disabled:text-gray-400"
@click.prevent="onSemanticTypeApply('')"
>
- <heroicons-outline:x class="w-4 h-4" />
- </button>
- <button
- class="w-6 h-6 p-1 hover:bg-control-bg-hover rounded cursor-pointer disabled:cursor-not-allowed disabled:hover:bg-white disabled:text-gray-400"
+ <XIcon class="w-4 h-4" />
+ </MiniActionButton>
+ <MiniActionButton
@click.prevent="state.showSemanticTypesDrawer = true"
>
- <heroicons-outline:pencil class="w-4 h-4" />
- </button>
+ <PencilIcon class="w-4 h-4" />
+ </MiniActionButton>
</div>
</div>
</div>
@@ -124,19 +100,17 @@
:classification-config="classificationConfig"
/>
<div v-if="allowEdit" class="flex items-center">
- <button
+ <MiniActionButton
v-if="state.column?.classification"
- class="w-6 h-6 p-1 hover:bg-control-bg-hover rounded cursor-pointer disabled:cursor-not-allowed disabled:hover:bg-white disabled:text-gray-400"
@click.prevent="state.column!.classification = ''"
>
- <heroicons-outline:x class="w-4 h-4" />
- </button>
- <button
- class="w-6 h-6 p-1 hover:bg-control-bg-hover rounded cursor-pointer disabled:cursor-not-allowed disabled:hover:bg-white disabled:text-gray-400"
+ <XIcon class="w-4 h-4" />
+ </MiniActionButton>
+ <MiniActionButton
@click.prevent="state.showClassificationDrawer = true"
>
- <heroicons-outline:pencil class="w-4 h-4" />
- </button>
+ <PencilIcon class="w-4 h-4" />
+ </MiniActionButton>
</div>
</div>
</div>
@@ -150,41 +124,20 @@
<div
class="relative flex flex-row justify-between items-center mt-1"
>
- <BBSelect
- v-if="schemaTemplateColumnTypes.length > 0"
- :selected-item="state.column!.type"
- :item-list="schemaTemplateColumnTypes"
- :show-prefix-item="false"
+ <DropdownInput
+ :value="state.column!.type || null"
+ :allow-input-value="
+ schemaTemplateColumnTypeOptions.length === 0
+ "
+ :options="
+ schemaTemplateColumnTypeOptions.length > 0
+ ? schemaTemplateColumnTypeOptions
+ : dataTypeOptions
+ "
+ :disabled="!allowEdit"
placeholder="column type"
- @select-item="(item: string) => state.column!.type = item"
- >
- <template #menuItem="{ item }">
- {{ item }}
- </template>
- </BBSelect>
- <template v-else>
- <input
- v-model="state.column!.type"
- required
- name="column-type"
- type="text"
- placeholder="column type"
- class="textfield w-full"
- :disabled="!allowEdit"
- />
- <NDropdown
- trigger="click"
- :options="dataTypeOptions"
- :disabled="!allowEdit"
- @select="(dataType: string) => (state.column!.type = dataType)"
- >
- <button class="absolute right-5">
- <heroicons-solid:chevron-up-down
- class="w-4 h-auto text-gray-400"
- />
- </button>
- </NDropdown>
- </template>
+ @update:value="state.column!.type = $event"
+ />
</div>
</div>
@@ -194,41 +147,28 @@
{{ $t("schema-template.form.default-value") }}
</label>
<div class="flex flex-row items-center relative">
- <input
- class="textfield mt-1 w-full"
- type="text"
- :value="getColumnDefaultDisplayString(state.column!)"
+ <DropdownInput
+ :value="getColumnDefaultDisplayString(state.column!)||null"
+ :options="defaultValueOptions"
:disabled="!allowEdit"
:placeholder="getColumnDefaultValuePlaceholder(state.column!)"
- @change="(e) => handleColumnDefaultInputChange(e)"
+ @update:value="handleColumnDefaultChange"
/>
- <NDropdown
- trigger="click"
- :disabled="!allowEdit"
- :options="getColumnDefaultValueOptions(state.engine, state.column!.type)"
- @select="(key: string) => handleColumnDefaultFieldChange(key)"
- >
- <button class="absolute right-5">
- <heroicons-solid:chevron-up-down
- class="w-4 h-auto text-gray-400"
- />
- </button>
- </NDropdown>
</div>
</div>
<!-- nullable -->
- <div class="sm:col-span-2 ml-0 sm:ml-3 flex flex-col">
+ <div class="sm:col-span-2 ml-0 sm:ml-3">
<label for="nullable" class="textlabel">
{{ $t("schema-template.form.nullable") }}
</label>
- <BBSwitch
- class="mt-4"
- :text="false"
- :value="state.column?.nullable"
- :disabled="!allowEdit"
- @toggle="(on: boolean) => state.column!.nullable = on"
- />
+ <div class="flex flex-row items-center h-[34px]">
+ <NSwitch
+ v-model:value="state.column!.nullable"
+ :text="false"
+ :disabled="!allowEdit"
+ />
+ </div>
</div>
<!-- comment -->
@@ -236,15 +176,16 @@
<label for="comment" class="textlabel">
{{ $t("schema-template.form.comment") }}
</label>
- <textarea
- v-model="state.column!.userComment"
- rows="3"
- class="textfield block w-full resize-none mt-1 text-sm text-control rounded-md whitespace-pre-wrap"
+ <NInput
+ v-model:value="state.column!.userComment"
+ type="textarea"
+ :autosize="{ minRows: 3, maxRows: 3 }"
:disabled="!allowEdit"
/>
</div>
</div>
</div>
+
<div class="space-y-1 pt-6">
<label for="category" class="textlabel">
{{ $t("common.labels") }}
@@ -267,9 +208,9 @@
</NButton>
<NButton
v-if="allowEdit"
- :disabled="sumbitDisabled"
+ :disabled="submitDisabled"
type="primary"
- @click.prevent="sumbit"
+ @click.prevent="submit"
>
{{ create ? $t("common.create") : $t("common.update") }}
</NButton>
@@ -303,16 +244,25 @@
<script lang="ts" setup>
import { isEqual, cloneDeep } from "lodash-es";
-import { NDropdown } from "naive-ui";
+import { XIcon, PencilIcon } from "lucide-vue-next";
+import { NButton, NInput, NRadio, NSwitch, SelectOption } from "naive-ui";
import { computed, reactive, watch } from "vue";
import { useI18n } from "vue-i18n";
+import { EngineIcon } from "@/components/Icon";
+import { LabelListEditor } from "@/components/Label";
import {
getColumnDefaultDisplayString,
getColumnDefaultValuePlaceholder,
getDefaultValueByKey,
getColumnDefaultValueOptions,
+ isTextOfColumnType,
} from "@/components/SchemaEditorV1/utils/columnDefaultValue";
-import { DrawerContent } from "@/components/v2";
+import {
+ DrawerContent,
+ DropdownInput,
+ MiniActionButton,
+ RichEngineName,
+} from "@/components/v2";
import { useSettingV1Store, useNotificationStore } from "@/store";
import { Engine } from "@/types/proto/v1/common";
import {
@@ -325,12 +275,13 @@ import {
} from "@/types/proto/v1/setting_service";
import {
getDataTypeSuggestionList,
- engineNameV1,
useWorkspacePermissionV1,
convertKVListToLabels,
convertLabelsToKVList,
} from "@/utils";
-import { engineList, caregoryList, classificationConfig } from "./utils";
+import ColumnDefaultValueExpressionModal from "../SchemaEditorV1/Modals/ColumnDefaultValueExpressionModal.vue";
+import SemanticTypesDrawer from "../SensitiveData/components/SemanticTypesDrawer.vue";
+import { engineList, categoryList, classificationConfig } from "./utils";
const props = defineProps<{
create: boolean;
@@ -412,18 +363,32 @@ const dirty = computed(() => {
});
const dataTypeOptions = computed(() => {
- return getDataTypeSuggestionList(state.engine).map((dataType) => {
- return {
- label: dataType,
- key: dataType,
- };
- });
+ return getDataTypeSuggestionList(state.engine).map<SelectOption>(
+ (dataType) => {
+ return {
+ label: dataType,
+ value: dataType,
+ };
+ }
+ );
});
const categoryOptions = computed(() => {
- return caregoryList.value.map((category) => ({
+ return categoryList.value.map<SelectOption>((category) => ({
label: category,
- key: category,
+ value: category,
+ }));
+});
+
+const defaultValueOptions = computed(() => {
+ if (!state.column) return [];
+ return getColumnDefaultValueOptions(
+ state.engine,
+ state.column.type
+ ).map<SelectOption>((opt) => ({
+ value: opt.key,
+ label: opt.label as string,
+ defaultValue: opt.value,
}));
});
@@ -440,6 +405,12 @@ const schemaTemplateColumnTypes = computed(() => {
}
return [];
});
+const schemaTemplateColumnTypeOptions = computed(() => {
+ return schemaTemplateColumnTypes.value.map<SelectOption>((type) => ({
+ label: type,
+ value: type,
+ }));
+});
const changeEngine = (engine: Engine) => {
if (allowEdit.value) {
@@ -447,7 +418,7 @@ const changeEngine = (engine: Engine) => {
}
};
-const sumbitDisabled = computed(() => {
+const submitDisabled = computed(() => {
if (!state.column?.name || !state.column?.type) {
return true;
}
@@ -457,7 +428,7 @@ const sumbitDisabled = computed(() => {
return false;
});
-const sumbit = async () => {
+const submit = async () => {
const template = SchemaTemplateSetting_FieldTemplate.fromPartial({
...state,
config: ColumnConfig.fromPartial({
@@ -508,22 +479,37 @@ const onClassificationSelect = (id: string) => {
state.column.classification = id;
};
-const handleColumnDefaultInputChange = (event: Event) => {
- const value = (event.target as HTMLInputElement).value;
- if (!state.column) {
+const handleColumnDefaultChange = (key: string) => {
+ const value = getDefaultValueByKey(key);
+ if (value) {
+ handleColumnDefaultSelect(key);
return;
}
- state.column.hasDefault = true;
- state.column.defaultNull = undefined;
- if (state.column.defaultString !== undefined) {
- state.column.defaultString = value;
+
+ handleColumnDefaultInput(key);
+};
+const handleColumnDefaultInput = (value: string) => {
+ const { column } = state;
+ if (!column) return;
+
+ 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(state.engine, column.type) ||
+ column.defaultString !== undefined
+ ) {
+ column.defaultString = value;
+ column.defaultExpression = undefined;
return;
}
- // By default, user input is treated as expression.
- state.column.defaultExpression = value;
+ // Otherwise we will treat user's input as expression.
+ column.defaultExpression = value;
};
+const handleColumnDefaultSelect = (key: string) => {
+ const { column } = state;
+ if (!column) return;
-const handleColumnDefaultFieldChange = (key: string) => {
if (key === "expression") {
state.showColumnDefaultValueExpressionModal = true;
return;
@@ -563,3 +549,9 @@ const onSemanticTypeApply = async (semanticTypeId: string) => {
});
};
</script>
+
+<style lang="postcss" scoped>
+.column-template-engine-button :deep(.n-button__content) {
+ @apply w-full justify-start;
+}
+</style>
diff --git a/frontend/src/components/SchemaTemplate/FieldTemplateTable.vue b/frontend/src/components/SchemaTemplate/FieldTemplateTable.vue
index 2561846af6..f4a20cd66e 100644
--- a/frontend/src/components/SchemaTemplate/FieldTemplateTable.vue
+++ b/frontend/src/components/SchemaTemplate/FieldTemplateTable.vue
@@ -33,22 +33,15 @@
<LabelsColumn :labels="item.config?.labels ?? {}" :show-count="2" />
</div>
<div class="bb-grid-cell flex items-center justify-start gap-x-2">
- <button
- class="w-5 h-5 p-0.5 hover:bg-gray-300 rounded cursor-pointer disabled:cursor-not-allowed disabled:hover:bg-white disabled:text-gray-400"
- @click.stop="$emit('view', item)"
- >
- <heroicons-outline:pencil class="w-4 h-4" />
- </button>
+ <MiniActionButton @click.stop="$emit('view', item)">
+ <PencilIcon class="w-4 h-4" />
+ </MiniActionButton>
<NPopconfirm v-if="!readonly" @positive-click="deleteTemplate(item.id)">
<template #trigger>
- <button
- class="w-5 h-5 p-0.5 hover:bg-gray-300 rounded cursor-pointer disabled:cursor-not-allowed disabled:hover:bg-white disabled:text-gray-400"
- @click.stop=""
- >
- <heroicons-outline:trash class="w-4 h-4" />
- </button>
+ <MiniActionButton tag="div" @click.stop>
+ <TrashIcon class="w-4 h-4" />
+ </MiniActionButton>
</template>
-
<div class="whitespace-nowrap">
{{ $t("common.delete") + ` '${item.column?.name}'?` }}
</div>
@@ -60,11 +53,14 @@
<script lang="ts" setup>
import { pullAt } from "lodash-es";
+import { PencilIcon } from "lucide-vue-next";
+import { TrashIcon } from "lucide-vue-next";
import { NPopconfirm } from "naive-ui";
import { computed } from "vue";
import { useI18n } from "vue-i18n";
import { BBGrid, BBGridColumn } from "@/bbkit";
import { getColumnDefaultValuePlaceholder } from "@/components/SchemaEditorV1/utils/columnDefaultValue";
+import { MiniActionButton } from "@/components/v2";
import { useSettingV1Store } from "@/store";
import { Engine } from "@/types/proto/v1/common";
import {
diff --git a/frontend/src/components/SchemaTemplate/FieldTemplateView.vue b/frontend/src/components/SchemaTemplate/FieldTemplateView.vue
index dd5bb47cc1..6cc6817997 100644
--- a/frontend/src/components/SchemaTemplate/FieldTemplateView.vue
+++ b/frontend/src/components/SchemaTemplate/FieldTemplateView.vue
@@ -3,40 +3,34 @@
<div
class="border-4 border-dashed border-gray-200 rounded-lg h-96 flex justify-center items-center"
>
- <div class="text-center flex flex-col justify-center items-center">
- <img src="../../assets/illustration/no-data.webp" class="w-52" />
- </div>
+ <NoData />
</div>
</div>
<div v-else class="flex">
<div
- class="hidden sm:flex w-1/6 max-w-xs flex-col space-y-3 border-r mr-5 pr-5"
+ class="hidden sm:flex w-1/5 max-w-xs flex-col space-y-3 border-r mr-5 pr-5"
>
<p class="text-lg">
{{ $t("schema-template.form.category") }}
</p>
<div class="space-y-2">
- <label
+ <NCheckbox
v-for="item in categoryList"
:key="item.id"
- class="flex items-center gap-x-1 text-sm text-gray-600"
+ :checked="state.selectedCategory.has(item.id)"
+ @update:checked="toggleCategoryCheck(item.id)"
>
- <input
- type="checkbox"
- :value="item"
- :checked="state.selectedCategory.has(item.id)"
- class="h-4 w-4 border-gray-300 rounded text-indigo-600 focus:ring-indigo-500"
- @input="toggleCategoryCheck(item.id)"
- />
- <span class="text-ellipsis whitespace-nowrap overflow-hidden">
- {{ item.text }}
- </span>
- <span
- class="items-center text-xs px-2 py-0.5 rounded-full bg-gray-200 text-gray-800"
- >
- {{ item.count }}
- </span>
- </label>
+ <div class="flex items-center gap-x-1 text-sm text-gray-600">
+ <span class="text-ellipsis whitespace-nowrap overflow-hidden">
+ {{ item.text }}
+ </span>
+ <span
+ class="items-center text-xs px-2 py-0.5 rounded-full bg-gray-200 text-gray-800"
+ >
+ {{ item.count }}
+ </span>
+ </div>
+ </NCheckbox>
</div>
</div>
<FieldTemplateTable
@@ -51,10 +45,13 @@
</template>
<script lang="ts" setup>
+import { NCheckbox } from "naive-ui";
import { reactive, computed } from "vue";
import { useI18n } from "vue-i18n";
import { Engine } from "@/types/proto/v1/common";
import { SchemaTemplateSetting_FieldTemplate } from "@/types/proto/v1/setting_service";
+import NoData from "../misc/NoData.vue";
+import FieldTemplateTable from "./FieldTemplateTable.vue";
interface LocalState {
selectedCategory: Set<string>;
diff --git a/frontend/src/components/SchemaTemplate/TableTemplateForm.vue b/frontend/src/components/SchemaTemplate/TableTemplateForm.vue
index a6520abd17..2dfa1b06b2 100644
--- a/frontend/src/components/SchemaTemplate/TableTemplateForm.vue
+++ b/frontend/src/components/SchemaTemplate/TableTemplateForm.vue
@@ -13,27 +13,13 @@
{{ $t("schema-template.form.category-desc") }}
</p>
<div class="relative flex flex-row justify-between items-center mt-1">
- <input
- v-model="state.category"
- required
- name="category"
- type="text"
+ <DropdownInput
+ v-model:value="state.category"
+ :options="categoryOptions"
:placeholder="$t('schema-template.form.unclassified')"
- class="textfield w-full"
:disabled="!allowEdit"
+ :consistent-menu-width="true"
/>
- <NDropdown
- trigger="click"
- :options="categoryOptions"
- :disabled="!allowEdit"
- @select="(category: string) => (state.category = category)"
- >
- <button class="absolute right-5">
- <heroicons-solid:chevron-up-down
- class="w-4 h-auto text-gray-400"
- />
- </button>
- </NDropdown>
</div>
</div>
@@ -42,34 +28,30 @@
{{ $t("database.engine") }}
</label>
<div class="grid grid-cols-4 gap-2">
- <template v-for="engine in engineList" :key="engine">
- <div
- class="flex relative justify-start p-2 border rounded"
- :class="[
- state.engine === engine && 'font-medium bg-control-bg-hover',
- allowEdit
- ? 'cursor-pointer hover:bg-control-bg-hover'
- : 'cursor-not-allowed',
- ]"
- @click.capture="changeEngine(engine)"
- >
- <div class="flex flex-row justify-start items-center">
- <input
- type="radio"
- class="btn mr-2"
- :checked="state.engine === engine"
- :disabled="!allowEdit"
- />
- <EngineIcon
- :engine="engine"
- custom-class="w-5 h-auto max-h-[20px] object-contain mr-1"
- />
- <p class="text-center text-sm">
- {{ engineNameV1(engine) }}
- </p>
- </div>
- </div>
- </template>
+ <NButton
+ v-for="engine in engineList"
+ :key="engine"
+ size="large"
+ ghost
+ class="table-template-engine-button"
+ :type="state.engine === engine ? 'primary' : 'default'"
+ @click="changeEngine(engine)"
+ >
+ <NRadio
+ :checked="state.engine === engine"
+ size="large"
+ class="btn mr-2 pointer-events-none"
+ />
+ <EngineIcon
+ :engine="engine"
+ class="w-5 h-auto max-h-[20px] object-contain mr-1 ml-0"
+ />
+ <RichEngineName
+ :engine="engine"
+ tag="p"
+ class="text-center text-sm !text-main"
+ />
+ </NButton>
</div>
</div>
@@ -83,19 +65,17 @@
:classification-config="classificationConfig"
/>
<div v-if="allowEdit" class="flex">
- <button
+ <MiniActionButton
v-if="state.table?.classification"
- class="w-6 h-6 p-1 hover:bg-control-bg-hover rounded cursor-pointer disabled:cursor-not-allowed disabled:hover:bg-white disabled:text-gray-400"
@click.prevent="state.table!.classification = ''"
>
- <heroicons-outline:x class="w-4 h-4" />
- </button>
- <button
- class="w-6 h-6 p-1 hover:bg-control-bg-hover rounded cursor-pointer disabled:cursor-not-allowed disabled:hover:bg-white disabled:text-gray-400"
+ <XIcon class="w-4 h-4" />
+ </MiniActionButton>
+ <MiniActionButton
@click.prevent="state.showClassificationDrawer = true"
>
- <heroicons-outline:pencil class="w-4 h-4" />
- </button>
+ <PencilIcon class="w-4 h-4" />
+ </MiniActionButton>
</div>
</div>
</div>
@@ -108,13 +88,9 @@
{{ $t("schema-template.form.table-name") }}
<span class="text-red-600 mr-2">*</span>
</label>
- <input
- v-model="state.table!.name"
- required
- name="table-name"
- type="text"
+ <NInput
+ v-model:value="state.table!.name"
placeholder="table name"
- class="textfield mt-1 w-full"
:disabled="!allowEdit"
/>
</div>
@@ -124,10 +100,10 @@
<label for="comment" class="textlabel">
{{ $t("schema-template.form.comment") }}
</label>
- <textarea
- v-model="state.table!.userComment"
- rows="3"
- class="textfield block w-full resize-none mt-1 text-sm text-control rounded-md whitespace-pre-wrap"
+ <NInput
+ v-model:value="state.table!.userComment"
+ type="textarea"
+ :autosize="{ minRows: 3, maxRows: 3 }"
:disabled="!allowEdit"
/>
</div>
@@ -138,7 +114,9 @@
class="w-full py-2 flex items-center space-x-2"
>
<NButton size="small" :disabled="false" @click="onColumnAdd">
- <heroicons-outline:plus class="w-4 h-auto mr-1 text-gray-400" />
+ <template #icon>
+ <PlusIcon class="w-4 h-4 text-control-placeholder" />
+ </template>
{{ $t("schema-editor.actions.add-column") }}
</NButton>
<NButton
@@ -146,8 +124,10 @@
:disabled="false"
@click="state.showFieldTemplateDrawer = true"
>
- <FeatureBadge feature="bb.feature.schema-template" />
- <heroicons-outline:plus class="w-4 h-auto mr-1 text-gray-400" />
+ <template #icon>
+ <FeatureBadge feature="bb.feature.schema-template" />
+ <PlusIcon class="w-4 h-4 text-control-placeholder" />
+ </template>
{{ $t("schema-editor.actions.add-from-template") }}
</NButton>
</div>
@@ -158,6 +138,7 @@
:engine="state.engine"
:classification-config-id="classificationConfig?.id"
:allow-reorder-columns="allowReorderColumns"
+ :max-body-height="640"
@drop="onColumnDrop"
@reorder="handleReorderColumn"
@primary-key-set="setColumnPrimaryKey"
@@ -212,10 +193,15 @@
<script lang="ts" setup>
import { isEqual, cloneDeep } from "lodash-es";
+import { PlusIcon, XIcon, PencilIcon } from "lucide-vue-next";
+import { NButton, NInput, NRadio, SelectOption } from "naive-ui";
import { computed, nextTick, reactive } from "vue";
import { useI18n } from "vue-i18n";
+import FeatureBadge from "@/components/FeatureGuard/FeatureBadge.vue";
+import { EngineIcon } from "@/components/Icon";
+import TableColumnEditor from "@/components/SchemaEditorV1/Panels/TableColumnEditor";
import { transformTableEditToMetadata } from "@/components/SchemaEditorV1/utils";
-import { Drawer, DrawerContent } from "@/components/v2";
+import { Drawer, DrawerContent, RichEngineName } from "@/components/v2";
import { useSettingV1Store, useNotificationStore } from "@/store";
import { Engine } from "@/types/proto/v1/common";
import { ColumnMetadata, TableConfig } from "@/types/proto/v1/database_service";
@@ -232,13 +218,11 @@ import {
} from "@/types/v1/schemaEditor";
import {
arraySwap,
- engineNameV1,
instanceV1AllowsReorderColumns,
useWorkspacePermissionV1,
} from "@/utils";
import FieldTemplates from "@/views/SchemaTemplate/FieldTemplates.vue";
-import TableColumnEditor from "../SchemaEditorV1/Panels/TableColumnEditor";
-import { engineList, caregoryList, classificationConfig } from "./utils";
+import { engineList, categoryList, classificationConfig } from "./utils";
const props = defineProps<{
create: boolean;
@@ -279,9 +263,9 @@ const allowEdit = computed(() => {
});
const categoryOptions = computed(() => {
- return caregoryList.value.map((category) => ({
+ return categoryList.value.map<SelectOption>((category) => ({
label: category,
- key: category,
+ value: category,
}));
});
@@ -433,3 +417,9 @@ const handleReorderColumn = (column: Column, index: number, delta: -1 | 1) => {
arraySwap(columnList, index, target);
};
</script>
+
+<style lang="postcss" scoped>
+.table-template-engine-button :deep(.n-button__content) {
+ @apply w-full justify-start;
+}
+</style>
diff --git a/frontend/src/components/SchemaTemplate/TableTemplateTable.vue b/frontend/src/components/SchemaTemplate/TableTemplateTable.vue
index ea643775ad..cbc7b663e7 100644
--- a/frontend/src/components/SchemaTemplate/TableTemplateTable.vue
+++ b/frontend/src/components/SchemaTemplate/TableTemplateTable.vue
@@ -24,22 +24,15 @@
{{ item.table?.userComment }}
</div>
<div class="bb-grid-cell flex items-center justify-start gap-x-2">
- <button
- class="w-5 h-5 p-0.5 hover:bg-gray-300 rounded cursor-pointer disabled:cursor-not-allowed disabled:hover:bg-white disabled:text-gray-400"
- @click.stop="$emit('view', item)"
- >
- <heroicons-outline:pencil class="w-4 h-4" />
- </button>
+ <MiniActionButton @click.stop="$emit('view', item)">
+ <PencilIcon class="w-4 h-4" />
+ </MiniActionButton>
<NPopconfirm v-if="!readonly" @positive-click="deleteTemplate(item.id)">
<template #trigger>
- <button
- class="w-5 h-5 p-0.5 hover:bg-gray-300 rounded cursor-pointer disabled:cursor-not-allowed disabled:hover:bg-white disabled:text-gray-400"
- @click.stop=""
- >
- <heroicons-outline:trash class="w-4 h-4" />
- </button>
+ <MiniActionButton tag="div" @click.stop>
+ <TrashIcon class="w-4 h-4" />
+ </MiniActionButton>
</template>
-
<div class="whitespace-nowrap">
{{ $t("common.delete") + ` '${item.table?.name}'?` }}
</div>
@@ -51,10 +44,12 @@
<script lang="ts" setup>
import { pullAt } from "lodash-es";
+import { PencilIcon, TrashIcon } from "lucide-vue-next";
import { NPopconfirm } from "naive-ui";
import { computed } from "vue";
import { useI18n } from "vue-i18n";
import { BBGrid, BBGridColumn } from "@/bbkit";
+import { MiniActionButton } from "@/components/v2";
import { useSettingV1Store } from "@/store";
import { Engine } from "@/types/proto/v1/common";
import {
@@ -81,28 +76,28 @@ const columnList = computed((): BBGridColumn[] => {
return [
{
title: t("schema-template.form.category"),
- width: "15rem",
+ width: "minmax(auto, 15rem)",
class: "capitalize",
},
{
title: t("schema-template.form.table-name"),
- width: "15rem",
+ width: "minmax(auto, 15rem)",
class: "capitalize",
},
{
title: t("schema-template.classification.self"),
- width: "auto",
+ width: "minmax(auto, 1fr)",
class: "capitalize",
hide: !classificationConfig.value,
},
{
title: t("schema-template.form.comment"),
- width: "auto",
+ width: "minmax(auto, 1fr)",
class: "capitalize",
},
{
title: t("common.operations"),
- width: "5rem",
+ width: "auto",
class: "capitalize",
},
].filter((col) => !col.hide);
diff --git a/frontend/src/components/SchemaTemplate/TableTemplateView.vue b/frontend/src/components/SchemaTemplate/TableTemplateView.vue
index 48fcbed52d..a860c0c47e 100644
--- a/frontend/src/components/SchemaTemplate/TableTemplateView.vue
+++ b/frontend/src/components/SchemaTemplate/TableTemplateView.vue
@@ -3,9 +3,7 @@
<div
class="border-4 border-dashed border-gray-200 rounded-lg h-96 flex justify-center items-center"
>
- <div class="text-center flex flex-col justify-center items-center">
- <img src="../../assets/illustration/no-data.webp" class="w-52" />
- </div>
+ <NoData />
</div>
</div>
<div v-else class="flex">
@@ -16,27 +14,23 @@
{{ $t("schema-template.form.category") }}
</p>
<div class="space-y-2">
- <label
+ <NCheckbox
v-for="item in categoryList"
:key="item.id"
- class="flex items-center gap-x-1 text-sm text-gray-600"
+ :checked="state.selectedCategory.has(item.id)"
+ @update:checked="toggleCategoryCheck(item.id)"
>
- <input
- type="checkbox"
- :value="item"
- :checked="state.selectedCategory.has(item.id)"
- class="h-4 w-4 border-gray-300 rounded text-indigo-600 focus:ring-indigo-500"
- @input="toggleCategoryCheck(item.id)"
- />
- <span class="text-ellipsis whitespace-nowrap overflow-hidden">
- {{ item.text }}
- </span>
- <span
- class="items-center text-xs px-2 py-0.5 rounded-full bg-gray-200 text-gray-800"
- >
- {{ item.count }}
- </span>
- </label>
+ <div class="flex items-center gap-x-1 text-sm text-gray-600">
+ <span class="text-ellipsis whitespace-nowrap overflow-hidden">
+ {{ item.text }}
+ </span>
+ <span
+ class="items-center text-xs px-2 py-0.5 rounded-full bg-gray-200 text-gray-800"
+ >
+ {{ item.count }}
+ </span>
+ </div>
+ </NCheckbox>
</div>
</div>
<TableTemplateTable
@@ -51,10 +45,13 @@
</template>
<script lang="ts" setup>
+import { NCheckbox } from "naive-ui";
import { reactive, computed } from "vue";
import { useI18n } from "vue-i18n";
+import NoData from "@/components/misc/NoData.vue";
import { Engine } from "@/types/proto/v1/common";
import { SchemaTemplateSetting_TableTemplate } from "@/types/proto/v1/setting_service";
+import TableTemplateTable from "./TableTemplateTable.vue";
interface LocalState {
selectedCategory: Set<string>;
diff --git a/frontend/src/components/SchemaTemplate/utils.ts b/frontend/src/components/SchemaTemplate/utils.ts
index 8ce24838ce..11c3897a0a 100644
--- a/frontend/src/components/SchemaTemplate/utils.ts
+++ b/frontend/src/components/SchemaTemplate/utils.ts
@@ -4,7 +4,7 @@ import { Engine } from "@/types/proto/v1/common";
export const engineList = [Engine.MYSQL, Engine.POSTGRES];
-export const caregoryList = computed(() => {
+export const categoryList = computed(() => {
const settingStore = useSettingV1Store();
const setting = settingStore.getSettingByName("bb.workspace.schema-template");
const fieldTemplateList =
diff --git a/frontend/src/components/misc/NoData.vue b/frontend/src/components/misc/NoData.vue
new file mode 100644
index 0000000000..be22fd7040
--- /dev/null
+++ b/frontend/src/components/misc/NoData.vue
@@ -0,0 +1,18 @@
+<template>
+ <div class="text-center flex flex-col justify-center items-center">
+ <img
+ src="@/assets/illustration/no-data.webp"
+ class="w-52"
+ v-bind="imgAttrs"
+ />
+ <slot name="default" />
+ </div>
+</template>
+
+<script setup lang="ts">
+import { HTMLAttributes } from "vue";
+
+defineProps<{
+ imgAttrs?: HTMLAttributes;
+}>();
+</script>
diff --git a/frontend/src/components/v2/Form/DropdownInput.vue b/frontend/src/components/v2/Form/DropdownInput.vue
index b0a7fbd99c..761343803e 100644
--- a/frontend/src/components/v2/Form/DropdownInput.vue
+++ b/frontend/src/components/v2/Form/DropdownInput.vue
@@ -4,7 +4,7 @@
trigger="click"
placement="bottom-start"
:options="dropdownOptions"
- :width="$attrs.consistentMenuWidth ? 'trigger' : undefined"
+ :width="consistentMenuWidth ? 'trigger' : undefined"
v-bind="dropdownProps"
@select="$emit('update:value', $event as string)"
>
@@ -41,6 +41,7 @@
v-else
:value="value"
:options="options"
+ :consistent-menu-width="consistentMenuWidth"
v-bind="$attrs"
@update:value="$emit('update:value', $event as string)"
/>
@@ -61,18 +62,21 @@ import { VueClass, VueStyle } from "@/utils";
const props = withDefaults(
defineProps<{
- value: string | undefined | null;
+ value?: string | undefined | null;
allowInputValue?: boolean;
options: SelectOption[];
dropdownProps?: DropdownProps;
suffixClass?: VueClass;
suffixStyle?: VueStyle;
+ consistentMenuWidth?: boolean;
}>(),
{
+ value: undefined,
allowInputValue: true,
dropdownProps: undefined,
suffixClass: undefined,
suffixStyle: undefined,
+ consistentMenuWidth: true,
}
);
defineEmits<{
diff --git a/frontend/src/views/SchemaTemplate/FieldTemplates.vue b/frontend/src/views/SchemaTemplate/FieldTemplates.vue
index b1647518ac..1156633bdc 100644
--- a/frontend/src/views/SchemaTemplate/FieldTemplates.vue
+++ b/frontend/src/views/SchemaTemplate/FieldTemplates.vue
@@ -12,33 +12,31 @@
</div>
</div>
</div>
- <div class="flex items-center gap-x-5 my-4 pb-5 border-b">
- <template v-if="showEngineFilter">
- <label
- v-for="item in engineList"
- :key="item"
- class="flex items-center gap-x-1 text-sm text-gray-600"
- >
- <input
- type="checkbox"
- :value="item"
+ <div class="flex items-center justify-between gap-x-2 my-4 pb-5 border-b">
+ <div class="flex flex-row items-center justify-start gap-x-4">
+ <template v-if="showEngineFilter">
+ <NCheckbox
+ v-for="item in engineList"
+ :key="item"
:checked="state.selectedEngine.has(item)"
- class="h-4 w-4 border-gray-300 rounded text-indigo-600 focus:ring-indigo-500"
- @input="toggleEngineCheck(item)"
- />
- <EngineIcon :engine="item" custom-class="ml-0 mr-1" />
- <span
- class="items-center text-xs px-2 py-0.5 rounded-full bg-gray-200 text-gray-800"
+ @update:checked="toggleEngineCheck(item)"
>
- {{ countTemplateByEngine(item) }}
- </span>
- </label>
- </template>
- <BBTableSearch
- ref="searchField"
- class="ml-auto w-72"
+ <div class="flex items-center gap-x-1 text-sm text-gray-600">
+ <EngineIcon :engine="item" class="ml-0 mr-1" />
+ <span
+ class="items-center text-xs px-2 py-0.5 rounded-full bg-gray-200 text-gray-800"
+ >
+ {{ countTemplateByEngine(item) }}
+ </span>
+ </div>
+ </NCheckbox>
+ </template>
+ </div>
+ <SearchBox
+ v-model:value="state.searchText"
+ :autofocus="true"
:placeholder="$t('schema-template.search-by-name-or-comment')"
- @change-text="(val: string) => state.searchText = val"
+ style="width: 18rem"
/>
</div>
<FieldTemplateView
@@ -60,11 +58,13 @@
</template>
<script lang="ts" setup>
-import { NButton } from "naive-ui";
+import { NButton, NCheckbox } from "naive-ui";
import { v1 as uuidv1 } from "uuid";
import { reactive, computed, onMounted } from "vue";
+import FieldTemplateForm from "@/components/SchemaTemplate/FieldTemplateForm.vue";
+import FieldTemplateView from "@/components/SchemaTemplate/FieldTemplateView.vue";
import { engineList } from "@/components/SchemaTemplate/utils";
-import { Drawer } from "@/components/v2";
+import { Drawer, SearchBox } from "@/components/v2";
import { useSettingV1Store } from "@/store";
import { Engine } from "@/types/proto/v1/common";
import {
diff --git a/frontend/src/views/SchemaTemplate/TableTemplates.vue b/frontend/src/views/SchemaTemplate/TableTemplates.vue
index 3513f9cc2d..b27f09f44a 100644
--- a/frontend/src/views/SchemaTemplate/TableTemplates.vue
+++ b/frontend/src/views/SchemaTemplate/TableTemplates.vue
@@ -16,33 +16,31 @@
</div>
</div>
</div>
- <div class="flex items-center gap-x-5 my-4 pb-5 border-b">
- <template v-if="showEngineFilter">
- <label
- v-for="item in engineList"
- :key="item"
- class="flex items-center gap-x-1 text-sm text-gray-600"
- >
- <input
- type="checkbox"
- :value="item"
+ <div class="flex items-center justify-between gap-x-2 my-4 pb-5 border-b">
+ <div class="flex flex-row items-center justify-start gap-x-4">
+ <template v-if="showEngineFilter">
+ <NCheckbox
+ v-for="item in engineList"
+ :key="item"
:checked="state.selectedEngine.has(item)"
- class="h-4 w-4 border-gray-300 rounded text-indigo-600 focus:ring-indigo-500"
- @input="toggleEngineCheck(item)"
- />
- <EngineIcon :engine="item" custom-class="ml-0 mr-1" />
- <span
- class="items-center text-xs px-2 py-0.5 rounded-full bg-gray-200 text-gray-800"
+ @update:checked="toggleEngineCheck(item)"
>
- {{ countTemplateByEngine(item) }}
- </span>
- </label>
- </template>
- <BBTableSearch
- ref="searchField"
- class="ml-auto w-72"
+ <div class="flex items-center gap-x-1 text-sm text-gray-600">
+ <EngineIcon :engine="item" class="ml-0 mr-1" />
+ <span
+ class="items-center text-xs px-2 py-0.5 rounded-full bg-gray-200 text-gray-800"
+ >
+ {{ countTemplateByEngine(item) }}
+ </span>
+ </div>
+ </NCheckbox>
+ </template>
+ </div>
+ <SearchBox
+ v-model:value="state.searchText"
+ :autofocus="true"
:placeholder="$t('schema-template.search-by-name-or-comment')"
- @change-text="(val: string) => state.searchText = val"
+ style="width: 18rem"
/>
</div>
<TableTemplateView
@@ -64,11 +62,13 @@
</template>
<script lang="ts" setup>
-import { NButton } from "naive-ui";
+import { NButton, NCheckbox } from "naive-ui";
import { v1 as uuidv1 } from "uuid";
import { reactive, computed, onMounted } from "vue";
+import TableTemplateForm from "@/components/SchemaTemplate/TableTemplateForm.vue";
+import TableTemplateView from "@/components/SchemaTemplate/TableTemplateView.vue";
import { engineList } from "@/components/SchemaTemplate/utils";
-import { Drawer } from "@/components/v2";
+import { Drawer, SearchBox } from "@/components/v2";
import { useSettingV1Store } from "@/store";
import { Engine } from "@/types/proto/v1/common";
import { TableMetadata, TableConfig } from "@/types/proto/v1/database_service";