From 58bb120c80a499c3925e28fa297f3f3c6d78226e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 16 Jul 2024 03:26:25 +0000 Subject: [PATCH 1/2] chore(deps): update dependency @types/lodash to v4.17.7 Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index b0bff82017..bcf4c10e5d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -17994,9 +17994,9 @@ __metadata: linkType: hard "@types/lodash@npm:^4.14.151": - version: 4.17.5 - resolution: "@types/lodash@npm:4.17.5" - checksum: 3c9bb15772509f0ecb40428531863dbc3f064f2bf34bbccc2ce2b2923c69fb0868aec7e357b1d97fd0d7f7e435a014ea5c1adef8a64715529887179c97a5a823 + version: 4.17.7 + resolution: "@types/lodash@npm:4.17.7" + checksum: 09e58a119cd8a70acfb33f8623dc2fc54f74cdce3b3429b879fc2daac4807fe376190a04b9e024dd300f9a3ee1876d6623979cefe619f70654ca0fe0c47679a7 languageName: node linkType: hard From ae9b6cbc71dab2fa32f61e923691de069ff29702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Tue, 27 Aug 2024 16:11:16 +0200 Subject: [PATCH 2/2] fixup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .changeset/tiny-icons-sit.md | 5 ++++ .../defaultEntityPresentation.ts | 23 ++++++++----------- .../EntityOwnerPicker/useFacetsEntities.ts | 7 ++++-- 3 files changed, 20 insertions(+), 15 deletions(-) create mode 100644 .changeset/tiny-icons-sit.md diff --git a/.changeset/tiny-icons-sit.md b/.changeset/tiny-icons-sit.md new file mode 100644 index 0000000000..7dc35a46fd --- /dev/null +++ b/.changeset/tiny-icons-sit.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-react': patch +--- + +Small internal fix to better work with recent `lodash` versions diff --git a/plugins/catalog-react/src/apis/EntityPresentationApi/defaultEntityPresentation.ts b/plugins/catalog-react/src/apis/EntityPresentationApi/defaultEntityPresentation.ts index 8d841f3c3c..b546f9aa93 100644 --- a/plugins/catalog-react/src/apis/EntityPresentationApi/defaultEntityPresentation.ts +++ b/plugins/catalog-react/src/apis/EntityPresentationApi/defaultEntityPresentation.ts @@ -71,6 +71,9 @@ export function defaultEntityPresentation( }; } +const isString = (value: unknown): value is string => + Boolean(value) && typeof value === 'string'; + // Try to extract display-worthy parts of an entity or ref as best we can, without throwing function getParts(entityOrRef: Entity | CompoundEntityRef | string): { kind?: string; @@ -99,35 +102,29 @@ function getParts(entityOrRef: Entity | CompoundEntityRef | string): { } if (typeof entityOrRef === 'object' && entityOrRef !== null) { - const kind = [get(entityOrRef, 'kind')].find( - candidate => candidate && typeof candidate === 'string', - ); + const kind = [get(entityOrRef, 'kind')].find(isString); const namespace = [ get(entityOrRef, 'metadata.namespace'), get(entityOrRef, 'namespace'), - ].find(candidate => candidate && typeof candidate === 'string'); + ].find(isString); const name = [ get(entityOrRef, 'metadata.name'), get(entityOrRef, 'name'), - ].find(candidate => candidate && typeof candidate === 'string'); + ].find(isString); - const title = [get(entityOrRef, 'metadata.title')].find( - candidate => candidate && typeof candidate === 'string', - ); + const title = [get(entityOrRef, 'metadata.title')].find(isString); const description = [get(entityOrRef, 'metadata.description')].find( - candidate => candidate && typeof candidate === 'string', + isString, ); const displayName = [get(entityOrRef, 'spec.profile.displayName')].find( - candidate => candidate && typeof candidate === 'string', + isString, ); - const type = [get(entityOrRef, 'spec.type')].find( - candidate => candidate && typeof candidate === 'string', - ); + const type = [get(entityOrRef, 'spec.type')].find(isString); return { kind, namespace, name, title, description, displayName, type }; } diff --git a/plugins/catalog-react/src/components/EntityOwnerPicker/useFacetsEntities.ts b/plugins/catalog-react/src/components/EntityOwnerPicker/useFacetsEntities.ts index 10a5c5a8c2..a82f2daaab 100644 --- a/plugins/catalog-react/src/components/EntityOwnerPicker/useFacetsEntities.ts +++ b/plugins/catalog-react/src/components/EntityOwnerPicker/useFacetsEntities.ts @@ -34,6 +34,9 @@ type FacetsInitialRequest = { text: string; }; +const maybeString = (value: unknown): string | undefined => + typeof value === 'string' ? value : undefined; + /** * This hook asynchronously loads the entity owners using the facets endpoint. * EntityOwnerPicker uses this hook when mode="owners-only" is passed as prop. @@ -67,11 +70,11 @@ export function useFacetsEntities({ enabled }: { enabled: boolean }) { 'en-US', ) || ( - get(a, 'spec.profile.displayName') || + maybeString(get(a, 'spec.profile.displayName')) || a.metadata.title || a.metadata.name ).localeCompare( - get(b, 'spec.profile.displayName') || + maybeString(get(b, 'spec.profile.displayName')) || b.metadata.title || b.metadata.name, 'en-US',