From 269d20a078572e3840f30d6b697085f2c176e984 Mon Sep 17 00:00:00 2001 From: Andre Wanlin <67169551+awanlin@users.noreply.github.com> Date: Tue, 21 Jun 2022 16:35:04 -0500 Subject: [PATCH] Refactored based on PR feedback Signed-off-by: Andre Wanlin <67169551+awanlin@users.noreply.github.com> --- plugins/catalog-react/api-report.md | 8 ++++---- .../EntityAdvancedPicker.test.tsx | 4 ++-- .../EntityAdvancedPicker/EntityAdvancedPicker.tsx | 12 ++++++------ plugins/catalog-react/src/filters.test.ts | 4 ++-- plugins/catalog-react/src/filters.ts | 8 ++++---- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/plugins/catalog-react/api-report.md b/plugins/catalog-react/api-report.md index 7f3d7a5f3c..61c1eb4592 100644 --- a/plugins/catalog-react/api-report.md +++ b/plugins/catalog-react/api-report.md @@ -150,11 +150,11 @@ export const EntityAdvancedPicker: () => JSX.Element; // @public export class EntityErrorFilter implements EntityFilter { - constructor(values: string[]); + constructor(value: boolean); // (undocumented) filterEntity(entity: Entity): boolean; // (undocumented) - readonly values: string[]; + readonly value: boolean; } // @public (undocumented) @@ -242,11 +242,11 @@ export type EntityLoadingStatus = { // @public export class EntityOrphanFilter implements EntityFilter { - constructor(values: string[]); + constructor(value: boolean); // (undocumented) filterEntity(entity: Entity): boolean; // (undocumented) - readonly values: string[]; + readonly value: boolean; } // @public diff --git a/plugins/catalog-react/src/components/EntityAdvancedPicker/EntityAdvancedPicker.test.tsx b/plugins/catalog-react/src/components/EntityAdvancedPicker/EntityAdvancedPicker.test.tsx index 8964038d42..c139c66505 100644 --- a/plugins/catalog-react/src/components/EntityAdvancedPicker/EntityAdvancedPicker.test.tsx +++ b/plugins/catalog-react/src/components/EntityAdvancedPicker/EntityAdvancedPicker.test.tsx @@ -83,7 +83,7 @@ describe('', () => { fireEvent.click(rendered.getByTestId('advanced-picker-expand')); fireEvent.click(rendered.getByText('Is Orphan')); expect(updateFilters).toHaveBeenCalledWith({ - orphan: new EntityOrphanFilter(['true']), + orphan: new EntityOrphanFilter(true), }); }); @@ -104,7 +104,7 @@ describe('', () => { fireEvent.click(rendered.getByTestId('advanced-picker-expand')); fireEvent.click(rendered.getByText('Has Error')); expect(updateFilters).toHaveBeenCalledWith({ - error: new EntityErrorFilter(['true']), + error: new EntityErrorFilter(true), }); }); diff --git a/plugins/catalog-react/src/components/EntityAdvancedPicker/EntityAdvancedPicker.tsx b/plugins/catalog-react/src/components/EntityAdvancedPicker/EntityAdvancedPicker.tsx index 9a813540f1..e3be9be3c5 100644 --- a/plugins/catalog-react/src/components/EntityAdvancedPicker/EntityAdvancedPicker.tsx +++ b/plugins/catalog-react/src/components/EntityAdvancedPicker/EntityAdvancedPicker.tsx @@ -54,15 +54,15 @@ export const EntityAdvancedPicker = () => { [], ); - function orphanChange(value: string) { + function orphanChange(value: boolean) { updateFilters({ - orphan: value === 'true' ? new EntityOrphanFilter([value]) : undefined, + orphan: value ? new EntityOrphanFilter(value) : undefined, }); } - function errorChange(value: string) { + function errorChange(value: boolean) { updateFilters({ - error: value === 'true' ? new EntityErrorFilter([value]) : undefined, + error: value ? new EntityErrorFilter(value) : undefined, }); } @@ -78,8 +78,8 @@ export const EntityAdvancedPicker = () => { value={selectedAdvancedItems} onChange={(_: object, value: string[]) => { setSelectedAdvancedItems(value); - orphanChange(value.includes('Is Orphan') ? 'true' : 'false'); - errorChange(value.includes('Has Error') ? 'true' : 'false'); + orphanChange(value.includes('Is Orphan')); + errorChange(value.includes('Has Error')); }} renderOption={(option, { selected }) => ( { }; it('should find orphans', () => { - const filter = new EntityOrphanFilter(['true']); + const filter = new EntityOrphanFilter(true); expect(filter.filterEntity(orphan)).toBeTruthy(); expect(filter.filterEntity(entities[1])).toBeFalsy(); }); @@ -137,7 +137,7 @@ describe('EntityErrorFilter', () => { }; it('should find errors', () => { - const filter = new EntityErrorFilter(['true']); + const filter = new EntityErrorFilter(true); expect(filter.filterEntity(error)).toBeTruthy(); expect(filter.filterEntity(entities[1])).toBeFalsy(); }); diff --git a/plugins/catalog-react/src/filters.ts b/plugins/catalog-react/src/filters.ts index efd23552e9..a828015f0e 100644 --- a/plugins/catalog-react/src/filters.ts +++ b/plugins/catalog-react/src/filters.ts @@ -169,10 +169,10 @@ export class UserListFilter implements EntityFilter { * @public */ export class EntityOrphanFilter implements EntityFilter { - constructor(readonly values: string[]) {} + constructor(readonly value: boolean) {} filterEntity(entity: Entity): boolean { const orphan = entity.metadata.annotations?.['backstage.io/orphan']; - return orphan !== undefined && this.values.includes(orphan); + return orphan !== undefined && this.value.toString() === orphan; } } @@ -181,10 +181,10 @@ export class EntityOrphanFilter implements EntityFilter { * @public */ export class EntityErrorFilter implements EntityFilter { - constructor(readonly values: string[]) {} + constructor(readonly value: boolean) {} filterEntity(entity: Entity): boolean { const error = ((entity as AlphaEntity)?.status?.items?.length as number) > 0; - return error !== undefined && this.values.includes(error.toString()); + return error !== undefined && this.value === error; } }