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:
parent
2bff8cc733
commit
d2d4ffbe5b
@ -6,10 +6,12 @@ import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { when } from "mobx";
|
||||
import prefixedLoggerInjectable from "../../../common/logger/prefixed-logger.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 { beforeClusterFrameStartsSecondInjectionToken } from "../../before-frame-starts/tokens";
|
||||
import clusterFrameClusterInjectable from "../../cluster-frame-context/cluster-frame-cluster.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";
|
||||
|
||||
const loadExtensionsAfterCatalogPopulatesInjectable = getInjectable({
|
||||
@ -22,23 +24,36 @@ const loadExtensionsAfterCatalogPopulatesInjectable = getInjectable({
|
||||
const autoInitExtensions = di.inject(autoInitExtensionsInjectable);
|
||||
const logger = di.inject(prefixedLoggerInjectable, "CLUSTER-FRAME");
|
||||
const showErrorNotification = di.inject(showErrorNotificationInjectable);
|
||||
const sendBundledExtensionsLoaded = di.inject(sendBundledExtensionsLoadedInjectable);
|
||||
|
||||
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.
|
||||
// Note that the Catalog might still have unprocessed entities until the extensions are fully loaded.
|
||||
when(
|
||||
() => catalogEntityRegistry.items.get().length > 0,
|
||||
() =>
|
||||
autoInitExtensions(),
|
||||
{
|
||||
timeout: 15_000,
|
||||
onError: (error) => {
|
||||
logger.warn("error from activeEntity when()", error);
|
||||
logger.warn("Failed to get KubernetesCluster before timeout");
|
||||
showErrorNotification("Failed to get KubernetesCluster for this view. Extensions will not be loaded.");
|
||||
},
|
||||
},
|
||||
);
|
||||
} else {
|
||||
await autoInitExtensions();
|
||||
}
|
||||
|
||||
sendBundledExtensionsLoaded();
|
||||
})();
|
||||
},
|
||||
runAfter: di.inject(waitForClusterToFinishActivatingInjectable),
|
||||
}),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user