Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: support labels in field template (#8692)
ecmadaofd740668cce8
diff --git a/frontend/src/components/SchemaTemplate/FieldTemplateForm.vue b/frontend/src/components/SchemaTemplate/FieldTemplateForm.vueindex 5b3c91ed58..188a043c2e 100644--- a/frontend/src/components/SchemaTemplate/FieldTemplateForm.vue+++ b/frontend/src/components/SchemaTemplate/FieldTemplateForm.vue@@ -208,6 +208,18 @@</div></div></div>+ <div class="space-y-1 pt-6">+ <label for="category" class="textlabel">+ {{ $t("common.labels") }}+ </label>+ <LabelListEditor+ ref="labelListEditorRef"+ v-model:kv-list="state.kvList"+ :readonly="!!readonly"+ :show-errors="dirty"+ class="max-w-[30rem]"+ />+ </div></div><template #footer>@@ -240,10 +252,11 @@<script lang="ts" setup>import { isEqual, cloneDeep } from "lodash-es";-import { computed, reactive } from "vue";+import { computed, reactive, watch } from "vue";import { DrawerContent } from "@/components/v2";import { useSettingV1Store } from "@/store";import { Engine } from "@/types/proto/v1/common";+import { ColumnConfig } from "@/types/proto/v1/database_service";import {SchemaTemplateSetting,SchemaTemplateSetting_FieldTemplate,@@ -252,6 +265,8 @@ import {getDataTypeSuggestionList,engineNameV1,useWorkspacePermissionV1,+ convertKVListToLabels,+ convertLabelsToKVList,} from "@/utils";import {engineList,@@ -270,6 +285,7 @@ const emit = defineEmits(["dismiss"]);interface LocalState extends SchemaTemplateSetting_FieldTemplate {showClassificationDrawer: boolean;+ kvList: { key: string; value: string }[];}const state = reactive<LocalState>({@@ -278,6 +294,8 @@ const state = reactive<LocalState>({category: props.template.category,column: Object.assign({}, props.template.column),showClassificationDrawer: false,+ config: Object.assign({}, props.template.config),+ kvList: [],});const settingStore = useSettingV1Store();const allowEdit = computed(() => {@@ -287,6 +305,30 @@ const allowEdit = computed(() => {);});+const convert = () => {+ return convertLabelsToKVList(+ props.template.config?.labels ?? {},+ true /* sort */+ );+};++watch(+ () => props.template.config?.labels,+ () => {+ state.kvList = convert();+ },+ {+ immediate: true,+ deep: true,+ }+);++const dirty = computed(() => {+ const original = convert();+ const local = state.kvList;+ return !isEqual(original, local);+});+const dataTypeOptions = computed(() => {return getDataTypeSuggestionList(state.engine).map((dataType) => {return {@@ -334,7 +376,13 @@ const sumbitDisabled = computed(() => {});const sumbit = async () => {- const template = state;+ const template = SchemaTemplateSetting_FieldTemplate.fromJSON({+ ...state,+ config: ColumnConfig.fromJSON({+ ...(state.config ?? {}),+ labels: convertKVListToLabels(state.kvList, false /* !omitEmpty */),+ }),+ });const setting = await settingStore.fetchSettingByName("bb.workspace.schema-template");diff --git a/frontend/src/components/SchemaTemplate/FieldTemplateTable.vue b/frontend/src/components/SchemaTemplate/FieldTemplateTable.vueindex c287a030d9..d5a539b04f 100644--- a/frontend/src/components/SchemaTemplate/FieldTemplateTable.vue+++ b/frontend/src/components/SchemaTemplate/FieldTemplateTable.vue@@ -29,6 +29,9 @@<div class="bb-grid-cell">{{ item.column?.comment }}</div>+ <div class="bb-grid-cell">+ <LabelsColumn :labels="item.config?.labels ?? {}" :show-count="2" />+ </div><div class="bb-grid-cell flex items-center justify-start gap-x-2"><buttonclass="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"@@ -84,10 +87,10 @@ const { t } = useI18n();const settingStore = useSettingV1Store();const columnList = computed((): BBGridColumn[] => {- const list = [+ return [{title: t("schema-template.form.category"),- width: "15rem",+ width: "7rem",class: "capitalize",},{@@ -95,6 +98,12 @@ const columnList = computed((): BBGridColumn[] => {width: "auto",class: "capitalize",},+ {+ title: t("schema-template.classification.self"),+ width: "auto",+ class: "capitalize",+ hide: !classificationConfig.value,+ },{title: t("schema-template.form.column-type"),width: "auto",@@ -111,20 +120,16 @@ const columnList = computed((): BBGridColumn[] => {class: "capitalize",},{- title: t("common.operations"),- width: "5rem",+ title: t("common.labels"),+ width: "auto",class: "capitalize",},- ];- if (classificationConfig.value) {- list.splice(2, 0, {- title: t("schema-template.classification.self"),- width: "auto",+ {+ title: t("common.operations"),+ width: "6rem",class: "capitalize",- });- }-- return list;+ },+ ].filter((col) => !col.hide);});const clickRow = (template: SchemaTemplateSetting_FieldTemplate) => {diff --git a/frontend/src/components/SchemaTemplate/FieldTemplateView.vue b/frontend/src/components/SchemaTemplate/FieldTemplateView.vueindex 62ac0b9f5d..dd5bb47cc1 100644--- a/frontend/src/components/SchemaTemplate/FieldTemplateView.vue+++ b/frontend/src/components/SchemaTemplate/FieldTemplateView.vue@@ -10,7 +10,7 @@</div><div v-else class="flex"><div- class="hidden sm:flex w-1/5 max-w-xs flex-col space-y-3 border-r mr-5 pr-5"+ class="hidden sm:flex w-1/6 max-w-xs flex-col space-y-3 border-r mr-5 pr-5"><p class="text-lg">{{ $t("schema-template.form.category") }}diff --git a/frontend/src/components/SchemaTemplate/TableTemplateForm.vue b/frontend/src/components/SchemaTemplate/TableTemplateForm.vueindex 3dc9e09864..fc7d6101a3 100644--- a/frontend/src/components/SchemaTemplate/TableTemplateForm.vue+++ b/frontend/src/components/SchemaTemplate/TableTemplateForm.vue@@ -215,7 +215,7 @@ import { transformTableEditToMetadata } from "@/components/Branch/utils";import { Drawer, DrawerContent } from "@/components/v2";import { useSettingV1Store } from "@/store";import { Engine } from "@/types/proto/v1/common";-import { ColumnMetadata } from "@/types/proto/v1/database_service";+import { ColumnMetadata, TableConfig } from "@/types/proto/v1/database_service";import {SchemaTemplateSetting,SchemaTemplateSetting_FieldTemplate,@@ -299,6 +299,7 @@ const onSumbit = async () => {engine: state.engine,category: state.category,table: transformTableEditToMetadata(state.table),+ config: TableConfig.fromPartial({}),};const setting = await settingStore.fetchSettingByName("bb.workspace.schema-template"diff --git a/frontend/src/components/SchemaTemplate/TableTemplateTable.vue b/frontend/src/components/SchemaTemplate/TableTemplateTable.vueindex 80375790e1..f7ce9d829c 100644--- a/frontend/src/components/SchemaTemplate/TableTemplateTable.vue+++ b/frontend/src/components/SchemaTemplate/TableTemplateTable.vue@@ -78,7 +78,7 @@ const { t } = useI18n();const settingStore = useSettingV1Store();const columnList = computed((): BBGridColumn[] => {- const list = [+ return [{title: t("schema-template.form.category"),width: "15rem",@@ -89,6 +89,12 @@ const columnList = computed((): BBGridColumn[] => {width: "15rem",class: "capitalize",},+ {+ title: t("schema-template.classification.self"),+ width: "auto",+ class: "capitalize",+ hide: !classificationConfig.value,+ },{title: t("schema-template.form.comment"),width: "auto",@@ -99,15 +105,7 @@ const columnList = computed((): BBGridColumn[] => {width: "5rem",class: "capitalize",},- ];- if (classificationConfig.value) {- list.splice(2, 0, {- title: t("schema-template.classification.self"),- width: "auto",- class: "capitalize",- });- }- return list;+ ].filter((col) => !col.hide);});const clickRow = (template: SchemaTemplateSetting_TableTemplate) => {diff --git a/frontend/src/views/SchemaTemplate/FieldTemplates.vue b/frontend/src/views/SchemaTemplate/FieldTemplates.vueindex b7b35ae5ee..256f0d318b 100644--- a/frontend/src/views/SchemaTemplate/FieldTemplates.vue+++ b/frontend/src/views/SchemaTemplate/FieldTemplates.vue@@ -67,7 +67,10 @@ import { engineList } from "@/components/SchemaTemplate/utils";import { Drawer } from "@/components/v2";import { useSettingV1Store } from "@/store";import { Engine } from "@/types/proto/v1/common";-import { ColumnMetadata } from "@/types/proto/v1/database_service";+import {+ ColumnMetadata,+ ColumnConfig,+} from "@/types/proto/v1/database_service";import { SchemaTemplateSetting_FieldTemplate } from "@/types/proto/v1/setting_service";interface LocalState {@@ -100,6 +103,7 @@ const initialTemplate = () => ({characterSet: "",collation: "",}),+ config: ColumnConfig.fromPartial({}),});const state = reactive<LocalState>({diff --git a/frontend/src/views/SchemaTemplate/TableTemplates.vue b/frontend/src/views/SchemaTemplate/TableTemplates.vueindex f1e4971423..b44ac17e70 100644--- a/frontend/src/views/SchemaTemplate/TableTemplates.vue+++ b/frontend/src/views/SchemaTemplate/TableTemplates.vue@@ -71,7 +71,7 @@ import { engineList } from "@/components/SchemaTemplate/utils";import { Drawer } from "@/components/v2";import { useSettingV1Store } from "@/store";import { Engine } from "@/types/proto/v1/common";-import { TableMetadata } from "@/types/proto/v1/database_service";+import { TableMetadata, TableConfig } from "@/types/proto/v1/database_service";import { SchemaTemplateSetting_TableTemplate } from "@/types/proto/v1/setting_service";interface LocalState {@@ -100,6 +100,7 @@ const initialTemplate = (): SchemaTemplateSetting_TableTemplate => ({comment: "",columns: [],}),+ config: TableConfig.fromPartial({}),});const state = reactive<LocalState>({