mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Move initClusterFrame around
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
ac6e3e18e2
commit
1058113e90
@ -3,7 +3,7 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import webFrameInjectable from "./web-frame/web-frame.injectable";
|
import webFrameInjectable from "./web-frame.injectable";
|
||||||
|
|
||||||
const frameRoutingIdInjectable = getInjectable({
|
const frameRoutingIdInjectable = getInjectable({
|
||||||
id: "frame-routing-id",
|
id: "frame-routing-id",
|
||||||
@ -12,7 +12,7 @@ import { DiContextProvider } from "@ogre-tools/injectable-react";
|
|||||||
import type { DiContainer } from "@ogre-tools/injectable";
|
import type { DiContainer } from "@ogre-tools/injectable";
|
||||||
import extensionInstallationStateStoreInjectable from "../extensions/extension-installation-state-store/extension-installation-state-store.injectable";
|
import extensionInstallationStateStoreInjectable from "../extensions/extension-installation-state-store/extension-installation-state-store.injectable";
|
||||||
import initRootFrameInjectable from "./frames/root-frame/init-root-frame.injectable";
|
import initRootFrameInjectable from "./frames/root-frame/init-root-frame.injectable";
|
||||||
import initClusterFrameInjectable from "./frames/cluster-frame/init-cluster-frame/init-cluster-frame.injectable";
|
import initClusterFrameInjectable from "./frames/cluster-frame/init-cluster-frame.injectable";
|
||||||
import { Router } from "react-router";
|
import { Router } from "react-router";
|
||||||
import historyInjectable from "./navigation/history.injectable";
|
import historyInjectable from "./navigation/history.injectable";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
|
|||||||
@ -0,0 +1,80 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import catalogEntityRegistryInjectable from "../../api/catalog/entity/registry.injectable";
|
||||||
|
import frameRoutingIdInjectable from "../../../features/electron/renderer/frame-routing-id.injectable";
|
||||||
|
import hostedClusterInjectable from "../../cluster-frame-context/hosted-cluster.injectable";
|
||||||
|
import assert from "assert";
|
||||||
|
import emitAppEventInjectable from "../../../common/app-event-bus/emit-event.injectable";
|
||||||
|
import showErrorNotificationInjectable from "../../components/notifications/show-error-notification.injectable";
|
||||||
|
import autoInitExtensionsInjectable from "../../../features/extensions/loader/common/auto-init-extensions.injectable";
|
||||||
|
import prefixedLoggerInjectable from "../../../common/logger/prefixed-logger.injectable";
|
||||||
|
import { when } from "mobx";
|
||||||
|
import { requestSetClusterFrameId } from "../../ipc";
|
||||||
|
|
||||||
|
const initClusterFrameInjectable = getInjectable({
|
||||||
|
id: "init-cluster-frame",
|
||||||
|
|
||||||
|
instantiate: (di) => {
|
||||||
|
const hostedCluster = di.inject(hostedClusterInjectable);
|
||||||
|
|
||||||
|
assert(hostedCluster, "This can only be injected within a cluster frame");
|
||||||
|
|
||||||
|
const loadExtensions = di.inject(autoInitExtensionsInjectable);
|
||||||
|
const catalogEntityRegistry = di.inject(catalogEntityRegistryInjectable);
|
||||||
|
const frameRoutingId = di.inject(frameRoutingIdInjectable);
|
||||||
|
const emitAppEvent = di.inject(emitAppEventInjectable);
|
||||||
|
const logger = di.inject(prefixedLoggerInjectable, "CLUSTER-FRAME");
|
||||||
|
const showErrorNotification = di.inject(showErrorNotificationInjectable);
|
||||||
|
|
||||||
|
return async (unmountRoot: () => void) => {
|
||||||
|
// TODO: Make catalogEntityRegistry already initialized when passed as dependency
|
||||||
|
catalogEntityRegistry.init();
|
||||||
|
|
||||||
|
logger.info(`Init dashboard, clusterId=${hostedCluster.id}, frameId=${frameRoutingId}`);
|
||||||
|
|
||||||
|
await requestSetClusterFrameId(hostedCluster.id);
|
||||||
|
await hostedCluster.whenReady; // cluster.activate() is done at this point
|
||||||
|
|
||||||
|
catalogEntityRegistry.activeEntity = hostedCluster.id;
|
||||||
|
|
||||||
|
// 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,
|
||||||
|
() =>
|
||||||
|
loadExtensions(),
|
||||||
|
{
|
||||||
|
timeout: 15_000,
|
||||||
|
onError: (error) => {
|
||||||
|
logger.warn(
|
||||||
|
"[CLUSTER-FRAME]: error from activeEntity when()",
|
||||||
|
error,
|
||||||
|
);
|
||||||
|
|
||||||
|
showErrorNotification("Failed to get KubernetesCluster for this view. Extensions will not be loaded.");
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
emitAppEvent({
|
||||||
|
name: "cluster",
|
||||||
|
action: "open",
|
||||||
|
params: {
|
||||||
|
clusterId: hostedCluster.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
window.addEventListener("beforeunload", () => {
|
||||||
|
logger.info(`Unload dashboard, clusterId=${(hostedCluster.id)}, frameId=${frameRoutingId}`);
|
||||||
|
unmountRoot();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default initClusterFrameInjectable;
|
||||||
@ -1,36 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
||||||
*/
|
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
|
||||||
import { initClusterFrame } from "./init-cluster-frame";
|
|
||||||
import catalogEntityRegistryInjectable from "../../../api/catalog/entity/registry.injectable";
|
|
||||||
import frameRoutingIdInjectable from "./frame-routing-id/frame-routing-id.injectable";
|
|
||||||
import hostedClusterInjectable from "../../../cluster-frame-context/hosted-cluster.injectable";
|
|
||||||
import assert from "assert";
|
|
||||||
import emitAppEventInjectable from "../../../../common/app-event-bus/emit-event.injectable";
|
|
||||||
import loggerInjectable from "../../../../common/logger.injectable";
|
|
||||||
import showErrorNotificationInjectable from "../../../components/notifications/show-error-notification.injectable";
|
|
||||||
import autoInitExtensionsInjectable from "../../../../features/extensions/loader/common/auto-init-extensions.injectable";
|
|
||||||
|
|
||||||
const initClusterFrameInjectable = getInjectable({
|
|
||||||
id: "init-cluster-frame",
|
|
||||||
|
|
||||||
instantiate: (di) => {
|
|
||||||
const hostedCluster = di.inject(hostedClusterInjectable);
|
|
||||||
|
|
||||||
assert(hostedCluster, "This can only be injected within a cluster frame");
|
|
||||||
|
|
||||||
return initClusterFrame({
|
|
||||||
hostedCluster,
|
|
||||||
loadExtensions: di.inject(autoInitExtensionsInjectable),
|
|
||||||
catalogEntityRegistry: di.inject(catalogEntityRegistryInjectable),
|
|
||||||
frameRoutingId: di.inject(frameRoutingIdInjectable),
|
|
||||||
emitAppEvent: di.inject(emitAppEventInjectable),
|
|
||||||
logger: di.inject(loggerInjectable),
|
|
||||||
showErrorNotification: di.inject(showErrorNotificationInjectable),
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default initClusterFrameInjectable;
|
|
||||||
@ -1,83 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
||||||
*/
|
|
||||||
import type { Cluster } from "../../../../common/cluster/cluster";
|
|
||||||
import type { CatalogEntityRegistry } from "../../../api/catalog/entity/registry";
|
|
||||||
import type { ShowNotification } from "../../../components/notifications";
|
|
||||||
import { when } from "mobx";
|
|
||||||
import { requestSetClusterFrameId } from "../../../ipc";
|
|
||||||
import type { EmitAppEvent } from "../../../../common/app-event-bus/emit-event.injectable";
|
|
||||||
import type { Logger } from "../../../../common/logger";
|
|
||||||
|
|
||||||
interface Dependencies {
|
|
||||||
hostedCluster: Cluster;
|
|
||||||
loadExtensions: () => void;
|
|
||||||
catalogEntityRegistry: CatalogEntityRegistry;
|
|
||||||
frameRoutingId: number;
|
|
||||||
emitAppEvent: EmitAppEvent;
|
|
||||||
logger: Logger;
|
|
||||||
showErrorNotification: ShowNotification;
|
|
||||||
}
|
|
||||||
|
|
||||||
const logPrefix = "[CLUSTER-FRAME]:";
|
|
||||||
|
|
||||||
export const initClusterFrame = ({
|
|
||||||
hostedCluster,
|
|
||||||
loadExtensions,
|
|
||||||
catalogEntityRegistry,
|
|
||||||
frameRoutingId,
|
|
||||||
emitAppEvent,
|
|
||||||
logger,
|
|
||||||
showErrorNotification,
|
|
||||||
}: Dependencies) =>
|
|
||||||
async (unmountRoot: () => void) => {
|
|
||||||
// TODO: Make catalogEntityRegistry already initialized when passed as dependency
|
|
||||||
catalogEntityRegistry.init();
|
|
||||||
|
|
||||||
logger.info(
|
|
||||||
`${logPrefix} Init dashboard, clusterId=${hostedCluster.id}, frameId=${frameRoutingId}`,
|
|
||||||
);
|
|
||||||
|
|
||||||
await requestSetClusterFrameId(hostedCluster.id);
|
|
||||||
await hostedCluster.whenReady; // cluster.activate() is done at this point
|
|
||||||
|
|
||||||
catalogEntityRegistry.activeEntity = hostedCluster.id;
|
|
||||||
|
|
||||||
// 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,
|
|
||||||
() =>
|
|
||||||
loadExtensions(),
|
|
||||||
{
|
|
||||||
timeout: 15_000,
|
|
||||||
onError: (error) => {
|
|
||||||
logger.warn(
|
|
||||||
"[CLUSTER-FRAME]: error from activeEntity when()",
|
|
||||||
error,
|
|
||||||
);
|
|
||||||
|
|
||||||
showErrorNotification("Failed to get KubernetesCluster for this view. Extensions will not be loaded.");
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
emitAppEvent({
|
|
||||||
name: "cluster",
|
|
||||||
action: "open",
|
|
||||||
params: {
|
|
||||||
clusterId: hostedCluster.id,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
window.onbeforeunload = () => {
|
|
||||||
logger.info(
|
|
||||||
`${logPrefix} Unload dashboard, clusterId=${(hostedCluster.id)}, frameId=${frameRoutingId}`,
|
|
||||||
);
|
|
||||||
|
|
||||||
unmountRoot();
|
|
||||||
};
|
|
||||||
};
|
|
||||||
Loading…
Reference in New Issue
Block a user