From 76dbbf86665a4e27697c5bc85d295fbd0e4c5d9b Mon Sep 17 00:00:00 2001 From: Tyler Davis Date: Thu, 12 Dec 2024 21:53:54 +1100 Subject: [PATCH] more closely replicate previous filterKinds implementation Signed-off-by: Tyler Davis --- .../components/EntityKindPicker/kindFilterUtils.ts | 12 ++++++++---- .../components/CatalogKindHeader/kindFilterUtils.ts | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/plugins/catalog-react/src/components/EntityKindPicker/kindFilterUtils.ts b/plugins/catalog-react/src/components/EntityKindPicker/kindFilterUtils.ts index 2147dbd3b8..6e6d9c134c 100644 --- a/plugins/catalog-react/src/components/EntityKindPicker/kindFilterUtils.ts +++ b/plugins/catalog-react/src/components/EntityKindPicker/kindFilterUtils.ts @@ -56,15 +56,19 @@ export function filterKinds( // enforced casing from the catalog-backend. This makes a key/value record for the Select options, // including selectedKind if it's unknown - but allows the selectedKind to get clobbered by the // more proper catalog kind if it exists. - const desiredKinds = allowedKinds - ? allowedKinds.map(k => k.toLocaleLowerCase('en-US')) - : Array.from(allKinds.keys()); + let availableKinds = Array.from(allKinds.keys()); + if (allowedKinds) { + availableKinds = allowedKinds + .map(k => k.toLocaleLowerCase('en-US')) + .filter(k => allKinds.has(k)); + } const kindsMap = new Map( - desiredKinds.map(kind => [kind, allKinds.get(kind) || kind]), + availableKinds.map(kind => [kind, allKinds.get(kind) || kind]), ); if (forcedKinds && !kindsMap.has(forcedKinds)) { + // this is the only time we set a label for a kind which is not properly capitalized kindsMap.set(forcedKinds.toLocaleLowerCase('en-US'), forcedKinds); } diff --git a/plugins/catalog/src/components/CatalogKindHeader/kindFilterUtils.ts b/plugins/catalog/src/components/CatalogKindHeader/kindFilterUtils.ts index 9fbe82548e..4c6fd74609 100644 --- a/plugins/catalog/src/components/CatalogKindHeader/kindFilterUtils.ts +++ b/plugins/catalog/src/components/CatalogKindHeader/kindFilterUtils.ts @@ -56,15 +56,19 @@ export function filterKinds( // enforced casing from the catalog-backend. This makes a key/value record for the Select options, // including selectedKind if it's unknown - but allows the selectedKind to get clobbered by the // more proper catalog kind if it exists. - const desiredKinds = allowedKinds - ? allowedKinds.map(k => k.toLocaleLowerCase('en-US')) - : Array.from(allKinds.keys()); + let availableKinds = Array.from(allKinds.keys()); + if (allowedKinds) { + availableKinds = allowedKinds + .map(k => k.toLocaleLowerCase('en-US')) + .filter(k => allKinds.has(k)); + } const kindsMap = new Map( - desiredKinds.map(kind => [kind, allKinds.get(kind) || kind]), + availableKinds.map(kind => [kind, allKinds.get(kind) || kind]), ); if (forcedKinds && !kindsMap.has(forcedKinds)) { + // this is the only time we set a label for a kind which is not properly capitalized kindsMap.set(forcedKinds.toLocaleLowerCase('en-US'), forcedKinds); }