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

cluster-view more fixes & UX optimizations

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2020-08-10 15:59:33 +03:00
parent 402d07d8e5
commit a34da5a5c6
2 changed files with 27 additions and 30 deletions

View File

@ -1,7 +1,11 @@
import "./cluster-manager.scss" import "./cluster-manager.scss"
import React from "react"; import React from "react";
import { WebviewTag } from "electron";
import { Redirect, Route, Switch } from "react-router"; import { Redirect, Route, Switch } from "react-router";
import { observable, reaction } from "mobx";
import { disposeOnUnmount, observer } from "mobx-react"; import { disposeOnUnmount, observer } from "mobx-react";
import { clusterIpc } from "../../../common/cluster-ipc";
import { cssNames } from "../../utils";
import { ClustersMenu } from "./clusters-menu"; import { ClustersMenu } from "./clusters-menu";
import { BottomBar } from "./bottom-bar"; import { BottomBar } from "./bottom-bar";
import { LandingPage, landingRoute, landingURL } from "../+landing-page"; import { LandingPage, landingRoute, landingURL } from "../+landing-page";
@ -9,16 +13,9 @@ import { Preferences, preferencesRoute } from "../+preferences";
import { Workspaces, workspacesRoute } from "../+workspaces"; import { Workspaces, workspacesRoute } from "../+workspaces";
import { AddCluster, addClusterRoute } from "../+add-cluster"; import { AddCluster, addClusterRoute } from "../+add-cluster";
import { ClusterView } from "./cluster-view"; import { ClusterView } from "./cluster-view";
import { clusterViewRoute, clusterViewURL, getMatchedCluster } from "./cluster-view.route"; import { clusterViewRoute, clusterViewURL, getMatchedCluster, getMatchedClusterId } from "./cluster-view.route";
import { ClusterId, clusterStore } from "../../../common/cluster-store"; import { ClusterId, clusterStore } from "../../../common/cluster-store";
import { WebviewTag } from "electron";
import { observable, reaction } from "mobx";
import logger from "../../../main/logger"; import logger from "../../../main/logger";
import { clusterIpc } from "../../../common/cluster-ipc";
import { cssNames } from "../../utils";
// fixme: hide active view on disconnect
// fixme: webview reloading/blinking when switching common <-> cluster views
interface LensView { interface LensView {
isLoaded?: boolean isLoaded?: boolean
@ -28,9 +25,13 @@ interface LensView {
const lensViews = observable.map<ClusterId, LensView>(); const lensViews = observable.map<ClusterId, LensView>();
// fixme: figure out how to replace webview-tag to iframe export function hasLoadedView(clusterId: ClusterId): boolean {
return !!lensViews.get(clusterId)?.isLoaded;
}
// todo: figure out how to replace webview-tag to iframe
function initView(clusterId: ClusterId) { function initView(clusterId: ClusterId) {
if (lensViews.has(clusterId)) { if (!clusterId || lensViews.has(clusterId)) {
return; return;
} }
logger.info(`[CLUSTER-VIEW]: init dashboard, clusterId=${clusterId}`) logger.info(`[CLUSTER-VIEW]: init dashboard, clusterId=${clusterId}`)
@ -39,9 +40,9 @@ function initView(clusterId: ClusterId) {
webview.setAttribute("src", `//${clusterId}.${location.host}`) webview.setAttribute("src", `//${clusterId}.${location.host}`)
webview.setAttribute("nodeintegration", "true") webview.setAttribute("nodeintegration", "true")
webview.setAttribute("enableremotemodule", "true") webview.setAttribute("enableremotemodule", "true")
webview.addEventListener("did-finish-load", async () => { webview.addEventListener("did-finish-load", () => {
logger.info(`[CLUSTER-VIEW]: loaded, clusterId=${clusterId}`) logger.info(`[CLUSTER-VIEW]: loaded, clusterId=${clusterId}`)
await clusterIpc.init.invokeFromRenderer(clusterId); // push cluster-state to webview and render dashboard clusterIpc.init.invokeFromRenderer(clusterId); // push cluster-state to webview and init render
lensViews.get(clusterId).isLoaded = true; lensViews.get(clusterId).isLoaded = true;
refreshViews(); refreshViews();
}); });
@ -53,9 +54,9 @@ function initView(clusterId: ClusterId) {
} }
function refreshViews() { function refreshViews() {
const activeCluster = getMatchedCluster() const cluster = getMatchedCluster()
lensViews.forEach(({ clusterId, view, isLoaded }) => { lensViews.forEach(({ clusterId, view, isLoaded }) => {
const isVisible = clusterId === activeCluster?.id && activeCluster?.available; const isVisible = cluster && cluster.available && cluster.id === clusterId;
view.style.display = isLoaded && isVisible ? "flex" : "none" view.style.display = isLoaded && isVisible ? "flex" : "none"
}) })
} }
@ -64,11 +65,13 @@ function refreshViews() {
export class ClusterManager extends React.Component { export class ClusterManager extends React.Component {
componentDidMount() { componentDidMount() {
disposeOnUnmount(this, [ disposeOnUnmount(this, [
reaction(getMatchedCluster, cluster => { reaction(getMatchedClusterId, initView, {
// auto-refresh visibility for active cluster fireImmediately: true
if (cluster) initView(cluster.id); }),
refreshViews(); reaction(() => [
}, { getMatchedClusterId(),
getMatchedCluster()?.available,
], refreshViews, {
fireImmediately: true fireImmediately: true
}) })
]) ])

View File

@ -3,24 +3,18 @@ import React from "react";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import { getMatchedCluster } from "./cluster-view.route"; import { getMatchedCluster } from "./cluster-view.route";
import { ClusterStatus } from "./cluster-status"; import { ClusterStatus } from "./cluster-status";
import { hasLoadedView } from "./cluster-manager";
@observer @observer
export class ClusterView extends React.Component { export class ClusterView extends React.Component {
renderContent() {
const cluster = getMatchedCluster();
if (!cluster) {
return;
}
if (!cluster.available) {
return <ClusterStatus clusterId={cluster.id} className="box center"/>
}
}
render() { render() {
const cluster = getMatchedCluster(); const cluster = getMatchedCluster();
const showStatus = cluster && (!cluster.available || !hasLoadedView(cluster.id))
return ( return (
<div className="ClusterView flex column"> <div className="ClusterView flex column">
{this.renderContent()} {showStatus && (
<ClusterStatus clusterId={cluster.id} className="box center"/>
)}
</div> </div>
) )
} }