Support extending KubernetesCluster in extensions

Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
This commit is contained in:
Panu Horsmalahti committed 2022-01-18 14:51:24 +02:00
1 parent 3d87d67165
commit 1ee5e32738
3 files changed
+10 -5

No files matched your search

@@ -60,7 +60,7 @@ export interface KubernetesClusterStatus extends CatalogEntityStatus {
export class KubernetesCluster extends CatalogEntity<KubernetesClusterMetadata, KubernetesClusterStatus, KubernetesClusterSpec> { export class KubernetesCluster extends CatalogEntity<KubernetesClusterMetadata, KubernetesClusterStatus, KubernetesClusterSpec> {
public static readonly apiVersion = "entity.k8slens.dev/v1alpha1"; public static readonly apiVersion = "entity.k8slens.dev/v1alpha1";
public static readonly kind = "KubernetesCluster"; public static readonly kind: string = "KubernetesCluster";
public readonly apiVersion = KubernetesCluster.apiVersion; public readonly apiVersion = KubernetesCluster.apiVersion;
public readonly kind = KubernetesCluster.kind; public readonly kind = KubernetesCluster.kind;
+7 -3
View File
@@ -4,7 +4,7 @@
*/ */
import { action, computed, IComputedValue, IObservableArray, makeObservable, observable } from "mobx"; import { action, computed, IComputedValue, IObservableArray, makeObservable, observable } from "mobx";
import { CatalogCategoryRegistry, catalogCategoryRegistry, CatalogEntity, CatalogEntityConstructor, CatalogEntityKindData } from "../../common/catalog"; import { CatalogCategoryRegistry, catalogCategoryRegistry, CatalogEntity, CatalogEntityConstructor } from "../../common/catalog";
import { iter } from "../../common/utils"; import { iter } from "../../common/utils";
export class CatalogEntityRegistry { export class CatalogEntityRegistry {
@@ -43,8 +43,12 @@ export class CatalogEntityRegistry {
return this.items.filter((item) => item.apiVersion === apiVersion && item.kind === kind) as T[]; return this.items.filter((item) => item.apiVersion === apiVersion && item.kind === kind) as T[];
} }
getItemsByEntityClass<T extends CatalogEntity>({ apiVersion, kind }: CatalogEntityKindData & CatalogEntityConstructor<T>): T[] { getItemsOfType<T extends CatalogEntity>(Constructor: CatalogEntityConstructor<T>): T[] {
return this.getItemsForApiKind(apiVersion, kind); return this.items.filter((item) => item instanceof Constructor) as T[];
}
getItemsByEntityClass<T extends CatalogEntity>(constructor: CatalogEntityConstructor<T>): T[] {
return this.getItemsOfType(constructor);
} }
} }
@@ -49,7 +49,8 @@ export const initClusterFrame =
// Only load the extensions once the catalog has been populated // Only load the extensions once the catalog has been populated
when( when(
() => Boolean(catalogEntityRegistry.activeEntity), // watch for .items, as .activeEntity might be populated only after extensions are loaded (if using custom Catalog Category)
() => catalogEntityRegistry.items.length > 0,
() => () =>
loadExtensions(catalogEntityRegistry.activeEntity as KubernetesCluster), loadExtensions(catalogEntityRegistry.activeEntity as KubernetesCluster),
{ {