Merge pull request #27404 from stephenglass/fix-search-ui-formatting

fix(search): fix collator text formatting for entities without description
This commit is contained in:
Andre Wanlin
2024-11-18 11:36:56 -07:00
committed by GitHub
3 changed files with 37 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-search-backend-module-catalog': patch
---
Fix search collator text formatting for catalog entities without description
@@ -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: '',
});
});
});
});
@@ -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) {