Skip to content

Commit 3816f73

Browse files
mihaelabalutoiuDany9966
authored andcommitted
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>
1 parent afd91f9 commit 3816f73

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

src/utils/LabelDictionary.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,22 @@ class LabelDictionary {
178178
}
179179

180180
static pushToCache(field: Field, dictionaryKey: string) {
181-
if (
182-
(field.title || field.description) &&
183-
!cache.find(i => i.key === dictionaryKey && i.name === field.name)
184-
) {
185-
cache.push({
186-
label: field.title,
187-
description: field.description,
188-
name: field.name,
189-
key: dictionaryKey,
190-
});
181+
if (!(field.title || field.description)) {
182+
return;
183+
}
184+
const existingIndex = cache.findIndex(
185+
i => i.key === dictionaryKey && i.name === field.name,
186+
);
187+
const entry = {
188+
label: field.title,
189+
description: field.description,
190+
name: field.name,
191+
key: dictionaryKey,
192+
};
193+
if (existingIndex >= 0) {
194+
cache[existingIndex] = entry;
195+
} else {
196+
cache.push(entry);
191197
}
192198
}
193199
}

0 commit comments

Comments
 (0)