diff --git a/plugins/catalog-react/src/components/EntityRefLink/humanize.test.ts b/plugins/catalog-react/src/components/EntityRefLink/humanize.test.ts index e7d1649a29..1182a7778d 100644 --- a/plugins/catalog-react/src/components/EntityRefLink/humanize.test.ts +++ b/plugins/catalog-react/src/components/EntityRefLink/humanize.test.ts @@ -215,9 +215,12 @@ describe('humanizeEntityRef', () => { describe('humanizeEntity', () => { it('gives a readable name when one is provided at metadata.title', () => { expect( - humanizeEntity({ - metadata: { name: 'my-entity', title: 'My Title' }, - } as Entity), + humanizeEntity( + { + metadata: { name: 'my-entity', title: 'My Title' }, + } as Entity, + 'default', + ), ).toBe('My Title'); }); @@ -257,13 +260,16 @@ describe('humanizeEntity', () => { ])( 'gives a readable name for kind %s when one is provided at spec.profile.displayName', (_, entity: Entity, expected) => { - expect(humanizeEntity(entity)).toBe(expected); + expect(humanizeEntity(entity, 'default')).toBe(expected); }, ); it('should pass through to humanizeEntityRef when nothing matches', () => { expect( - humanizeEntity({ kind: 'Group', metadata: { name: 'test' } } as Entity), - ).toBe('group:test'); + humanizeEntity( + { kind: 'Group', metadata: { name: 'test' } } as Entity, + 'default', + ), + ).toBe('default'); }); }); diff --git a/plugins/catalog-react/src/components/EntityRefLink/humanize.ts b/plugins/catalog-react/src/components/EntityRefLink/humanize.ts index 7f1501280a..478f0dce9d 100644 --- a/plugins/catalog-react/src/components/EntityRefLink/humanize.ts +++ b/plugins/catalog-react/src/components/EntityRefLink/humanize.ts @@ -25,7 +25,8 @@ import get from 'lodash/get'; * @param defaultNamespace - if set to false then namespace is never omitted, * if set to string which matches namespace of entity then omitted * - * @public */ + * @public + **/ export function humanizeEntityRef( entityRef: Entity | CompoundEntityRef, opts?: { @@ -73,27 +74,19 @@ export function humanizeEntityRef( * If an entity is either User or Group, this will be its `spec.profile.displayName`. * Otherwise, this is `metadata.title`. * - * If neither of those are found or populated, fallback to `humanizeEntityRef`. + * If neither of those are found or populated, fallback to `defaultName`. * * @param entity - Entity to convert. - * @param opts - If entity readable name is not available, opts will be used to specify humanizeEntityRef options. - * @returns Readable name, defaults to unique identifier. + * @param defaultName - If entity readable name is not available, `defaultName` will be returned. + * @returns Readable name, defaults to `defaultName`. * - * @public */ -export function humanizeEntity( - entity: Entity, - opts?: { - defaultKind?: string; - defaultNamespace?: string | false; - }, -) { +export function humanizeEntity(entity: Entity, defaultName: string) { for (const path of ['spec.profile.displayName', 'metadata.title']) { const value = get(entity, path); if (value && typeof value === 'string') { return value; } } - - return humanizeEntityRef(entity, opts); + return defaultName; }