From 7b5092d78beb52ddb82c994788a2d62519ac67bf Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 10 Aug 2020 15:59:33 +0300 Subject: [PATCH] cluster-view more fixes & UX optimizations Signed-off-by: Roman Signed-off-by: Lauri Nevala --- .../cluster-manager/cluster-manager.tsx | 41 ++++++++++--------- .../cluster-manager/cluster-view.tsx | 16 +++----- 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/src/renderer/components/cluster-manager/cluster-manager.tsx b/src/renderer/components/cluster-manager/cluster-manager.tsx index 8a958e38a1..5e1ca61513 100644 --- a/src/renderer/components/cluster-manager/cluster-manager.tsx +++ b/src/renderer/components/cluster-manager/cluster-manager.tsx @@ -1,7 +1,11 @@ import "./cluster-manager.scss" import React from "react"; +import { WebviewTag } from "electron"; import { Redirect, Route, Switch } from "react-router"; +import { observable, reaction } from "mobx"; import { disposeOnUnmount, observer } from "mobx-react"; +import { clusterIpc } from "../../../common/cluster-ipc"; +import { cssNames } from "../../utils"; import { ClustersMenu } from "./clusters-menu"; import { BottomBar } from "./bottom-bar"; import { LandingPage, landingRoute, landingURL } from "../+landing-page"; @@ -9,16 +13,9 @@ import { Preferences, preferencesRoute } from "../+preferences"; import { Workspaces, workspacesRoute } from "../+workspaces"; import { AddCluster, addClusterRoute } from "../+add-cluster"; 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 { WebviewTag } from "electron"; -import { observable, reaction } from "mobx"; 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 { isLoaded?: boolean @@ -28,9 +25,13 @@ interface LensView { const lensViews = observable.map(); -// 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) { - if (lensViews.has(clusterId)) { + if (!clusterId || lensViews.has(clusterId)) { return; } logger.info(`[CLUSTER-VIEW]: init dashboard, clusterId=${clusterId}`) @@ -39,9 +40,9 @@ function initView(clusterId: ClusterId) { webview.setAttribute("src", `//${clusterId}.${location.host}`) webview.setAttribute("nodeintegration", "true") webview.setAttribute("enableremotemodule", "true") - webview.addEventListener("did-finish-load", async () => { + webview.addEventListener("did-finish-load", () => { 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; refreshViews(); }); @@ -53,9 +54,9 @@ function initView(clusterId: ClusterId) { } function refreshViews() { - const activeCluster = getMatchedCluster() + const cluster = getMatchedCluster() 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" }) } @@ -64,11 +65,13 @@ function refreshViews() { export class ClusterManager extends React.Component { componentDidMount() { disposeOnUnmount(this, [ - reaction(getMatchedCluster, cluster => { - // auto-refresh visibility for active cluster - if (cluster) initView(cluster.id); - refreshViews(); - }, { + reaction(getMatchedClusterId, initView, { + fireImmediately: true + }), + reaction(() => [ + getMatchedClusterId(), + getMatchedCluster()?.available, + ], refreshViews, { fireImmediately: true }) ]) diff --git a/src/renderer/components/cluster-manager/cluster-view.tsx b/src/renderer/components/cluster-manager/cluster-view.tsx index b0e3212a9e..c3fc1c3ad6 100644 --- a/src/renderer/components/cluster-manager/cluster-view.tsx +++ b/src/renderer/components/cluster-manager/cluster-view.tsx @@ -3,24 +3,18 @@ import React from "react"; import { observer } from "mobx-react"; import { getMatchedCluster } from "./cluster-view.route"; import { ClusterStatus } from "./cluster-status"; +import { hasLoadedView } from "./cluster-manager"; @observer export class ClusterView extends React.Component { - renderContent() { - const cluster = getMatchedCluster(); - if (!cluster) { - return; - } - if (!cluster.available) { - return - } - } - render() { const cluster = getMatchedCluster(); + const showStatus = cluster && (!cluster.available || !hasLoadedView(cluster.id)) return (
- {this.renderContent()} + {showStatus && ( + + )}
) }