From 2510b6418592fd02899d2a3a180a22f3f1216e2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Tunkl?= Date: Fri, 5 Aug 2022 15:20:07 +0200 Subject: [PATCH] Adds possibility to not skip default namespace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomáš Tunkl --- .../components/EntityRefLink/humanize.test.ts | 28 +++++++++++++++++++ .../src/components/EntityRefLink/humanize.ts | 8 ++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/plugins/catalog-react/src/components/EntityRefLink/humanize.test.ts b/plugins/catalog-react/src/components/EntityRefLink/humanize.test.ts index d41d3c6635..ac873b5140 100644 --- a/plugins/catalog-react/src/components/EntityRefLink/humanize.test.ts +++ b/plugins/catalog-react/src/components/EntityRefLink/humanize.test.ts @@ -34,6 +34,23 @@ describe('humanizeEntityRef', () => { expect(title).toEqual('component:software'); }); + it('formats entity in default namespace without skipping default namespace', () => { + const entity = { + apiVersion: 'v1', + kind: 'Component', + metadata: { + name: 'software', + }, + spec: { + owner: 'guest', + type: 'service', + lifecycle: 'production', + }, + }; + const title = humanizeEntityRef(entity, {skipDefaultNamespace: false}); + expect(title).toEqual('component:default/software'); + }); + it('formats entity in other namespace', () => { const entity = { apiVersion: 'v1', @@ -103,4 +120,15 @@ describe('humanizeEntityRef', () => { }); expect(title).toEqual('test/software'); }); + + it('formats entity name in default namespace without skip of default namespace', () => { + const entityName = { + kind: 'Component', + namespace: 'default', + name: 'software', + }; + + const title = humanizeEntityRef(entityName, {skipDefaultNamespace: false}); + expect(title).toEqual('component:default/software'); + }); }); diff --git a/plugins/catalog-react/src/components/EntityRefLink/humanize.ts b/plugins/catalog-react/src/components/EntityRefLink/humanize.ts index 2f72a7ee3b..bbf826ecb2 100644 --- a/plugins/catalog-react/src/components/EntityRefLink/humanize.ts +++ b/plugins/catalog-react/src/components/EntityRefLink/humanize.ts @@ -23,9 +23,13 @@ import { /** @public */ export function humanizeEntityRef( entityRef: Entity | CompoundEntityRef, - opts?: { defaultKind?: string }, + opts?: { + defaultKind?: string + skipDefaultNamespace?: boolean + }, ) { const defaultKind = opts?.defaultKind; + const skipDefaultNamespace = opts?.skipDefaultNamespace ?? true; let kind; let namespace; let name; @@ -40,7 +44,7 @@ export function humanizeEntityRef( name = entityRef.name; } - if (namespace === DEFAULT_NAMESPACE) { + if (skipDefaultNamespace === true && namespace === DEFAULT_NAMESPACE) { namespace = undefined; }