Skip to content

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

fix: sort classification (#10893)

ecmadao892d1c61789c
diff --git a/frontend/src/components/SchemaTemplate/ClassificationTree.vue b/frontend/src/components/SchemaTemplate/ClassificationTree.vue
index efddfd9c5a..c7669637b8 100644
--- a/frontend/src/components/SchemaTemplate/ClassificationTree.vue
+++ b/frontend/src/components/SchemaTemplate/ClassificationTree.vue
@@ -79,9 +79,25 @@ 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 id1s = item1.id.split("-");
+ const id2s = item2.id.split("-");
+
+ if (id1s.length !== id2s.length) {
+ return id1s.length - id2s.length;
+ }
+
+ for (let i = 0; i < id1s.length; i++) {
+ if (id1s[i] === id2s[i]) {
+ continue;
+ }
+ if (Number.isNaN(id1s[i]) || Number.isNaN(id1s[i])) {
+ return id1s[i].localeCompare(id2s[i]);
+ }
+ return Number(id1s[i]) - Number(id2s[i]);
+ }
+
+ // shouldn't has duplicate id
+ return 0;
};
const treeData = computed((): TreeNode[] => {
diff --git a/frontend/src/components/SensitiveData/ClassificationView.vue b/frontend/src/components/SensitiveData/ClassificationView.vue
index 4632f79c1d..04d8597100 100644
--- a/frontend/src/components/SensitiveData/ClassificationView.vue
+++ b/frontend/src/components/SensitiveData/ClassificationView.vue
@@ -150,16 +150,27 @@ const onFileChange = () => {
return pushNotification({
module: "bytebase",
style: "CRITICAL",
- title: `Read file error`,
- description: "should has classifications array field",
+ title: "Data format error",
+ description: "Should has classifications array field",
});
}
if (!Array.isArray(data.levels) || data.levels.length === 0) {
return pushNotification({
module: "bytebase",
style: "CRITICAL",
- title: `Read file error`,
- description: "should has levels array field",
+ title: "Data format error",
+ description: "Should has levels array field",
+ });
+ }
+ if (
+ data.classifications.length !==
+ new Set(data.classifications.map((item) => item.id)).size
+ ) {
+ return pushNotification({
+ module: "bytebase",
+ style: "CRITICAL",
+ title: "Data format error",
+ description: "Should not contains duplicate classification id",
});
}
state.classification =
@@ -177,7 +188,7 @@ const onFileChange = () => {
pushNotification({
module: "bytebase",
style: "CRITICAL",
- title: `Read file error`,
+ title: "Read file error",
description: String(fr.error),
});
return;