mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
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:
1 parent
7981e79cbd
commit
6fdb2f0b58
8 files changed
+192
-27
No files matched your search
@@ -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[] {
|
||||
|
||||
Reference in new issue
Block a user