Support filtering catalog entities (#3647)

* Support filtering catalog entities

- This allows extensions and OpenLens to restrict which of the entities
  the sources have provied are "visible" to the rest of Lens

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix lint

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* switch to filtering only for catalog view

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix test

Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>

* Add test to iter reduce

Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>

Co-authored-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
This commit is contained in:
Sebastian MaltonandPanu Horsmalahti authored and GitHub committed 2021-08-31 16:00:56 +03:00
1 parent 7981e79cbd
commit 6fdb2f0b58
8 files changed
+192 -27

No files matched your search

+8 -12
View File
@@ -43,24 +43,20 @@ export class CatalogEntityRegistry {
}
@computed get items(): CatalogEntity[] {
const allItems = Array.from(iter.flatMap(this.sources.values(), source => source.get()));
return allItems.filter((entity) => this.categoryRegistry.getCategoryForEntity(entity) !== undefined);
return Array.from(
iter.filter(
iter.flatMap(this.sources.values(), source => source.get()),
entity => this.categoryRegistry.getCategoryForEntity(entity)
)
);
}
getById<T extends CatalogEntity>(id: string): T | undefined {
const item = this.items.find((entity) => entity.metadata.uid === id);
if (item) return item as T;
return undefined;
return this.items.find((entity) => entity.metadata.uid === id) as T | undefined;
}
getItemsForApiKind<T extends CatalogEntity>(apiVersion: string, kind: string): T[] {
const items = this.items.filter((item) => item.apiVersion === apiVersion && item.kind === kind);
return items as T[];
return this.items.filter((item) => item.apiVersion === apiVersion && item.kind === kind) as T[];
}
getItemsByEntityClass<T extends CatalogEntity>({ apiVersion, kind }: CatalogEntityKindData): T[] {