From 720f62cc1f6803f3b2430b875c2483da7c1e81a3 Mon Sep 17 00:00:00 2001 From: Alex Andreev Date: Mon, 26 Apr 2021 15:19:22 +0300 Subject: [PATCH] Reset active cluster when leaving dashboard Signed-off-by: Alex Andreev --- src/common/catalog-entities/kubernetes-cluster.ts | 2 +- .../components/cluster-manager/cluster-manager.tsx | 1 + src/renderer/components/hotbar/hotbar-menu.tsx | 9 +++++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/common/catalog-entities/kubernetes-cluster.ts b/src/common/catalog-entities/kubernetes-cluster.ts index b4b4c6aa5a..fda4927944 100644 --- a/src/common/catalog-entities/kubernetes-cluster.ts +++ b/src/common/catalog-entities/kubernetes-cluster.ts @@ -64,7 +64,7 @@ export class KubernetesCluster implements CatalogEntity { }, ]; - if (this.status.active) { + if (this.status.phase == "connected") { context.menuItems.unshift({ icon: "link_off", title: "Disconnect", diff --git a/src/renderer/components/cluster-manager/cluster-manager.tsx b/src/renderer/components/cluster-manager/cluster-manager.tsx index 489ffae284..00661a566a 100644 --- a/src/renderer/components/cluster-manager/cluster-manager.tsx +++ b/src/renderer/components/cluster-manager/cluster-manager.tsx @@ -27,6 +27,7 @@ export class ClusterManager extends React.Component { reaction(getMatchedClusterId, initView, { fireImmediately: true }), + reaction(() => !getMatchedClusterId(), () => ClusterStore.getInstance().setActive(null)), reaction(() => [ getMatchedClusterId(), // refresh when active cluster-view changed hasLoadedView(getMatchedClusterId()), // refresh when cluster's webview loaded diff --git a/src/renderer/components/hotbar/hotbar-menu.tsx b/src/renderer/components/hotbar/hotbar-menu.tsx index 11bde7ddc8..533dd09742 100644 --- a/src/renderer/components/hotbar/hotbar-menu.tsx +++ b/src/renderer/components/hotbar/hotbar-menu.tsx @@ -7,11 +7,12 @@ import { HotbarIcon } from "./hotbar-icon"; import { cssNames, IClassName } from "../../utils"; import { catalogEntityRegistry } from "../../api/catalog-entity-registry"; import { defaultHotbarCells, HotbarItem, HotbarStore } from "../../../common/hotbar-store"; -import { catalogEntityRunContext } from "../../api/catalog-entity"; +import { CatalogEntity, catalogEntityRunContext } from "../../api/catalog-entity"; import { Icon } from "../icon"; import { Badge } from "../badge"; import { CommandOverlay } from "../command-palette"; import { HotbarSwitchCommand } from "./hotbar-switch-command"; +import { ClusterStore } from "../../../common/cluster-store"; interface Props { className?: IClassName; @@ -23,6 +24,10 @@ export class HotbarMenu extends React.Component { return HotbarStore.getInstance().getActive(); } + isActive(item: CatalogEntity) { + return ClusterStore.getInstance().activeClusterId == item.getId(); + } + getEntity(item: HotbarItem) { const hotbar = HotbarStore.getInstance().getActive(); @@ -58,7 +63,7 @@ export class HotbarMenu extends React.Component { key={index} index={index} entity={entity} - isActive={entity.status.active} + isActive={this.isActive(entity)} onClick={() => entity.onRun(catalogEntityRunContext)} /> )}