Refactored based on PR feedback
Signed-off-by: Andre Wanlin <67169551+awanlin@users.noreply.github.com>
This commit is contained in:
@@ -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<TEntity extends Entity = Entity> = {
|
||||
|
||||
// @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
|
||||
|
||||
+2
-2
@@ -83,7 +83,7 @@ describe('<EntityAdvancedPicker/>', () => {
|
||||
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('<EntityAdvancedPicker/>', () => {
|
||||
fireEvent.click(rendered.getByTestId('advanced-picker-expand'));
|
||||
fireEvent.click(rendered.getByText('Has Error'));
|
||||
expect(updateFilters).toHaveBeenCalledWith({
|
||||
error: new EntityErrorFilter(['true']),
|
||||
error: new EntityErrorFilter(true),
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -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 }) => (
|
||||
<FormControlLabel
|
||||
|
||||
@@ -110,7 +110,7 @@ describe('EntityOrphanFilter', () => {
|
||||
};
|
||||
|
||||
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();
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user