From 4cf9a79b44ee0822dcd5379b66eebb751fd46378 Mon Sep 17 00:00:00 2001
From: LIlGG <1103069291@qq.com>
Date: Tue, 31 Oct 2023 17:18:53 +0800
Subject: [PATCH 1/2] fix: resolve the issue of occasional blank metadata and
 error occurrences

---
 console/src/components/form/AnnotationsForm.vue | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/console/src/components/form/AnnotationsForm.vue b/console/src/components/form/AnnotationsForm.vue
index 11cb240052..9bb06fd55b 100644
--- a/console/src/components/form/AnnotationsForm.vue
+++ b/console/src/components/form/AnnotationsForm.vue
@@ -13,6 +13,7 @@ import cloneDeep from "lodash.clonedeep";
 import { getValidationMessages } from "@formkit/validation";
 import { useThemeStore } from "@/stores/theme";
 import { randomUUID } from "@/utils/id";
+import { onUnmounted } from "vue";
 
 const themeStore = useThemeStore();
 
@@ -150,9 +151,20 @@ onMounted(async () => {
   handleProcessCustomAnnotations();
 });
 
+onUnmounted(() => {
+  cleanAnnotations();
+  annotationSettings.value = [];
+});
+
+const cleanAnnotations = () => {
+  annotations.value = {};
+  customAnnotationsState.value = [];
+};
+
 watch(
   () => props.value,
   (value) => {
+    cleanAnnotations();
     reset(specFormId);
     reset(customFormId);
     annotations.value = cloneDeep(props.value) || {};

From edaf3fc1c00d7915728c2d7591594bc76b23824f Mon Sep 17 00:00:00 2001
From: LIlGG <1103069291@qq.com>
Date: Wed, 1 Nov 2023 18:09:32 +0800
Subject: [PATCH 2/2] fix: resolve errors caused by blank annotations

---
 .../src/components/form/AnnotationsForm.vue   | 28 ++++---------------
 1 file changed, 6 insertions(+), 22 deletions(-)

diff --git a/console/src/components/form/AnnotationsForm.vue b/console/src/components/form/AnnotationsForm.vue
index 9bb06fd55b..676686b8a7 100644
--- a/console/src/components/form/AnnotationsForm.vue
+++ b/console/src/components/form/AnnotationsForm.vue
@@ -13,15 +13,16 @@ import cloneDeep from "lodash.clonedeep";
 import { getValidationMessages } from "@formkit/validation";
 import { useThemeStore } from "@/stores/theme";
 import { randomUUID } from "@/utils/id";
-import { onUnmounted } from "vue";
 
 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(
@@ -74,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;
@@ -151,20 +146,9 @@ onMounted(async () => {
   handleProcessCustomAnnotations();
 });
 
-onUnmounted(() => {
-  cleanAnnotations();
-  annotationSettings.value = [];
-});
-
-const cleanAnnotations = () => {
-  annotations.value = {};
-  customAnnotationsState.value = [];
-};
-
 watch(
   () => props.value,
   (value) => {
-    cleanAnnotations();
     reset(specFormId);
     reset(customFormId);
     annotations.value = cloneDeep(props.value) || {};