fix: resolve the issue of ineffective duplicate key validation in AnnotationsForm (#4369)

#### What type of PR is this?

/kind bug
/area console

#### What this PR does / why we need it:

在 AnnotationsForm 新增 customAnnotationsDuplicateKey 校验规则,校验自定义元数据中是否具有重复的 key。

#### Which issue(s) this PR fixes:

Fixes #4367 

#### Special notes for your reviewer:

在任意一个使用 AnnotationsForm 的位置,例如`文章设置 - 元数据` 中,新增一个已经存在的 key,查看是否有重复 key 的校验。

#### Does this PR introduce a user-facing change?
```release-note
修复 AnnotationsForm 重复的 key 校验无效的问题。
```
pull/4392/head
Takagi 2023-08-08 15:04:12 +08:00 committed by GitHub
parent 20df302ef5
commit 3ec409100b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 1 deletions

View File

@ -17,7 +17,10 @@ import { randomUUID } from "@/utils/id";
const themeStore = useThemeStore();
function keyValidationRule(node: FormKitNode) {
return !annotations?.[node.value as string];
return (
!annotations.value?.[node.value as string] &&
!customAnnotationsDuplicateKey.value
);
}
const props = withDefaults(
@ -70,6 +73,12 @@ const annotations = ref<{
}>({});
const customAnnotationsState = ref<{ key: string; value: string }[]>([]);
const customAnnotationsDuplicateKey = computed(() => {
const keys = customAnnotationsState.value.map((item) => item.key);
const uniqueKeys = new Set(keys);
return keys.length !== uniqueKeys.size;
});
const customAnnotations = computed(() => {
return customAnnotationsState.value.reduce((acc, cur) => {
acc[cur.key] = cur.value;