From 1f0e79cee8419d6d47b8f5505af08ae30cc882d7 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Wed, 28 Jul 2021 10:42:23 -0400 Subject: [PATCH] Fix hotbar active check and accessible namespaces Signed-off-by: Sebastian Malton --- .../catalog-entities/kubernetes-cluster.ts | 26 ++++++++++--------- .../components/cluster-manager/lens-views.ts | 10 ++++++- .../components/hotbar/hotbar-entity-icon.tsx | 10 +++---- src/renderer/ipc/index.tsx | 13 ++++++++++ 4 files changed, 41 insertions(+), 18 deletions(-) diff --git a/src/common/catalog-entities/kubernetes-cluster.ts b/src/common/catalog-entities/kubernetes-cluster.ts index b09d3734e0..fb2bac0e06 100644 --- a/src/common/catalog-entities/kubernetes-cluster.ts +++ b/src/common/catalog-entities/kubernetes-cluster.ts @@ -103,18 +103,20 @@ export class KubernetesCluster extends CatalogEntity this.onRun(), - }, - { - title: "Open in new window", - icon: "launch", - onClick: () => requestMain(onNewWindowForClusterHandler, this.getId()), - }, - ); + if (this.status.phase === "connected" || this.status.phase === "disconnected") { + context.menuItems.push( + { + title: "Open", + icon: "open_in_full", + onClick: () => this.onRun(), + }, + { + title: "Open in new window", + icon: "launch", + onClick: () => requestMain(onNewWindowForClusterHandler, this.getId()), + }, + ); + } if (!this.metadata.source || this.metadata.source === "local") { context.menuItems.push( diff --git a/src/renderer/components/cluster-manager/lens-views.ts b/src/renderer/components/cluster-manager/lens-views.ts index f5355183ad..dc10d55a6f 100644 --- a/src/renderer/components/cluster-manager/lens-views.ts +++ b/src/renderer/components/cluster-manager/lens-views.ts @@ -19,11 +19,12 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { observable, when } from "mobx"; +import { observable, observe, when } from "mobx"; import { ClusterId, ClusterStore, getClusterFrameUrl } from "../../../common/cluster-store"; import logger from "../../../main/logger"; import { requestMain } from "../../../common/ipc"; import { clusterVisibilityHandler } from "../../../common/cluster-ipc"; +import { toJS } from "../../utils"; export interface LensView { isLoaded?: boolean @@ -32,6 +33,11 @@ export interface LensView { } export const lensViews = observable.map(); +export const visibleCluster = observable.box(); + +observe(lensViews, change => { + console.info(`lensViews change: type=${change.type} name=${change.name}`, toJS((change as any).newValue)); +}); export function hasLoadedView(clusterId: ClusterId): boolean { return !!lensViews.get(clusterId)?.isLoaded; @@ -89,6 +95,8 @@ export function refreshViews(visibleClusterId?: string) { console.info(`[LENS-VIEW]: refreshing iframe views, visible cluster id=${visibleClusterId}`); const cluster = ClusterStore.getInstance().getById(visibleClusterId); + visibleCluster.set(visibleClusterId); + lensViews.forEach(({ clusterId, view, isLoaded }) => { const isCurrent = clusterId === cluster?.id; const isReady = cluster?.available && cluster?.ready; diff --git a/src/renderer/components/hotbar/hotbar-entity-icon.tsx b/src/renderer/components/hotbar/hotbar-entity-icon.tsx index a7b809bff7..cd716eae78 100644 --- a/src/renderer/components/hotbar/hotbar-entity-icon.tsx +++ b/src/renderer/components/hotbar/hotbar-entity-icon.tsx @@ -31,6 +31,7 @@ import { cssNames, IClassName } from "../../utils"; import { Icon } from "../icon"; import { HotbarIcon } from "./hotbar-icon"; import { HotbarStore } from "../../../common/hotbar-store"; +import { visibleCluster } from "../cluster-manager/lens-views"; interface Props extends DOMAttributes { entity: CatalogEntity; @@ -87,7 +88,7 @@ export class HotbarEntityIcon extends React.Component { } isActive(item: CatalogEntity) { - return catalogEntityRegistry.activeEntity?.metadata?.uid == item.getId(); + return visibleCluster.get() === item.getId(); } isPersisted(entity: CatalogEntity) { @@ -98,14 +99,14 @@ export class HotbarEntityIcon extends React.Component { if (!this.contextMenu) { return null; } - const { entity, errorClass, add, remove, index, children, ...elemProps } = this.props; + const active = this.isActive(entity); const className = cssNames("HotbarEntityIcon", this.props.className, { interactive: true, - active: this.isActive(entity), + active, disabled: !entity }); @@ -129,7 +130,6 @@ export class HotbarEntityIcon extends React.Component { await entity.onContextMenuOpen(this.contextMenu); }; - const isActive = this.isActive(entity); return ( { material={entity.spec.icon?.material} background={entity.spec.icon?.background} className={className} - active={isActive} + active={active} onMenuOpen={onOpen} menuItems={this.contextMenu.menuItems} tooltip={`${entity.metadata.name} (${entity.metadata.source})`} diff --git a/src/renderer/ipc/index.tsx b/src/renderer/ipc/index.tsx index 338f71c38d..5eff7373d3 100644 --- a/src/renderer/ipc/index.tsx +++ b/src/renderer/ipc/index.tsx @@ -28,6 +28,7 @@ import { isMac } from "../../common/vars"; import { ClusterStore } from "../../common/cluster-store"; import { navigate } from "../navigation"; import { entitySettingsURL } from "../../common/routes"; +import { visibleCluster } from "../components/cluster-manager/lens-views"; function sendToBackchannel(backchannel: string, notificationId: string, data: BackchannelArg): void { notificationsStore.remove(notificationId); @@ -80,6 +81,18 @@ const listNamespacesForbiddenHandlerDisplayedAt = new Map(); const intervalBetweenNotifications = 1000 * 60; // 60s function ListNamespacesForbiddenHandler(event: IpcRendererEvent, ...[clusterId]: ListNamespaceForbiddenArgs): void { + const cluster = ClusterStore.getInstance().getById(clusterId); + + if (!cluster) { + return void console.warn("[IPC]: ListNamespacesForbiddenHandler was called with unknown clusterId", { clusterId }); + } + + const visibileClusterId = visibleCluster.get(); + + if (visibileClusterId && visibileClusterId !== clusterId) { + return void console.debug("[IPC]: ListNamespacesForbiddenHandler not displaying notification that is not about the currently active cluster"); + } + const lastDisplayedAt = listNamespacesForbiddenHandlerDisplayedAt.get(clusterId); const wasDisplayed = Boolean(lastDisplayedAt); const now = Date.now();