1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/renderer/components/cluster-manager/cluster-view.tsx
Roman a78d5a0fb9 cluster-view battling -- part 1 (iframe failing support nodeintegration)
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
2020-08-18 11:50:54 +03:00

58 lines
1.7 KiB
TypeScript

import "./cluster-view.scss"
import React from "react";
import { WebviewTag } from "electron"
import { autorun, computed, observable } from "mobx";
import { disposeOnUnmount, observer } from "mobx-react";
import { ClusterId, clusterStore } from "../../../common/cluster-store";
import { getMatchedClusterId } from "./cluster-view.route";
import { Cluster } from "../../../main/cluster";
import { ClusterStatus } from "./cluster-status";
@observer
export class ClusterView extends React.Component {
static views = observable.map<ClusterId, WebviewTag>()
static isLoaded = observable.map<ClusterId, boolean>()
@computed get cluster() {
return clusterStore.getById(getMatchedClusterId())
}
@computed get clusterView() {
return ClusterView.views.get(this.cluster?.id)
}
componentDidMount() {
disposeOnUnmount(this, [
autorun(() => this.activateView(this.cluster))
])
}
// fixme
activateView = (cluster: Cluster) => {
if (!cluster || ClusterView.views.has(cluster.id)) {
return;
}
const view = document.createElement("webview");
view.className = "ClusterView"
view.setAttribute("nodeintegration", "true")
view.setAttribute("enableremotemodule", "true")
view.addEventListener("did-finish-load", () => {
console.log('CLUSTER VIEW READY!', cluster)
view.openDevTools()
});
view.addEventListener("did-fail-load", event => {
// todo: handle
});
view.src = `${location.protocol}//${cluster.id}.${location.host}`
document.body.appendChild(view);
ClusterView.views.set(cluster.id, view);
}
render() {
const { cluster } = this;
if (cluster) {
return <ClusterStatus clusterId={cluster.id}/>
}
}
}