fix catalog search by display name

Signed-off-by: Stephen Glass <stephen@stephen.glass>
This commit is contained in:
Stephen Glass
2024-11-21 17:00:18 -05:00
parent 6571935728
commit f18c67db38
3 changed files with 45 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-react': patch
---
Fix catalog filtering to allow searching entities by display name
+33
View File
@@ -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', () => {
+7
View File
@@ -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) {