diff --git a/src/common/cluster-ipc.ts b/src/common/cluster-ipc.ts index 718151c3ed..b1cced3edf 100644 --- a/src/common/cluster-ipc.ts +++ b/src/common/cluster-ipc.ts @@ -25,9 +25,12 @@ import { appEventBus } from "./event-bus"; import { ResourceApplier } from "../main/resource-applier"; import { ipcMain, IpcMainInvokeEvent } from "electron"; import { clusterFrameMap } from "./cluster-frames"; +import { catalogEntityRegistry } from "../main/catalog"; +import type { KubernetesCluster } from "./catalog-entities"; export const clusterActivateHandler = "cluster:activate"; export const clusterSetFrameIdHandler = "cluster:set-frame-id"; +export const clusterVisibilityHandler = "cluster:visibility"; export const clusterRefreshHandler = "cluster:refresh"; export const clusterDisconnectHandler = "cluster:disconnect"; export const clusterKubectlApplyAllHandler = "cluster:kubectl-apply-all"; @@ -49,6 +52,18 @@ if (ipcMain) { } }); + handleRequest(clusterVisibilityHandler, (event: IpcMainInvokeEvent, clusterId: ClusterId, visible: boolean) => { + const entity = catalogEntityRegistry.getById(clusterId); + + for (const kubeEntity of catalogEntityRegistry.getItemsForApiKind(entity.apiVersion, entity.kind)) { + kubeEntity.status.active = false; + } + + if (entity) { + entity.status.active = visible; + } + }); + handleRequest(clusterRefreshHandler, (event, clusterId: ClusterId) => { return ClusterStore.getInstance() .getById(clusterId) diff --git a/src/main/catalog/catalog-entity-registry.ts b/src/main/catalog/catalog-entity-registry.ts index 55162970a2..4cecf4f49b 100644 --- a/src/main/catalog/catalog-entity-registry.ts +++ b/src/main/catalog/catalog-entity-registry.ts @@ -48,6 +48,15 @@ export class CatalogEntityRegistry { return allItems.filter((entity) => this.categoryRegistry.getCategoryForEntity(entity) !== undefined); } + getById(id: string): T | undefined { + const item = this.items.find((entity) => entity.metadata.uid === id); + + if (item) return item as T; + + + return undefined; + } + getItemsForApiKind(apiVersion: string, kind: string): T[] { const items = this.items.filter((item) => item.apiVersion === apiVersion && item.kind === kind); diff --git a/src/main/cluster-manager.ts b/src/main/cluster-manager.ts index b0eb2e7471..2daefb689a 100644 --- a/src/main/cluster-manager.ts +++ b/src/main/cluster-manager.ts @@ -79,8 +79,7 @@ export class ClusterManager extends Singleton { if (index !== -1) { const entity = catalogEntityRegistry.items[index] as KubernetesCluster; - entity.status.phase = cluster.disconnected ? "disconnected" : "connected"; - entity.status.active = !cluster.disconnected; + this.updateEntityStatus(entity, cluster); if (cluster.preferences?.clusterName) { entity.metadata.name = cluster.preferences.clusterName; @@ -101,6 +100,10 @@ export class ClusterManager extends Singleton { } } + protected updateEntityStatus(entity: KubernetesCluster, cluster: Cluster) { + entity.status.phase = cluster.accessible ? "connected" : "disconnected"; + } + @action syncClustersFromCatalog(entities: KubernetesCluster[]) { for (const entity of entities) { const cluster = this.store.getById(entity.metadata.uid); @@ -118,10 +121,7 @@ export class ClusterManager extends Singleton { cluster.kubeConfigPath = entity.spec.kubeconfigPath; cluster.contextName = entity.spec.kubeconfigContext; - entity.status = { - phase: cluster.disconnected ? "disconnected" : "connected", - active: !cluster.disconnected - }; + this.updateEntityStatus(entity, cluster); } } } diff --git a/src/renderer/components/cluster-manager/lens-views.ts b/src/renderer/components/cluster-manager/lens-views.ts index e6d636c318..ace85eed6e 100644 --- a/src/renderer/components/cluster-manager/lens-views.ts +++ b/src/renderer/components/cluster-manager/lens-views.ts @@ -22,6 +22,8 @@ import { observable, 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"; export interface LensView { isLoaded?: boolean @@ -93,5 +95,9 @@ export function refreshViews(visibleClusterId?: string) { const isVisible = isCurrent && isLoaded && isReady; view.style.display = isVisible ? "flex" : "none"; + + requestMain(clusterVisibilityHandler, clusterId, isVisible).catch(() => { + logger.error(`[LENS-VIEW]: failed to set cluster visibility, clusterId=${clusterId}`); + }); }); }