diff --git a/.changeset/lazy-years-float.md b/.changeset/lazy-years-float.md new file mode 100644 index 0000000000..23bd77a0bb --- /dev/null +++ b/.changeset/lazy-years-float.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-react': patch +--- + +Fix catalog filtering to allow searching entities by display name diff --git a/plugins/catalog-react/src/filters.test.ts b/plugins/catalog-react/src/filters.test.ts index 8ddac7e53b..12ebc4ba04 100644 --- a/plugins/catalog-react/src/filters.test.ts +++ b/plugins/catalog-react/src/filters.test.ts @@ -72,6 +72,33 @@ const templates: TemplateEntityV1beta3[] = [ }, ]; +const users: Entity[] = [ + { + apiVersion: '1', + kind: 'User', + metadata: { + name: 'jd1234', + }, + spec: { + profile: { + displayName: 'DOE, JOHN', + }, + }, + }, + { + apiVersion: '1', + kind: 'User', + metadata: { + name: 'fb3456', + }, + spec: { + profile: { + displayName: 'BAR, FOO', + }, + }, + }, +]; + describe('EntityTextFilter', () => { it('should search name', () => { const filter = new EntityTextFilter('app'); @@ -96,6 +123,12 @@ describe('EntityTextFilter', () => { expect(filter.filterEntity(entities[0])).toBeFalsy(); expect(filter.filterEntity(entities[1])).toBeTruthy(); }); + + it('should search display name', () => { + const filter = new EntityTextFilter('doe'); + expect(filter.filterEntity(users[0])).toBeTruthy(); + expect(filter.filterEntity(users[1])).toBeFalsy(); + }); }); describe('EntityOrphanFilter', () => { diff --git a/plugins/catalog-react/src/filters.ts b/plugins/catalog-react/src/filters.ts index 08be27a561..1bab65ce9a 100644 --- a/plugins/catalog-react/src/filters.ts +++ b/plugins/catalog-react/src/filters.ts @@ -94,6 +94,13 @@ export class EntityTextFilter implements EntityFilter { const partialMatch = this.toUpperArray([ entity.metadata.name, entity.metadata.title, + ...(typeof entity.spec?.profile === 'object' && + entity.spec?.profile !== null && + !Array.isArray(entity.spec.profile) && + 'displayName' in entity.spec.profile && + typeof entity.spec.profile.displayName === 'string' + ? [entity.spec.profile.displayName] + : []), ]); for (const word of words) {