From 1a1e2f431618513ad7cd766a1fc3dde6889361fb Mon Sep 17 00:00:00 2001 From: Stephen Glass Date: Wed, 30 Oct 2024 18:41:21 -0400 Subject: [PATCH] fix collator text formatting for entities without description Signed-off-by: Stephen Glass --- .changeset/three-parrots-dress.md | 5 ++++ ...ltCatalogCollatorEntityTransformer.test.ts | 29 +++++++++++++++++++ ...defaultCatalogCollatorEntityTransformer.ts | 4 ++- 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 .changeset/three-parrots-dress.md diff --git a/.changeset/three-parrots-dress.md b/.changeset/three-parrots-dress.md new file mode 100644 index 0000000000..836abbf21c --- /dev/null +++ b/.changeset/three-parrots-dress.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-search-backend-module-catalog': patch +--- + +Fix search collator text formatting for catalog entities without description diff --git a/plugins/search-backend-module-catalog/src/collators/defaultCatalogCollatorEntityTransformer.test.ts b/plugins/search-backend-module-catalog/src/collators/defaultCatalogCollatorEntityTransformer.test.ts index 3fe6a9c3e5..b0b7465f5b 100644 --- a/plugins/search-backend-module-catalog/src/collators/defaultCatalogCollatorEntityTransformer.test.ts +++ b/plugins/search-backend-module-catalog/src/collators/defaultCatalogCollatorEntityTransformer.test.ts @@ -147,5 +147,34 @@ describe('DefaultCatalogCollatorEntityTransformer', () => { owner: '', }); }); + + it('sets text correctly when description is not provided', async () => { + const userEntityWithoutDescription = { + ...userEntity, + metadata: { + ...userEntity.metadata, + description: undefined, + }, + spec: { + profile: { + ...userEntity.spec.profile, + email: undefined, + }, + }, + }; + + const document = defaultCatalogCollatorEntityTransformer( + userEntityWithoutDescription, + ); + + expect(document).toMatchObject({ + title: userEntity.metadata.name, + text: userEntity.spec.profile.displayName, + namespace: 'default', + componentType: 'other', + lifecycle: '', + owner: '', + }); + }); }); }); diff --git a/plugins/search-backend-module-catalog/src/collators/defaultCatalogCollatorEntityTransformer.ts b/plugins/search-backend-module-catalog/src/collators/defaultCatalogCollatorEntityTransformer.ts index db239b8669..8acc3e24b8 100644 --- a/plugins/search-backend-module-catalog/src/collators/defaultCatalogCollatorEntityTransformer.ts +++ b/plugins/search-backend-module-catalog/src/collators/defaultCatalogCollatorEntityTransformer.ts @@ -19,7 +19,9 @@ import { CatalogCollatorEntityTransformer } from './CatalogCollatorEntityTransfo const getDocumentText = (entity: Entity): string => { const documentTexts: string[] = []; - documentTexts.push(entity.metadata.description || ''); + if (entity.metadata.description) { + documentTexts.push(entity.metadata.description); + } if (isUserEntity(entity) || isGroupEntity(entity)) { if (entity.spec?.profile?.displayName) {