mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Make Inject-component usable in both LensApp and "App"
Note: this will need some rehaul, as current design with "bootstrap" and iframe make single root for injectables somewhat challenging. Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
c4c4bc5845
commit
3bc01dc50f
@ -50,6 +50,9 @@ import { SentryInit } from "../common/sentry";
|
||||
import { TerminalStore } from "./components/dock/terminal.store";
|
||||
import { AppPaths } from "../common/app-paths";
|
||||
import { registerCustomThemes } from "./components/monaco-editor";
|
||||
import { getDi } from "./components/getDi";
|
||||
import { DiContextProvider } from "@ogre-tools/injectable-react";
|
||||
import type { IDependencyInjectionContainer } from "@ogre-tools/injectable";
|
||||
|
||||
if (process.isMainFrame) {
|
||||
SentryInit();
|
||||
@ -73,7 +76,7 @@ type AppComponent = React.ComponentType & {
|
||||
init(rootElem: HTMLElement): Promise<void>;
|
||||
};
|
||||
|
||||
export async function bootstrap(comp: () => Promise<AppComponent>) {
|
||||
export async function bootstrap(comp: () => Promise<AppComponent>, di: IDependencyInjectionContainer) {
|
||||
const rootElem = document.getElementById("app");
|
||||
const logPrefix = `[BOOTSTRAP-${process.isMainFrame ? "ROOT" : "CLUSTER"}-FRAME]:`;
|
||||
|
||||
@ -147,17 +150,26 @@ export async function bootstrap(comp: () => Promise<AppComponent>) {
|
||||
|
||||
await App.init(rootElem);
|
||||
|
||||
render(<>
|
||||
{isMac && <div id="draggable-top" />}
|
||||
{DefaultProps(App)}
|
||||
</>, rootElem);
|
||||
render(
|
||||
<DiContextProvider value={{ di }}>
|
||||
{isMac && <div id="draggable-top" />}
|
||||
|
||||
{DefaultProps(App)}
|
||||
</DiContextProvider>,
|
||||
|
||||
rootElem,
|
||||
);
|
||||
}
|
||||
|
||||
const di = getDi();
|
||||
|
||||
// run
|
||||
bootstrap(
|
||||
async () => process.isMainFrame
|
||||
? (await import("./root-frame")).RootFrame
|
||||
: (await import("./cluster-frame")).ClusterFrame,
|
||||
async () =>
|
||||
process.isMainFrame
|
||||
? (await import("./root-frame")).RootFrame
|
||||
: (await import("./cluster-frame")).ClusterFrame,
|
||||
di,
|
||||
);
|
||||
|
||||
|
||||
|
||||
@ -22,7 +22,6 @@ import React from "react";
|
||||
import { observable, makeObservable } from "mobx";
|
||||
import { disposeOnUnmount, observer } from "mobx-react";
|
||||
import { Redirect, Route, Router, Switch } from "react-router";
|
||||
import { DiContextProvider } from "@ogre-tools/injectable-react";
|
||||
import { history } from "./navigation";
|
||||
import { NotFound } from "./components/+404";
|
||||
import { UserManagement } from "./components/+user-management/user-management";
|
||||
@ -74,14 +73,12 @@ import { watchHistoryState } from "./remote-helpers/history-updater";
|
||||
import { unmountComponentAtNode } from "react-dom";
|
||||
import { PortForwardDialog } from "./port-forward";
|
||||
import { DeleteClusterDialog } from "./components/delete-cluster-dialog";
|
||||
import { getDi } from "./components/getDi";
|
||||
|
||||
@observer
|
||||
export class ClusterFrame extends React.Component {
|
||||
static clusterId: ClusterId;
|
||||
static readonly logPrefix = "[CLUSTER-FRAME]:";
|
||||
static displayName = "ClusterFrame";
|
||||
diContainer = getDi();
|
||||
|
||||
constructor(props: {}) {
|
||||
super(props);
|
||||
@ -196,42 +193,40 @@ export class ClusterFrame extends React.Component {
|
||||
|
||||
render() {
|
||||
return (
|
||||
<DiContextProvider value={{ di: this.diContainer }}>
|
||||
<Router history={history}>
|
||||
<ErrorBoundary>
|
||||
<MainLayout sidebar={<Sidebar/>} footer={<Dock/>}>
|
||||
<Switch>
|
||||
<Route component={ClusterOverview} {...routes.clusterRoute}/>
|
||||
<Route component={Nodes} {...routes.nodesRoute}/>
|
||||
<Route component={Workloads} {...routes.workloadsRoute}/>
|
||||
<Route component={Config} {...routes.configRoute}/>
|
||||
<Route component={Network} {...routes.networkRoute}/>
|
||||
<Route component={Storage} {...routes.storageRoute}/>
|
||||
<Route component={Namespaces} {...routes.namespacesRoute}/>
|
||||
<Route component={Events} {...routes.eventRoute}/>
|
||||
<Route component={CustomResources} {...routes.crdRoute}/>
|
||||
<Route component={UserManagement} {...routes.usersManagementRoute}/>
|
||||
<Route component={Apps} {...routes.appsRoute}/>
|
||||
{this.renderExtensionTabLayoutRoutes()}
|
||||
{this.renderExtensionRoutes()}
|
||||
<Redirect exact from="/" to={this.startUrl}/>
|
||||
<Route component={NotFound}/>
|
||||
</Switch>
|
||||
</MainLayout>
|
||||
<Notifications/>
|
||||
<ConfirmDialog/>
|
||||
<KubeObjectDetails/>
|
||||
<KubeConfigDialog/>
|
||||
<DeploymentScaleDialog/>
|
||||
<StatefulSetScaleDialog/>
|
||||
<ReplicaSetScaleDialog/>
|
||||
<CronJobTriggerDialog/>
|
||||
<PortForwardDialog/>
|
||||
<DeleteClusterDialog/>
|
||||
<CommandContainer clusterId={ClusterFrame.clusterId}/>
|
||||
</ErrorBoundary>
|
||||
</Router>
|
||||
</DiContextProvider>
|
||||
<Router history={history}>
|
||||
<ErrorBoundary>
|
||||
<MainLayout sidebar={<Sidebar/>} footer={<Dock/>}>
|
||||
<Switch>
|
||||
<Route component={ClusterOverview} {...routes.clusterRoute}/>
|
||||
<Route component={Nodes} {...routes.nodesRoute}/>
|
||||
<Route component={Workloads} {...routes.workloadsRoute}/>
|
||||
<Route component={Config} {...routes.configRoute}/>
|
||||
<Route component={Network} {...routes.networkRoute}/>
|
||||
<Route component={Storage} {...routes.storageRoute}/>
|
||||
<Route component={Namespaces} {...routes.namespacesRoute}/>
|
||||
<Route component={Events} {...routes.eventRoute}/>
|
||||
<Route component={CustomResources} {...routes.crdRoute}/>
|
||||
<Route component={UserManagement} {...routes.usersManagementRoute}/>
|
||||
<Route component={Apps} {...routes.appsRoute}/>
|
||||
{this.renderExtensionTabLayoutRoutes()}
|
||||
{this.renderExtensionRoutes()}
|
||||
<Redirect exact from="/" to={this.startUrl}/>
|
||||
<Route component={NotFound}/>
|
||||
</Switch>
|
||||
</MainLayout>
|
||||
<Notifications/>
|
||||
<ConfirmDialog/>
|
||||
<KubeObjectDetails/>
|
||||
<KubeConfigDialog/>
|
||||
<DeploymentScaleDialog/>
|
||||
<StatefulSetScaleDialog/>
|
||||
<ReplicaSetScaleDialog/>
|
||||
<CronJobTriggerDialog/>
|
||||
<PortForwardDialog/>
|
||||
<DeleteClusterDialog/>
|
||||
<CommandContainer clusterId={ClusterFrame.clusterId}/>
|
||||
</ErrorBoundary>
|
||||
</Router>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user