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

Fix not emitting bundled extensions are loaded in cluster frame

- Fixes tests that relied on root frame being initialized before cluster frames

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2023-02-24 15:43:45 -05:00
parent 2bff8cc733
commit d2d4ffbe5b

View File

@ -6,10 +6,12 @@ import { getInjectable } from "@ogre-tools/injectable";
import { when } from "mobx"; import { when } from "mobx";
import prefixedLoggerInjectable from "../../../common/logger/prefixed-logger.injectable"; import prefixedLoggerInjectable from "../../../common/logger/prefixed-logger.injectable";
import autoInitExtensionsInjectable from "../../../features/extensions/loader/common/auto-init-extensions.injectable"; import autoInitExtensionsInjectable from "../../../features/extensions/loader/common/auto-init-extensions.injectable";
import sendBundledExtensionsLoadedInjectable from "../../../features/extensions/loader/renderer/send-bundled-extensions-loaded.injectable";
import catalogEntityRegistryInjectable from "../../api/catalog/entity/registry.injectable"; import catalogEntityRegistryInjectable from "../../api/catalog/entity/registry.injectable";
import { beforeClusterFrameStartsSecondInjectionToken } from "../../before-frame-starts/tokens"; import { beforeClusterFrameStartsSecondInjectionToken } from "../../before-frame-starts/tokens";
import clusterFrameClusterInjectable from "../../cluster-frame-context/cluster-frame-cluster.injectable"; import clusterFrameClusterInjectable from "../../cluster-frame-context/cluster-frame-cluster.injectable";
import showErrorNotificationInjectable from "../../components/notifications/show-error-notification.injectable"; import showErrorNotificationInjectable from "../../components/notifications/show-error-notification.injectable";
import { delay, disposer } from "../../utils";
import waitForClusterToFinishActivatingInjectable from "./wait-for-cluster-to-finish-activating.injectable"; import waitForClusterToFinishActivatingInjectable from "./wait-for-cluster-to-finish-activating.injectable";
const loadExtensionsAfterCatalogPopulatesInjectable = getInjectable({ const loadExtensionsAfterCatalogPopulatesInjectable = getInjectable({
@ -22,23 +24,36 @@ const loadExtensionsAfterCatalogPopulatesInjectable = getInjectable({
const autoInitExtensions = di.inject(autoInitExtensionsInjectable); const autoInitExtensions = di.inject(autoInitExtensionsInjectable);
const logger = di.inject(prefixedLoggerInjectable, "CLUSTER-FRAME"); const logger = di.inject(prefixedLoggerInjectable, "CLUSTER-FRAME");
const showErrorNotification = di.inject(showErrorNotificationInjectable); const showErrorNotification = di.inject(showErrorNotificationInjectable);
const sendBundledExtensionsLoaded = di.inject(sendBundledExtensionsLoadedInjectable);
catalogEntityRegistry.activeEntity = cluster.id; catalogEntityRegistry.activeEntity = cluster.id;
void (async () => {
const waitForCatalogEntityToAppear = when(() => catalogEntityRegistry.items.get().length > 0);
const maxWaitingTime = delay(15_000);
const cleanup = disposer(
() => waitForCatalogEntityToAppear.cancel(),
() => maxWaitingTime.cancel(),
);
const entityAppeared = await Promise.race([
waitForCatalogEntityToAppear.then(() => true),
maxWaitingTime.then(() => false),
]);
cleanup();
if (!entityAppeared) {
// Only load the extensions once the catalog has been populated. // Only load the extensions once the catalog has been populated.
// Note that the Catalog might still have unprocessed entities until the extensions are fully loaded. // Note that the Catalog might still have unprocessed entities until the extensions are fully loaded.
when( logger.warn("Failed to get KubernetesCluster before timeout");
() => catalogEntityRegistry.items.get().length > 0,
() =>
autoInitExtensions(),
{
timeout: 15_000,
onError: (error) => {
logger.warn("error from activeEntity when()", error);
showErrorNotification("Failed to get KubernetesCluster for this view. Extensions will not be loaded."); showErrorNotification("Failed to get KubernetesCluster for this view. Extensions will not be loaded.");
}, } else {
}, await autoInitExtensions();
); }
sendBundledExtensionsLoaded();
})();
}, },
runAfter: di.inject(waitForClusterToFinishActivatingInjectable), runAfter: di.inject(waitForClusterToFinishActivatingInjectable),
}), }),