Skip to content

Commit

Permalink
fix: resolve the issue of receiving duplicate key error after deletin…
Browse files Browse the repository at this point in the history
…g metadata (#4815)

#### What type of PR is this?

/kind bug
/area console
/milestone 2.11.x

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

重构去重元数据的逻辑,解决删除元数据后仍旧提示 key 不能重复的问题。

#### How to test it?

1. 在文章列表点击设置按钮
2. 添加两个个空的元数据,不保存直接关闭设置框。
3. 再次打开设置框,点击删除空的元数据,查看是否会提示 key 重复。

#### Does this PR introduce a user-facing change?
```release-note
解决删除元数据后仍旧提示 key 不能重复的问题
```
  • Loading branch information
LIlGG authored Nov 2, 2023
1 parent a8a5413 commit 57b2426
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions console/src/components/form/AnnotationsForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import { randomUUID } from "@/utils/id";
const themeStore = useThemeStore();
function keyValidationRule(node: FormKitNode) {
return (
!annotations.value?.[node.value as string] &&
!customAnnotationsDuplicateKey.value
);
const validAnnotations = [
...Object.keys(annotations.value),
...customAnnotationsState.value.map((item) => item.key),
];
const count = validAnnotations.filter((item) => item === node.value);
return count.length < 2;
}
const props = withDefaults(
Expand Down Expand Up @@ -73,12 +75,6 @@ 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;
Expand Down

0 comments on commit 57b2426

Please sign in to comment.