From 67dbe016713b457aa3def29ac2439d181a99443b Mon Sep 17 00:00:00 2001 From: Jason Nguyen Date: Fri, 8 Apr 2022 09:26:23 -0600 Subject: [PATCH] catalog-backend: simplify getDocumentText Signed-off-by: Jason Nguyen --- plugins/catalog-backend/src/search/util.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/plugins/catalog-backend/src/search/util.ts b/plugins/catalog-backend/src/search/util.ts index 47a5570899..7e7ce7064e 100644 --- a/plugins/catalog-backend/src/search/util.ts +++ b/plugins/catalog-backend/src/search/util.ts @@ -25,15 +25,13 @@ function isGroupEntity(entity: Entity): entity is UserEntity { } export function getDocumentText(entity: Entity): string { - let documentText = entity.metadata.description || ''; + const documentTexts: string[] = []; + documentTexts.push(entity.metadata.description || ''); + if (isUserEntity(entity) || isGroupEntity(entity)) { - if (entity.spec?.profile?.displayName && documentText) { - // combine displayName and description - const displayName = entity.spec.profile.displayName; - documentText = displayName.concat(' : ', documentText); - } else { - documentText = entity.spec?.profile?.displayName || documentText; + if (entity.spec?.profile?.displayName) { + documentTexts.push(entity.spec.profile.displayName); } } - return documentText; + return documentTexts.join(' : '); }