From 4ac53a548143063a8ab33db467d39a32871fb1b7 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Wed, 24 Nov 2021 10:18:05 -0500 Subject: [PATCH] Fix disconnect on currently connecting cluster Signed-off-by: Sebastian Malton --- .../cluster-manager/cluster-view.tsx | 24 +++++++++++++------ .../components/cluster-manager/lens-views.ts | 6 +---- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/renderer/components/cluster-manager/cluster-view.tsx b/src/renderer/components/cluster-manager/cluster-view.tsx index 5187866ef3..a9095f43fb 100644 --- a/src/renderer/components/cluster-manager/cluster-view.tsx +++ b/src/renderer/components/cluster-manager/cluster-view.tsx @@ -5,7 +5,7 @@ import "./cluster-view.scss"; import React from "react"; -import { computed, makeObservable, reaction } from "mobx"; +import { computed, makeObservable, reaction, when } from "mobx"; import { disposeOnUnmount, observer } from "mobx-react"; import type { RouteComponentProps } from "react-router"; import { ClusterStatus } from "./cluster-status"; @@ -55,17 +55,27 @@ export class ClusterView extends React.Component { bindEvents() { disposeOnUnmount(this, [ reaction(() => this.clusterId, async (clusterId) => { - ClusterFrameHandler.getInstance().setVisibleCluster(clusterId); - ClusterFrameHandler.getInstance().initView(clusterId); - requestClusterActivation(clusterId, false); // activate and fetch cluster's state from main + console.log(`[CLUSTER-VIEW]: clusterId=${clusterId} is now matched`, this.cluster?.getMeta()); + + const frameHandler = ClusterFrameHandler.getInstance(); + + frameHandler.setVisibleCluster(clusterId); + frameHandler.initView(clusterId); + requestClusterActivation(clusterId, !this.cluster.disconnected); // activate and fetch cluster's state from main catalogEntityRegistry.activeEntity = clusterId; }, { fireImmediately: true, }), - reaction(() => [this.cluster?.ready, this.cluster?.disconnected], ([, disconnected]) => { - if (ClusterFrameHandler.getInstance().hasLoadedView(this.clusterId) && disconnected) { - navigate(catalogURL()); // redirect to catalog when active cluster get disconnected/not available + reaction(() => this.cluster?.disconnected, disconnected => { + if (!disconnected) { + const cluster = this.cluster; // save a reference for the when so that changes in `clusterId` do + + when(() => cluster?.disconnected, () => { + if (cluster.id === this.clusterId) { + navigate(catalogURL()); // redirect to catalog when active cluster get disconnected/not available + } + }); } }), ]); diff --git a/src/renderer/components/cluster-manager/lens-views.ts b/src/renderer/components/cluster-manager/lens-views.ts index 22d5cba586..57c3d44b61 100644 --- a/src/renderer/components/cluster-manager/lens-views.ts +++ b/src/renderer/components/cluster-manager/lens-views.ts @@ -63,11 +63,7 @@ export class ClusterFrameHandler extends Singleton { () => !cluster.disconnected, () => { when( - () => { - const cluster = ClusterStore.getInstance().getById(clusterId); - - return !cluster || (cluster.disconnected && this.views.get(clusterId)?.isLoaded); - }, + () => !cluster || (cluster.disconnected && this.views.get(clusterId)?.isLoaded), () => { logger.info(`[LENS-VIEW]: remove dashboard, clusterId=${clusterId}`); this.views.delete(clusterId);