1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Improve entity loading for extension custom types.

Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
This commit is contained in:
Panu Horsmalahti 2022-01-18 14:43:58 +02:00
parent e711b953ed
commit 6965379de1
3 changed files with 21 additions and 5 deletions

View File

@ -270,11 +270,12 @@ export class ExtensionLoader {
});
};
loadOnClusterRenderer = (entity: KubernetesCluster) => {
loadOnClusterRenderer(getCluster: () => KubernetesCluster) {
logger.debug(`${logModule}: load on cluster renderer (dashboard)`);
this.autoInitExtensions(async (extension: LensRendererExtension) => {
if ((await extension.isEnabledForCluster(entity)) === false) {
// getCluster must be a callback, as the entity might be available only after an extension has been loaded
if ((await extension.isEnabledForCluster(getCluster())) === false) {
return [];
}

View File

@ -47,10 +47,25 @@ export class CatalogEntityRegistry {
makeObservable(this);
}
get activeEntity(): CatalogEntity | null {
protected getActiveEntityById() {
return this._entities.get(this.activeEntityId) || null;
}
get activeEntity(): CatalogEntity | null {
const entity = this.getActiveEntityById();
// If the entity was not found but there are rawEntities to be processed,
// try to process them and return the entity.
// This might happen if an extension registered a new Catalog category.
if (this.activeEntityId && !entity && this.rawEntities.length > 0) {
this.processRawEntities();
return this.getActiveEntityById();
}
return entity;
}
set activeEntity(raw: CatalogEntity | string | null) {
if (raw) {
const id = typeof raw === "string"

View File

@ -19,7 +19,7 @@ import { KubeObjectStore } from "../../../../common/k8s-api/kube-object.store";
interface Dependencies {
hostedCluster: Cluster;
loadExtensions: (entity: CatalogEntity) => void;
loadExtensions: (getCluster: () => CatalogEntity) => void;
catalogEntityRegistry: CatalogEntityRegistry;
frameRoutingId: number;
emitEvent: (event: AppEvent) => void;
@ -52,7 +52,7 @@ export const initClusterFrame =
// 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),
{
timeout: 15_000,
onError: (error) => {