Skip to content

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

chore: support set classification in template and designer (#7891)

ecmadao5252fbc78403
diff --git a/backend/api/v1/setting_service.go b/backend/api/v1/setting_service.go
index d70dd9c9e4..e5bf843514 100644
--- a/backend/api/v1/setting_service.go
+++ b/backend/api/v1/setting_service.go
@@ -952,11 +952,12 @@ func convertToSchemaTemplateSetting(s *storepb.SchemaTemplateSetting) *v1pb.Sche
Engine: v1pb.Engine(template.Engine),
Category: template.Category,
Column: &v1pb.ColumnMetadata{
- Name: template.Column.Name,
- Type: template.Column.Type,
- Default: template.Column.Default,
- Nullable: template.Column.Nullable,
- Comment: template.Column.Comment,
+ Name: template.Column.Name,
+ Type: template.Column.Type,
+ Default: template.Column.Default,
+ Nullable: template.Column.Nullable,
+ Comment: template.Column.Comment,
+ Classification: template.Column.Classification,
},
})
}
diff --git a/frontend/src/components/ColumnTable.vue b/frontend/src/components/ColumnTable.vue
index 835fe27278..2190ec7161 100644
--- a/frontend/src/components/ColumnTable.vue
+++ b/frontend/src/components/ColumnTable.vue
@@ -35,25 +35,23 @@
/>
</div>
</BBTableCell>
- <BBTableCell class="w-14" :left-padding="showSensitiveColumn ? 2 : 4">
+ <BBTableCell class="w-10" :left-padding="showSensitiveColumn ? 2 : 4">
{{ column.name }}
</BBTableCell>
- <BBTableCell v-if="showClassificationColumn" class="w-10">
+ <BBTableCell v-if="showClassificationColumn" class="w-14">
{{ getColumnClassification(column.classification)?.title }}
- <span
- v-if="getColumnSensitiveLevel(column.classification)?.sensitive"
- class="inline-flex items-center px-2 py-0.5 rounded-lg text-xs font-semibold bg-red-100 text-red-800"
- >
- {{ $t("database.sensitive") }}
- </span>
+ <ClassificationLevelBadge
+ :level-id="getColumnClassification(column.classification)?.levelId"
+ :classification-config="classificationConfig"
+ />
</BBTableCell>
- <BBTableCell class="w-8">
+ <BBTableCell class="w-5">
{{ column.type }}
</BBTableCell>
- <BBTableCell class="w-8">
+ <BBTableCell class="w-6">
{{ column.default }}
</BBTableCell>
- <BBTableCell class="w-8">
+ <BBTableCell class="w-4">
{{ column.nullable }}
</BBTableCell>
<BBTableCell
@@ -62,7 +60,7 @@
engine !== Engine.CLICKHOUSE &&
engine !== Engine.SNOWFLAKE
"
- class="w-8"
+ class="w-6"
>
{{ column.characterSet }}
</BBTableCell>
@@ -73,7 +71,7 @@
{{ column.collation }}
</BBTableCell>
<BBTableCell class="w-16">
- {{ column.comment }}
+ {{ column.userComment }}
</BBTableCell>
</template>
</BBTable>
@@ -355,14 +353,4 @@ const getColumnClassification = (classificationId: string) => {
}
return props.classificationConfig.classification[classificationId];
};
-
-const getColumnSensitiveLevel = (classificationId: string) => {
- const classification = getColumnClassification(classificationId);
- if (!classification) {
- return;
- }
- return (props.classificationConfig?.levels ?? []).find(
- (level) => level.id === classification.levelId
- );
-};
</script>
diff --git a/frontend/src/components/SchemaDesigner/CreateSchemaDesignPanel.vue b/frontend/src/components/SchemaDesigner/CreateSchemaDesignPanel.vue
index 5600ea335e..3b7ff69b41 100644
--- a/frontend/src/components/SchemaDesigner/CreateSchemaDesignPanel.vue
+++ b/frontend/src/components/SchemaDesigner/CreateSchemaDesignPanel.vue
@@ -54,6 +54,7 @@
:readonly="true"
:engine="state.schemaDesign.engine"
:schema-design="state.schemaDesign"
+ :project="project"
/>
</div>
@@ -216,6 +217,11 @@ const cancel = () => {
emit("dismiss");
};
+const project = computed(() => {
+ const { project } = useProjectV1ByUID(state.projectId || "");
+ return project.value;
+});
+
const handleConfirm = async () => {
if (!state.schemaDesign) {
return;
@@ -235,7 +241,6 @@ const handleConfirm = async () => {
return;
}
- const { project } = useProjectV1ByUID(state.projectId || "");
const database = useDatabaseV1Store().getDatabaseByUID(
state.baselineSchema.databaseId || ""
);
diff --git a/frontend/src/components/SchemaDesigner/EditSchemaDesignPanel.vue b/frontend/src/components/SchemaDesigner/EditSchemaDesignPanel.vue
index d2e2ed526a..2f7a8173c4 100644
--- a/frontend/src/components/SchemaDesigner/EditSchemaDesignPanel.vue
+++ b/frontend/src/components/SchemaDesigner/EditSchemaDesignPanel.vue
@@ -151,6 +151,7 @@
:readonly="!state.isEditing"
:engine="schemaDesign.engine"
:schema-design="schemaDesign"
+ :project="project"
/>
<!-- Don't show delete button in view mode. -->
<div v-if="!viewMode">
diff --git a/frontend/src/components/SchemaDesigner/Panels/TableEditor.vue b/frontend/src/components/SchemaDesigner/Panels/TableEditor.vue
index 251e44d2ca..239c0d1d4a 100644
--- a/frontend/src/components/SchemaDesigner/Panels/TableEditor.vue
+++ b/frontend/src/components/SchemaDesigner/Panels/TableEditor.vue
@@ -46,7 +46,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="sticky top-0 z-10 grid grid-cols-[6rem_minmax(0,_1.5fr)_repeat(3,_minmax(0,_0.8fr))_repeat(2,_80px)_minmax(0,_7rem)_20px] w-full text-sm leading-6 select-none bg-gray-50 text-gray-400"
:class="shownColumnList.length > 0 && 'border-b'"
>
<span
@@ -62,7 +62,7 @@
<div
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="grid grid-cols-[6rem_minmax(0,_1.5fr)_repeat(3,_minmax(0,_0.8fr))_repeat(2,_80px)_minmax(0,_7rem)_20px] gr text-sm even:bg-gray-50"
:class="[
`column-${column.id}`,
getColumnItemComputedClassList(column),
@@ -77,6 +77,32 @@
type="text"
/>
</div>
+ <div
+ class="table-body-item-container flex items-center gap-x-2 ml-3 text-sm"
+ >
+ {{ getColumnClassification(column)?.title ?? "N/A" }}
+ <ClassificationLevelBadge
+ :level-id="getColumnClassification(column)?.levelId"
+ :classification-config="classificationConfig"
+ />
+ <div
+ v-if="classificationConfig && !disableChangeTable"
+ class="flex"
+ >
+ <button
+ class="w-4 h-4 p-0.5 hover:bg-control-bg-hover rounded cursor-pointer"
+ @click.prevent="column.classification = ''"
+ >
+ <heroicons-outline:x class="w-3 h-3" />
+ </button>
+ <button
+ class="w-4 h-4 p-0.5 hover:bg-control-bg-hover rounded cursor-pointer"
+ @click.prevent="state.pendingUpdateColumnIndex = index"
+ >
+ <heroicons-outline:pencil class="w-3 h-3" />
+ </button>
+ </div>
+ </div>
<div
class="table-body-item-container flex flex-row justify-between items-center"
>
@@ -235,6 +261,14 @@
:open="state.showFeatureModal"
@cancel="state.showFeatureModal = false"
/>
+
+ <SelectClassificationDrawer
+ v-if="classificationConfig"
+ :show="state.pendingUpdateColumnIndex >= 0"
+ :classification-config="classificationConfig"
+ @dismiss="state.pendingUpdateColumnIndex = -1"
+ @select="onClassificationSelect"
+ />
</template>
<script lang="ts" setup>
@@ -276,11 +310,13 @@ interface LocalState {
showEditColumnForeignKeyModal: boolean;
showSchemaTemplateDrawer: boolean;
showFeatureModal: boolean;
+ pendingUpdateColumnIndex: number;
}
const { t } = useI18n();
-const { readonly, engine, editableSchemas, getCurrentTab, addTab } =
+const { readonly, engine, project, editableSchemas, getCurrentTab, addTab } =
useSchemaDesignerContext();
+useSchemaDesignerContext();
const settingStore = useSettingV1Store();
const currentTab = computed(() => getCurrentTab() as TableTabContext);
const state = reactive<LocalState>({
@@ -289,6 +325,7 @@ const state = reactive<LocalState>({
showEditColumnForeignKeyModal: false,
showSchemaTemplateDrawer: false,
showFeatureModal: false,
+ pendingUpdateColumnIndex: -1,
});
const schema = computed(() => {
@@ -331,6 +368,10 @@ const columnHeaderList = computed(() => {
key: "name",
label: t("schema-editor.column.name"),
},
+ {
+ key: "classification",
+ label: t("schema-editor.column.classification"),
+ },
{
key: "type",
label: t("schema-editor.column.type"),
@@ -515,16 +556,7 @@ const handleApplyColumnTemplate = (
if (template.engine !== engine.value || !template.column) {
return;
}
- const column = convertColumnMetadataToColumn(
- ColumnMetadata.fromPartial({
- name: template.column.name,
- type: template.column.type,
- nullable: template.column.nullable,
- comment: template.column.comment,
- userComment: template.column.userComment,
- default: template.column.default,
- })
- );
+ const column = convertColumnMetadataToColumn(template.column);
column.status = "created";
table.value.columnList.push(column);
state.showSchemaTemplateDrawer = false;
@@ -630,6 +662,35 @@ const handleRestoreColumn = (column: Column) => {
column.status = "normal";
};
+
+const classificationConfig = computed(() => {
+ if (!project.value || !project.value.dataClassificationConfigId) {
+ return;
+ }
+ return settingStore.getProjectClassification(
+ project.value.dataClassificationConfigId
+ );
+});
+
+const getColumnClassification = (column: Column) => {
+ if (!classificationConfig.value) {
+ return;
+ }
+ const { classification } = column;
+ if (!classification) {
+ return;
+ }
+ return classificationConfig.value.classification[classification];
+};
+
+const onClassificationSelect = (classificationId: string) => {
+ if (!table.value.columnList[state.pendingUpdateColumnIndex]) {
+ return;
+ }
+ table.value.columnList[state.pendingUpdateColumnIndex].classification =
+ classificationId;
+ state.pendingUpdateColumnIndex = -1;
+};
</script>
<style scoped>
diff --git a/frontend/src/components/SchemaDesigner/common/context.ts b/frontend/src/components/SchemaDesigner/common/context.ts
index 0f5a0d0b4f..ed01ada70f 100644
--- a/frontend/src/components/SchemaDesigner/common/context.ts
+++ b/frontend/src/components/SchemaDesigner/common/context.ts
@@ -24,6 +24,7 @@ export const provideSchemaDesignerContext = (
| "tabState"
| "originalSchemas"
| "editableSchemas"
+ | "project"
>
) => {
const { editableSchemas, tabState } = context;
diff --git a/frontend/src/components/SchemaDesigner/common/type.ts b/frontend/src/components/SchemaDesigner/common/type.ts
index 4d6d5240f8..b2d508327f 100644
--- a/frontend/src/components/SchemaDesigner/common/type.ts
+++ b/frontend/src/components/SchemaDesigner/common/type.ts
@@ -1,5 +1,5 @@
import { Ref } from "vue";
-import { Schema, Table } from "@/types";
+import { Schema, Table, ComposedProject } from "@/types";
import { Engine } from "@/types/proto/v1/common";
import { DatabaseMetadata } from "@/types/proto/v1/database_service";
@@ -31,6 +31,7 @@ export interface SchemaDesignerContext {
tabState: Ref<SchemaDesignerTabState>;
originalSchemas: Ref<Schema[]>;
editableSchemas: Ref<Schema[]>;
+ project: Ref<ComposedProject>;
// Tab related functions.
getCurrentTab: () => TabContext | undefined;
diff --git a/frontend/src/components/SchemaDesigner/common/util.ts b/frontend/src/components/SchemaDesigner/common/util.ts
index 40def226b3..926eb4d700 100644
--- a/frontend/src/components/SchemaDesigner/common/util.ts
+++ b/frontend/src/components/SchemaDesigner/common/util.ts
@@ -91,6 +91,7 @@ export const mergeSchemaEditToMetadata = (
column.nullable = columnEdit.nullable;
column.comment = columnEdit.comment;
column.userComment = columnEdit.userComment;
+ column.classification = columnEdit.classification ?? "";
column.default = columnEdit.default;
}
}
@@ -226,6 +227,7 @@ const transformSchemaEditToMetadata = (schemaEdit: Schema): SchemaMetadata => {
default: column.default,
comment: column.comment,
userComment: column.userComment,
+ classification: column.classification,
})
);
}
@@ -272,6 +274,7 @@ const transformTableEditToMetadata = (tableEdit: Table): TableMetadata => {
default: column.default,
comment: column.comment,
userComment: column.userComment,
+ classification: column.classification,
})
);
}
@@ -306,6 +309,7 @@ const transformColumnEditToMetadata = (columnEdit: Column): ColumnMetadata => {
default: columnEdit.default,
comment: columnEdit.comment,
userComment: columnEdit.userComment,
+ classification: columnEdit.classification,
});
};
@@ -349,6 +353,7 @@ export const rebuildEditableSchemas = (
editableColumn.nullable = column.nullable;
editableColumn.comment = column.comment;
editableColumn.userComment = column.userComment;
+ editableColumn.classification = column.classification;
editableColumn.default = column.default;
}
diff --git a/frontend/src/components/SchemaDesigner/index.vue b/frontend/src/components/SchemaDesigner/index.vue
index afcb262d23..ef70ec65bd 100644
--- a/frontend/src/components/SchemaDesigner/index.vue
+++ b/frontend/src/components/SchemaDesigner/index.vue
@@ -18,7 +18,12 @@ import { cloneDeep, isEqual } from "lodash-es";
import { Splitpanes, Pane } from "splitpanes";
import { onMounted, ref, watch } from "vue";
import { useSettingV1Store } from "@/store";
-import { Schema, convertSchemaMetadataList } from "@/types";
+import {
+ Schema,
+ convertSchemaMetadataList,
+ ComposedProject,
+ unknownProject,
+} from "@/types";
import { Engine } from "@/types/proto/v1/common";
import { DatabaseMetadata } from "@/types/proto/v1/database_service";
import { SchemaDesign } from "@/types/proto/v1/schema_design_service";
@@ -32,6 +37,7 @@ const props = defineProps<{
readonly: boolean;
engine: Engine;
schemaDesign: SchemaDesign;
+ project: ComposedProject;
}>();
const settingStore = useSettingV1Store();
@@ -40,6 +46,7 @@ const engine = ref(props.engine);
const metadata = ref<DatabaseMetadata>(DatabaseMetadata.fromPartial({}));
const originalSchemas = ref<Schema[]>([]);
const editableSchemas = ref<Schema[]>([]);
+const project = ref<ComposedProject>(unknownProject());
const baselineMetadata = ref<DatabaseMetadata>(
DatabaseMetadata.fromPartial({})
);
@@ -73,6 +80,7 @@ provideSchemaDesignerContext({
tabState: tabState,
originalSchemas: originalSchemas,
editableSchemas: editableSchemas,
+ project,
});
watch(
@@ -86,6 +94,7 @@ watch(
DatabaseMetadata.fromPartial({});
readonly.value = props.readonly;
engine.value = props.engine;
+ project.value = props.project;
},
{
immediate: true,
diff --git a/frontend/src/components/SchemaTemplate/ClassificationLevelBadge.vue b/frontend/src/components/SchemaTemplate/ClassificationLevelBadge.vue
new file mode 100644
index 0000000000..fc52846d05
--- /dev/null
+++ b/frontend/src/components/SchemaTemplate/ClassificationLevelBadge.vue
@@ -0,0 +1,35 @@
+<template>
+ <span
+ v-if="level"
+ :class="[
+ 'px-1 py-0.5 rounded text-xs',
+ bgColorList[Number(level.id) - 1] ?? 'bg-gray-200',
+ ]"
+ >
+ {{ level.title }}
+ </span>
+</template>
+
+<script lang="ts" setup>
+import { computed } from "vue";
+import { DataClassificationSetting_DataClassificationConfig } from "@/types/proto/v1/setting_service";
+
+const props = defineProps<{
+ levelId?: string;
+ classificationConfig: DataClassificationSetting_DataClassificationConfig;
+}>();
+
+const bgColorList = [
+ "bg-green-200",
+ "bg-yellow-200",
+ "bg-orange-300",
+ "bg-amber-500",
+ "bg-red-500",
+];
+
+const level = computed(() => {
+ return (props.classificationConfig.levels ?? []).find(
+ (level) => level.id === props.levelId
+ );
+});
+</script>
diff --git a/frontend/src/components/SchemaTemplate/FieldTemplateForm.vue b/frontend/src/components/SchemaTemplate/FieldTemplateForm.vue
index b05f82762e..8d87f0810d 100644
--- a/frontend/src/components/SchemaTemplate/FieldTemplateForm.vue
+++ b/frontend/src/components/SchemaTemplate/FieldTemplateForm.vue
@@ -89,6 +89,34 @@
/>
</div>
+ <div v-if="classificationConfig" class="sm:col-span-2 sm:col-start-1">
+ <label for="column-name" class="textlabel">
+ {{ $t("schema-template.classification.self") }}
+ </label>
+ <div class="flex items-center gap-x-2">
+ {{ columnClassification?.title ?? "N/A" }}
+ <ClassificationLevelBadge
+ :level-id="columnClassification?.levelId"
+ :classification-config="classificationConfig"
+ />
+ <div class="flex">
+ <button
+ v-if="columnClassification"
+ 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"
+ @click.prevent="state.showClassificationDrawer = true"
+ >
+ <heroicons-outline:pencil class="w-4 h-4" />
+ </button>
+ </div>
+ </div>
+ </div>
+
<!-- type -->
<div class="sm:col-span-2 sm:col-start-1">
<label for="column-type" class="textlabel">
@@ -200,6 +228,14 @@
</div>
</template>
</DrawerContent>
+
+ <SelectClassificationDrawer
+ v-if="classificationConfig"
+ :show="state.showClassificationDrawer"
+ :classification-config="classificationConfig"
+ @dismiss="state.showClassificationDrawer = false"
+ @select="onClassificationSelect"
+ />
</template>
<script lang="ts" setup>
@@ -224,14 +260,16 @@ const props = defineProps<{
const emit = defineEmits(["dismiss"]);
-// eslint-disable-next-line @typescript-eslint/no-empty-interface
-interface LocalState extends SchemaTemplateSetting_FieldTemplate {}
+interface LocalState extends SchemaTemplateSetting_FieldTemplate {
+ showClassificationDrawer: boolean;
+}
const state = reactive<LocalState>({
id: props.template.id,
engine: props.template.engine,
category: props.template.category,
column: Object.assign({}, props.template.column),
+ showClassificationDrawer: false,
});
const settingStore = useSettingV1Store();
const store = useSchemaEditorStore();
@@ -242,6 +280,20 @@ const allowEdit = computed(() => {
);
});
+const classificationConfig = computed(() => {
+ // TODO(ed): it's a temporary solution
+ return settingStore.classification[0];
+});
+
+const columnClassification = computed(() => {
+ if (!state.column?.classification || !classificationConfig.value) {
+ return;
+ }
+ return classificationConfig.value.classification[
+ state.column?.classification
+ ];
+});
+
const dataTypeOptions = computed(() => {
return getDataTypeSuggestionList(state.engine).map((dataType) => {
return {
@@ -301,4 +353,12 @@ const sumbit = async () => {
await store.upsertSchemaTemplate(state);
emit("dismiss");
};
+
+const onClassificationSelect = (id: string) => {
+ if (!state.column) {
+ return;
+ }
+ state.column.classification = id;
+ state.showClassificationDrawer = false;
+};
</script>
diff --git a/frontend/src/components/SchemaTemplate/FieldTemplateTable.vue b/frontend/src/components/SchemaTemplate/FieldTemplateTable.vue
index 7b80ff97f5..daaf68f1df 100644
--- a/frontend/src/components/SchemaTemplate/FieldTemplateTable.vue
+++ b/frontend/src/components/SchemaTemplate/FieldTemplateTable.vue
@@ -11,6 +11,15 @@
<EngineIcon :engine="item.engine" custom-class="ml-0 mr-1" />
{{ item.column?.name }}
</div>
+ <div class="bb-grid-cell flex gap-x-1">
+ {{ getColumnClassification(item.column?.classification)?.title }}
+ <ClassificationLevelBadge
+ :level-id="
+ getColumnClassification(item.column?.classification)?.levelId
+ "
+ :classification-config="classificationConfig"
+ />
+ </div>
<div class="bb-grid-cell">
{{ item.column?.type }}
</div>
@@ -45,7 +54,7 @@
import { computed } from "vue";
import { useI18n } from "vue-i18n";
import { BBGrid, BBGridColumn } from "@/bbkit";
-import { useSchemaEditorStore } from "@/store";
+import { useSchemaEditorStore, useSettingV1Store } from "@/store";
import { Engine } from "@/types/proto/v1/common";
import { SchemaTemplateSetting_FieldTemplate } from "@/types/proto/v1/setting_service";
import { getDefaultValue } from "./utils";
@@ -63,6 +72,7 @@ const emit = defineEmits<{
const { t } = useI18n();
const store = useSchemaEditorStore();
+const settingStore = useSettingV1Store();
const columnList = computed((): BBGridColumn[] => {
return [
@@ -71,6 +81,11 @@ const columnList = computed((): BBGridColumn[] => {
width: "auto",
class: "capitalize",
},
+ {
+ title: t("schema-template.classification.self"),
+ width: "auto",
+ class: "capitalize",
+ },
{
title: t("schema-template.form.column-type"),
width: "auto",
@@ -105,4 +120,15 @@ const isRowClickable = (template: SchemaTemplateSetting_FieldTemplate) => {
const deleteTemplate = async (id: string) => {
await store.deleteSchemaTemplate(id);
};
+
+const classificationConfig = computed(() => {
+ return settingStore.classification[0];
+});
+
+const getColumnClassification = (classificationId: string | undefined) => {
+ if (!classificationId || !classificationConfig.value) {
+ return;
+ }
+ return classificationConfig.value.classification[classificationId];
+};
</script>
diff --git a/frontend/src/components/SchemaTemplate/SelectClassificationDrawer.vue b/frontend/src/components/SchemaTemplate/SelectClassificationDrawer.vue
new file mode 100644
index 0000000000..c6234a420b
--- /dev/null
+++ b/frontend/src/components/SchemaTemplate/SelectClassificationDrawer.vue
@@ -0,0 +1,153 @@
+<template>
+ <Drawer :show="show" @close="$emit('dismiss')">
+ <DrawerContent :title="$t('schema-template.classification.select')">
+ <div class="divide-block-border space-y-8 w-[25rem] h-full">
+ <SearchBox
+ v-model:value="state.searchText"
+ style="width: 100%"
+ :placeholder="$t('schema-template.classification.search')"
+ />
+
+ <NTree
+ ref="treeRef"
+ block-line
+ style="height: 100%; user-select: none"
+ :data="treeData"
+ :multiple="false"
+ :selectable="true"
+ :pattern="state.searchText"
+ :show-irrelevant-nodes="false"
+ :expand-on-click="true"
+ :render-suffix="renderSuffix"
+ :node-props="nodeProps"
+ :virtual-scroll="true"
+ />
+ </div>
+
+ <template #footer>
+ <div class="w-full flex justify-between items-center">
+ <div class="w-full flex justify-end items-center gap-x-3">
+ <NButton @click.prevent="$emit('dismiss')">
+ {{ $t("common.cancel") }}
+ </NButton>
+ </div>
+ </div>
+ </template>
+ </DrawerContent>
+ </Drawer>
+</template>
+
+<script lang="ts" setup>
+import { NTree, TreeOption } from "naive-ui";
+import { computed, reactive, h } from "vue";
+import { Drawer, DrawerContent } from "@/components/v2";
+import { DataClassificationSetting_DataClassificationConfig } from "@/types/proto/v1/setting_service";
+import ClassificationLevelBadge from "./ClassificationLevelBadge.vue";
+
+const props = defineProps<{
+ show: boolean;
+ classificationConfig: DataClassificationSetting_DataClassificationConfig;
+}>();
+
+const emit = defineEmits<{
+ (event: "dismiss"): void;
+ (event: "select", classificationId: string): void;
+}>();
+
+interface LocalState {
+ searchText: string;
+}
+
+interface TreeNode extends TreeOption {
+ key: string;
+ label: string;
+ levelId?: string;
+ children?: TreeNode[];
+}
+
+interface ClassificationMap {
+ [key: string]: {
+ id: string;
+ label: string;
+ levelId?: string;
+ children: ClassificationMap;
+ };
+}
+
+const state = reactive<LocalState>({
+ searchText: "",
+});
+
+const nodeProps = ({ option }: { option: TreeOption }) => {
+ return {
+ onClick(e: MouseEvent) {
+ if (!option.isLeaf || !option.key) {
+ return;
+ }
+ emit("select", option.key as string);
+ },
+ };
+};
+
+const sortClassification = (
+ item1: { id: string },
+ item2: { id: string }
+): number => {
+ const n1 = Number(item1.id.split("-").join(""));
+ const n2 = Number(item2.id.split("-").join(""));
+ return n1 - n2;
+};
+
+const treeData = computed((): TreeNode[] => {
+ const classifications = Object.values(
+ props.classificationConfig.classification
+ ).sort(sortClassification);
+
+ const classificationMap: ClassificationMap = {};
+ for (const classification of classifications) {
+ const ids = classification.id.split("-");
+ let tmp = classificationMap;
+ for (let i = 0; i < ids.length - 1; i++) {
+ tmp = tmp[ids.slice(0, i + 1).join("-")].children;
+ if (!tmp) {
+ break;
+ }
+ }
+ if (tmp) {
+ tmp[classification.id] = {
+ id: classification.id,
+ label: classification.title,
+ levelId: classification.levelId,
+ children: {},
+ };
+ }
+ }
+ return getTreeNodeList(classificationMap);
+});
+
+const getTreeNodeList = (classificationMap: ClassificationMap): TreeNode[] => {
+ return Object.values(classificationMap)
+ .sort(sortClassification)
+ .map((item) => {
+ const children = getTreeNodeList(item.children);
+ return {
+ key: item.id,
+ label: item.label,
+ levelId: item.levelId,
+ isLeaf: children.length === 0,
+ children,
+ };
+ });
+};
+
+const renderSuffix = ({ option }: { option: TreeOption }) => {
+ const node = option as any as TreeNode;
+ if (!node.levelId) {
+ return null;
+ }
+ return h(ClassificationLevelBadge, {
+ levelId: node.levelId,
+ classificationConfig: props.classificationConfig,
+ });
+};
+</script>
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 2aeb3f6c10..1772a748b8 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1970,7 +1970,8 @@
"comment": "Comment",
"not-null": "Not Null",
"primary": "Primary",
- "foreign-key": "Foreign Key"
+ "foreign-key": "Foreign Key",
+ "classification": "Classification"
},
"nothing-changed": "Nothing changed",
"message": {
@@ -2763,6 +2764,11 @@
"default-value": "Default value",
"comment": "Comment",
"nullable": "Nullable"
+ },
+ "classification": {
+ "self": "Data Classification",
+ "select": "Select classification",
+ "search": "Search classification"
}
},
"principal": {
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index e33b42c41a..57740aebd2 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -1966,7 +1966,8 @@
"comment": "Comentario",
"not-null": "No nulo",
"primary": "Primaria",
- "foreign-key": "Clave foránea"
+ "foreign-key": "Clave foránea",
+ "classification": "Clasificación"
},
"nothing-changed": "Nada ha cambiado",
"message": {
@@ -2760,6 +2761,11 @@
"default-value": "Valor por defecto",
"comment": "Comentario",
"nullable": "Anulable"
+ },
+ "classification": {
+ "self": "Clasificación de datos",
+ "select": "Seleccionar clasificación",
+ "search": "Clasificación de búsqueda"
}
},
"principal": {
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 58b1dde306..d451767d1e 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1966,7 +1966,8 @@
"comment": "注释",
"not-null": "不可为空",
"primary": "主键",
- "foreign-key": "外键"
+ "foreign-key": "外键",
+ "classification": "分类分级"
},
"nothing-changed": "无任何改动",
"message": {
@@ -2756,6 +2757,11 @@
"default-value": "默认值",
"comment": "备注",
"nullable": "可为空"
+ },
+ "classification": {
+ "self": "数据分类分级",
+ "select": "选择分类",
+ "search": "搜索分类"
}
},
"principal": {
diff --git a/frontend/src/store/modules/v1/setting.ts b/frontend/src/store/modules/v1/setting.ts
index b8540bebb9..c4476bd350 100644
--- a/frontend/src/store/modules/v1/setting.ts
+++ b/frontend/src/store/modules/v1/setting.ts
@@ -31,6 +31,14 @@ export const useSettingV1Store = defineStore("setting_v1", {
);
return setting?.value?.stringValue;
},
+ classification(
+ state
+ ): DataClassificationSetting_DataClassificationConfig[] {
+ const setting = this.settingMapByName.get(
+ `${settingNamePrefix}bb.workspace.data-classification`
+ );
+ return setting?.value?.dataClassificationSettingValue?.configs ?? [];
+ },
},
actions: {
getProjectClassification(
diff --git a/frontend/src/types/schemaEditor/atomType.ts b/frontend/src/types/schemaEditor/atomType.ts
index 79d4c27b19..f89014e206 100644
--- a/frontend/src/types/schemaEditor/atomType.ts
+++ b/frontend/src/types/schemaEditor/atomType.ts
@@ -17,6 +17,7 @@ export interface Column {
userComment: string;
default?: string;
status: AtomResourceStatus;
+ classification?: string;
}
export interface PrimaryKey {
@@ -68,6 +69,7 @@ export const convertColumnMetadataToColumn = (
comment: columnMetadata.comment,
userComment: columnMetadata.userComment,
default: columnMetadata.default,
+ classification: columnMetadata.classification,
status: "normal",
};
};