Use title instead of name when it exists, to sort the list of entities by default

Signed-off-by: albertojuanL <alberto.juan@lansweeper.com>
This commit is contained in:
albertojuanL
2023-02-04 14:13:24 +01:00
parent 50d7039368
commit 9ec79c9737
+13 -2
View File
@@ -20,6 +20,7 @@ import {
parseEntityRef,
stringifyEntityRef,
stringifyLocationRef,
DEFAULT_NAMESPACE,
} from '@backstage/catalog-model';
import { ResponseError } from '@backstage/errors';
import crossFetch from 'cross-fetch';
@@ -176,8 +177,8 @@ export class CatalogClient implements CatalogApi {
return 0;
}
const aRef = stringifyEntityRef(a);
const bRef = stringifyEntityRef(b);
const aRef = this.stringifySortingEntityRef(a);
const bRef = this.stringifySortingEntityRef(b);
if (aRef < bRef) {
return -1;
}
@@ -504,4 +505,14 @@ export class CatalogClient implements CatalogApi {
return await response.json();
}
private stringifySortingEntityRef(ref: Entity): string {
const kind = ref.kind;
const namespace = ref.metadata.namespace ?? DEFAULT_NAMESPACE;
const name = ref.metadata.title || ref.metadata.name;
return `${kind.toLocaleLowerCase('en-US')}:${namespace.toLocaleLowerCase(
'en-US',
)}/${name.toLocaleLowerCase('en-US')}`;
}
}