From 86ee5f2ed84e01eb80f71670ddd3f0dca94d76e6 Mon Sep 17 00:00:00 2001 From: albertojuanL Date: Mon, 6 Feb 2023 19:38:58 +0100 Subject: [PATCH] Use title when exits or humanitizeEntityRef for the default catalog entities sorting Signed-off-by: albertojuanL --- .../components/CatalogTable/CatalogTable.tsx | 30 +++++-------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx b/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx index e6f9d1458e..8cee912219 100644 --- a/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx +++ b/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx @@ -16,7 +16,6 @@ import { ANNOTATION_EDIT_URL, ANNOTATION_VIEW_URL, - DEFAULT_NAMESPACE, Entity, RELATION_OWNED_BY, RELATION_PART_OF, @@ -64,29 +63,16 @@ const YellowStar = withStyles({ }, })(Star); -const 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')}`; -}; - const refCompare = (a: Entity, b: Entity) => { - // in case field filtering is used, these fields might not be part of the response - if ( - a.metadata?.name === undefined || - a.kind === undefined || - b.metadata?.name === undefined || - b.kind === undefined - ) { - return 0; - } + const toRef = (entity: Entity) => + entity.metadata.title?.toLocaleLowerCase('en-US') || + humanizeEntityRef(entity, { + defaultKind: 'Component', + }); + + const aRef = toRef(a); + const bRef = toRef(b); - const aRef = stringifySortingEntityRef(a); - const bRef = stringifySortingEntityRef(b); if (aRef < bRef) { return -1; }