소스 검색

Fix LabelDictionary overwriting stale in-memory cached field labels

`pushToCache` was skipping updates for already-seen field names, causing
the `UI` to display outdated titles even after a fresh schema fetch.
Update existing entries instead of skipping them.

Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
Mihaela Balutoiu 1 개월 전
부모
커밋
3816f73ba5
1개의 변경된 파일16개의 추가작업 그리고 10개의 파일을 삭제
  1. 16 10
      src/utils/LabelDictionary.ts

+ 16 - 10
src/utils/LabelDictionary.ts

@@ -178,16 +178,22 @@ class LabelDictionary {
   }
 
   static pushToCache(field: Field, dictionaryKey: string) {
-    if (
-      (field.title || field.description) &&
-      !cache.find(i => i.key === dictionaryKey && i.name === field.name)
-    ) {
-      cache.push({
-        label: field.title,
-        description: field.description,
-        name: field.name,
-        key: dictionaryKey,
-      });
+    if (!(field.title || field.description)) {
+      return;
+    }
+    const existingIndex = cache.findIndex(
+      i => i.key === dictionaryKey && i.name === field.name,
+    );
+    const entry = {
+      label: field.title,
+      description: field.description,
+      name: field.name,
+      key: dictionaryKey,
+    };
+    if (existingIndex >= 0) {
+      cache[existingIndex] = entry;
+    } else {
+      cache.push(entry);
     }
   }
 }