Adds possibility to not skip default namespace

Signed-off-by: Tomáš Tunkl <tomas.tunkl@avast.com>
This commit is contained in:
Tomáš Tunkl
2022-08-05 15:20:07 +02:00
parent 84ad48160a
commit 2510b64185
2 changed files with 34 additions and 2 deletions
@@ -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');
});
});
@@ -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;
}