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) {