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 1/8] 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; } From f6033d1121a053901f1df02c852db25171ffb43c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Tunkl?= Date: Tue, 23 Aug 2022 12:06:57 +0200 Subject: [PATCH 2/8] New changeset MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomáš Tunkl --- .changeset/eight-shrimps-call.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/eight-shrimps-call.md diff --git a/.changeset/eight-shrimps-call.md b/.changeset/eight-shrimps-call.md new file mode 100644 index 0000000000..2e19681f7a --- /dev/null +++ b/.changeset/eight-shrimps-call.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-react': patch +--- + +humanizeEntityRef function can now be forced to include default namespace From 727e66aeb60258c04399defdd56585b159f1e3aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Tunkl?= Date: Tue, 23 Aug 2022 12:50:27 +0200 Subject: [PATCH 3/8] Applied prettier on files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomáš Tunkl --- .../src/components/EntityRefLink/humanize.test.ts | 6 ++++-- .../catalog-react/src/components/EntityRefLink/humanize.ts | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/catalog-react/src/components/EntityRefLink/humanize.test.ts b/plugins/catalog-react/src/components/EntityRefLink/humanize.test.ts index ac873b5140..9f08290095 100644 --- a/plugins/catalog-react/src/components/EntityRefLink/humanize.test.ts +++ b/plugins/catalog-react/src/components/EntityRefLink/humanize.test.ts @@ -47,7 +47,7 @@ describe('humanizeEntityRef', () => { lifecycle: 'production', }, }; - const title = humanizeEntityRef(entity, {skipDefaultNamespace: false}); + const title = humanizeEntityRef(entity, { skipDefaultNamespace: false }); expect(title).toEqual('component:default/software'); }); @@ -128,7 +128,9 @@ describe('humanizeEntityRef', () => { name: 'software', }; - const title = humanizeEntityRef(entityName, {skipDefaultNamespace: false}); + 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 bbf826ecb2..bd97ce2548 100644 --- a/plugins/catalog-react/src/components/EntityRefLink/humanize.ts +++ b/plugins/catalog-react/src/components/EntityRefLink/humanize.ts @@ -24,8 +24,8 @@ import { export function humanizeEntityRef( entityRef: Entity | CompoundEntityRef, opts?: { - defaultKind?: string - skipDefaultNamespace?: boolean + defaultKind?: string; + skipDefaultNamespace?: boolean; }, ) { const defaultKind = opts?.defaultKind; From ec12bbe64b5060a87f521bf2f81baf5174ed4aad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Tunkl?= Date: Thu, 8 Sep 2022 13:04:03 +0200 Subject: [PATCH 4/8] Implemented new tests for humanize update. Fix of logic 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 | 80 ++++++++++++++++++- .../src/components/EntityRefLink/humanize.ts | 18 ++++- 2 files changed, 92 insertions(+), 6 deletions(-) diff --git a/plugins/catalog-react/src/components/EntityRefLink/humanize.test.ts b/plugins/catalog-react/src/components/EntityRefLink/humanize.test.ts index 9f08290095..80ce2100f6 100644 --- a/plugins/catalog-react/src/components/EntityRefLink/humanize.test.ts +++ b/plugins/catalog-react/src/components/EntityRefLink/humanize.test.ts @@ -47,7 +47,7 @@ describe('humanizeEntityRef', () => { lifecycle: 'production', }, }; - const title = humanizeEntityRef(entity, { skipDefaultNamespace: false }); + const title = humanizeEntityRef(entity, { defaultNamespace: false }); expect(title).toEqual('component:default/software'); }); @@ -69,6 +69,24 @@ describe('humanizeEntityRef', () => { expect(title).toEqual('component:test/software'); }); + it('formats entity in other namespace and hides this namespace', () => { + const entity = { + apiVersion: 'v1', + kind: 'Component', + metadata: { + name: 'software', + namespace: 'test', + }, + spec: { + owner: 'guest', + type: 'service', + lifecycle: 'production', + }, + }; + const title = humanizeEntityRef(entity, { defaultNamespace: 'test' }); + expect(title).toEqual('component:software'); + }); + it('formats entity and hides default kind', () => { const entity = { apiVersion: 'v1', @@ -87,6 +105,27 @@ describe('humanizeEntityRef', () => { expect(title).toEqual('test/software'); }); + it('formats entity and hides default kind and hiding namespace', () => { + const entity = { + apiVersion: 'v1', + kind: 'Component', + metadata: { + name: 'software', + namespace: 'test', + }, + spec: { + owner: 'guest', + type: 'service', + lifecycle: 'production', + }, + }; + const title = humanizeEntityRef(entity, { + defaultKind: 'Component', + defaultNamespace: 'test', + }); + expect(title).toEqual('software'); + }); + it('formats entity name in default namespace', () => { const entityName = { kind: 'Component', @@ -97,6 +136,16 @@ describe('humanizeEntityRef', () => { expect(title).toEqual('component:software'); }); + it('formats entity name in default namespace and does not skip default namespace', () => { + const entityName = { + kind: 'Component', + namespace: 'default', + name: 'software', + }; + const title = humanizeEntityRef(entityName, { defaultNamespace: false }); + expect(title).toEqual('component:default/software'); + }); + it('formats entity name in other namespace', () => { const entityName = { kind: 'Component', @@ -108,6 +157,19 @@ describe('humanizeEntityRef', () => { expect(title).toEqual('component:test/software'); }); + it('formats entity name in other namespace with skipping this namespace', () => { + const entityName = { + kind: 'Component', + namespace: 'test', + name: 'software', + }; + + const title = humanizeEntityRef(entityName, { + defaultNamespace: 'test', + }); + expect(title).toEqual('component:software'); + }); + it('renders link for entity name and hides default kind', () => { const entityName = { kind: 'Component', @@ -121,6 +183,20 @@ describe('humanizeEntityRef', () => { expect(title).toEqual('test/software'); }); + it('renders link for entity name and hides default kind with skipping namespace', () => { + const entityName = { + kind: 'Component', + namespace: 'test', + name: 'software', + }; + + const title = humanizeEntityRef(entityName, { + defaultKind: 'component', + defaultNamespace: 'test', + }); + expect(title).toEqual('software'); + }); + it('formats entity name in default namespace without skip of default namespace', () => { const entityName = { kind: 'Component', @@ -129,7 +205,7 @@ describe('humanizeEntityRef', () => { }; const title = humanizeEntityRef(entityName, { - skipDefaultNamespace: false, + defaultNamespace: 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 bd97ce2548..536b9a3a6e 100644 --- a/plugins/catalog-react/src/components/EntityRefLink/humanize.ts +++ b/plugins/catalog-react/src/components/EntityRefLink/humanize.ts @@ -20,16 +20,19 @@ import { DEFAULT_NAMESPACE, } from '@backstage/catalog-model'; -/** @public */ +/** + * @property defaultNamespace - if set to false then namespace is never ommited, + * if set to string which matches namespace of entity then omited + * + * @public */ export function humanizeEntityRef( entityRef: Entity | CompoundEntityRef, opts?: { defaultKind?: string; - skipDefaultNamespace?: boolean; + defaultNamespace?: string | boolean; }, ) { const defaultKind = opts?.defaultKind; - const skipDefaultNamespace = opts?.skipDefaultNamespace ?? true; let kind; let namespace; let name; @@ -44,7 +47,14 @@ export function humanizeEntityRef( name = entityRef.name; } - if (skipDefaultNamespace === true && namespace === DEFAULT_NAMESPACE) { + if (namespace === undefined || namespace === '') { + namespace = DEFAULT_NAMESPACE; + } + if (opts?.defaultNamespace !== undefined) { + if (opts?.defaultNamespace === namespace) { + namespace = undefined; + } + } else if (namespace === DEFAULT_NAMESPACE) { namespace = undefined; } From 5986fa4f2d77abccaed491b65cbcab16a581f6fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Tunkl?= Date: Thu, 8 Sep 2022 14:11:37 +0200 Subject: [PATCH 5/8] Fix of typo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomáš Tunkl --- .../catalog-react/src/components/EntityRefLink/humanize.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/catalog-react/src/components/EntityRefLink/humanize.ts b/plugins/catalog-react/src/components/EntityRefLink/humanize.ts index 536b9a3a6e..4a53ace1e3 100644 --- a/plugins/catalog-react/src/components/EntityRefLink/humanize.ts +++ b/plugins/catalog-react/src/components/EntityRefLink/humanize.ts @@ -21,8 +21,8 @@ import { } from '@backstage/catalog-model'; /** - * @property defaultNamespace - if set to false then namespace is never ommited, - * if set to string which matches namespace of entity then omited + * @property defaultNamespace - if set to false then namespace is never omitted, + * if set to string which matches namespace of entity then omitted * * @public */ export function humanizeEntityRef( From 978d691ed2b5adfafdf9e3dad659f4f4c2d07349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Tunkl?= Date: Fri, 9 Sep 2022 09:53:09 +0200 Subject: [PATCH 6/8] Update of api-report.md after change of humanize public api MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomáš Tunkl --- plugins/catalog-react/api-report.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/catalog-react/api-report.md b/plugins/catalog-react/api-report.md index 5232c49150..a5567aa9c8 100644 --- a/plugins/catalog-react/api-report.md +++ b/plugins/catalog-react/api-report.md @@ -436,11 +436,14 @@ export function getEntitySourceLocation( scmIntegrationsApi: ScmIntegrationRegistry, ): EntitySourceLocation | undefined; -// @public (undocumented) +// Warning: (tsdoc-undefined-tag) The TSDoc tag "@property" is not defined in this configuration +// +// @public export function humanizeEntityRef( entityRef: Entity | CompoundEntityRef, opts?: { defaultKind?: string; + defaultNamespace?: string | boolean; }, ): string; From 007204a8befe871f5de7ce62bd5ffcce820bd68f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Tunkl?= Date: Fri, 9 Sep 2022 11:03:30 +0200 Subject: [PATCH 7/8] Update of api-report.md and humanize documentation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomáš Tunkl --- plugins/catalog-react/api-report.md | 4 +--- .../catalog-react/src/components/EntityRefLink/humanize.ts | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/catalog-react/api-report.md b/plugins/catalog-react/api-report.md index a5567aa9c8..b2b098ec68 100644 --- a/plugins/catalog-react/api-report.md +++ b/plugins/catalog-react/api-report.md @@ -436,9 +436,7 @@ export function getEntitySourceLocation( scmIntegrationsApi: ScmIntegrationRegistry, ): EntitySourceLocation | undefined; -// Warning: (tsdoc-undefined-tag) The TSDoc tag "@property" is not defined in this configuration -// -// @public +// @public (undocumented) export function humanizeEntityRef( entityRef: Entity | CompoundEntityRef, opts?: { diff --git a/plugins/catalog-react/src/components/EntityRefLink/humanize.ts b/plugins/catalog-react/src/components/EntityRefLink/humanize.ts index 4a53ace1e3..358b6a5851 100644 --- a/plugins/catalog-react/src/components/EntityRefLink/humanize.ts +++ b/plugins/catalog-react/src/components/EntityRefLink/humanize.ts @@ -21,7 +21,7 @@ import { } from '@backstage/catalog-model'; /** - * @property defaultNamespace - if set to false then namespace is never omitted, + * @param defaultNamespace - if set to false then namespace is never omitted, * if set to string which matches namespace of entity then omitted * * @public */ From d9ab14d04cfa73e14882d50fe95c95e92e31c4d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Tunkl?= Date: Mon, 12 Sep 2022 14:05:34 +0200 Subject: [PATCH 8/8] Update of humanize method parameters type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomáš Tunkl --- plugins/catalog-react/api-report.md | 2 +- plugins/catalog-react/src/components/EntityRefLink/humanize.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/catalog-react/api-report.md b/plugins/catalog-react/api-report.md index b2b098ec68..f6ead9a31a 100644 --- a/plugins/catalog-react/api-report.md +++ b/plugins/catalog-react/api-report.md @@ -441,7 +441,7 @@ export function humanizeEntityRef( entityRef: Entity | CompoundEntityRef, opts?: { defaultKind?: string; - defaultNamespace?: string | boolean; + defaultNamespace?: string | false; }, ): string; diff --git a/plugins/catalog-react/src/components/EntityRefLink/humanize.ts b/plugins/catalog-react/src/components/EntityRefLink/humanize.ts index 358b6a5851..bfc8e2af84 100644 --- a/plugins/catalog-react/src/components/EntityRefLink/humanize.ts +++ b/plugins/catalog-react/src/components/EntityRefLink/humanize.ts @@ -29,7 +29,7 @@ export function humanizeEntityRef( entityRef: Entity | CompoundEntityRef, opts?: { defaultKind?: string; - defaultNamespace?: string | boolean; + defaultNamespace?: string | false; }, ) { const defaultKind = opts?.defaultKind;