diff --git a/src/common/cluster-store.ts b/src/common/cluster-store.ts index d1ae7294d4..54140c5c20 100644 --- a/src/common/cluster-store.ts +++ b/src/common/cluster-store.ts @@ -82,13 +82,13 @@ export interface ClusterRenderInfo extends ClusterModel { online: boolean; } -export class LensClusterStoreImpl extends BaseStore { +export class ClusterStore extends BaseStore { static getCustomKubeConfigPath(clusterId: ClusterId): string { return path.resolve((app || remote.app).getPath("userData"), "kubeconfigs", clusterId); } static embedCustomKubeConfig(clusterId: ClusterId, kubeConfig: KubeConfig | string): string { - const filePath = LensClusterStoreImpl.getCustomKubeConfigPath(clusterId); + const filePath = ClusterStore.getCustomKubeConfigPath(clusterId); const fileContents = typeof kubeConfig == "string" ? kubeConfig : dumpConfigYaml(kubeConfig); saveToAppFiles(filePath, fileContents, { mode: 0o600 }); return filePath; @@ -200,21 +200,6 @@ export class LensClusterStoreImpl extends BaseStore { return this.deadClusters.get(id); } - protected getRendererInfoByWorkspace(workspaceId: string): ClusterRenderInfo[] { - const aliveClusters: ClusterRenderInfo[] = this.clustersList.filter(c => c.workspace === workspaceId); - const deadClusters: ClusterRenderInfo[] = this.deadClustersList - .filter(([c]) => c.workspace === workspaceId) - .map(([cluster, error]) => ({ - DeadError: error, - name: cluster.contextName, - online: false, - ...cluster, - })); - - - return _.sortBy([...aliveClusters, ...deadClusters], c => c.preferences?.iconOrder); - } - getByWorkspaceId(workspaceId: string): Cluster[] { const clusters = this.clustersList.filter(c => c.workspace === workspaceId); return _.sortBy(clusters, c => c.preferences?.iconOrder); @@ -262,7 +247,7 @@ export class LensClusterStoreImpl extends BaseStore { this.setActive(null); } // remove only custom kubeconfigs (pasted as text) - if (cluster.kubeConfigPath == LensClusterStoreImpl.getCustomKubeConfigPath(clusterId)) { + if (cluster.kubeConfigPath == ClusterStore.getCustomKubeConfigPath(clusterId)) { unlink(cluster.kubeConfigPath).catch(() => null); } } @@ -348,20 +333,22 @@ export class LensClusterStoreImpl extends BaseStore { } } -export class LensClusterStore extends LensClusterStoreImpl { - public getRendererInfoByWorkspace(workspaceId: string): ClusterRenderInfo[] { - return super.getRendererInfoByWorkspace(workspaceId); - } -} - -export class ClusterStore extends LensClusterStoreImpl { - private constructor() { - super(); - } -} - export const clusterStore = ClusterStore.getInstance(); -export const lensClusterStore = clusterStore as LensClusterStore; + +export function getRendererInfoByWorkspace(workspaceId: string): ClusterRenderInfo[] { + const aliveClusters: ClusterRenderInfo[] = clusterStore.clustersList.filter(c => c.workspace === workspaceId); + const deadClusters: ClusterRenderInfo[] = clusterStore.deadClustersList + .filter(([c]) => c.workspace === workspaceId) + .map(([cluster, error]) => ({ + DeadError: error, + name: cluster.contextName, + online: false, + ...cluster, + })); + + + return _.sortBy([...aliveClusters, ...deadClusters], c => c.preferences?.iconOrder); +} export function getClusterIdFromHost(hostname: string): ClusterId { const subDomains = hostname.split(":")[0].split("."); diff --git a/src/main/tray.ts b/src/main/tray.ts index e5ea069a1a..39aa18d9e4 100644 --- a/src/main/tray.ts +++ b/src/main/tray.ts @@ -5,7 +5,7 @@ import { autorun } from "mobx"; import { showAbout } from "./menu"; import { AppUpdater } from "./app-updater"; import { WindowManager } from "./window-manager"; -import { ClusterRenderInfo, clusterStore, lensClusterStore } from "../common/cluster-store"; +import { ClusterRenderInfo, getRendererInfoByWorkspace } from "../common/cluster-store"; import { Workspace, workspaceStore } from "../common/workspace-store"; import { preferencesURL } from "../renderer/components/+preferences/preferences.route"; import { clusterViewURL } from "../renderer/components/cluster-manager/cluster-view.route"; @@ -82,7 +82,7 @@ export function createTrayMenu(windowManager: WindowManager): Menu { { label: "Clusters", submenu: workspaceStore.enabledWorkspacesList - .map((workspace): [Workspace, ClusterRenderInfo[]] => [workspace, lensClusterStore.getRendererInfoByWorkspace(workspace.id)]) + .map((workspace): [Workspace, ClusterRenderInfo[]] => [workspace, getRendererInfoByWorkspace(workspace.id)]) .filter(([, clusters]) => clusters.length > 0) .map(([workspace, clusters]): MenuItemConstructorOptions => ({ label: workspace.name, diff --git a/src/renderer/components/cluster-manager/clusters-menu.tsx b/src/renderer/components/cluster-manager/clusters-menu.tsx index 729739e9be..464cdc6e66 100644 --- a/src/renderer/components/cluster-manager/clusters-menu.tsx +++ b/src/renderer/components/cluster-manager/clusters-menu.tsx @@ -8,7 +8,7 @@ import { observer } from "mobx-react"; import { _i18n } from "../../i18n"; import { t, Trans } from "@lingui/macro"; import { userStore } from "../../../common/user-store"; -import { ClusterId, ClusterRenderInfo, clusterStore, lensClusterStore } from "../../../common/cluster-store"; +import { ClusterId, ClusterRenderInfo, clusterStore, getRendererInfoByWorkspace } from "../../../common/cluster-store"; import { workspaceStore } from "../../../common/workspace-store"; import { ClusterIcon } from "../cluster-icon"; import { Icon } from "../icon"; @@ -105,7 +105,7 @@ export class ClusterMenu extends React.Component { const { className } = this.props; const { newContexts } = userStore; const workspace = workspaceStore.getById(workspaceStore.currentWorkspaceId); - const clusters = lensClusterStore.getRendererInfoByWorkspace(workspace.id); + const clusters = getRendererInfoByWorkspace(workspace.id); const activeClusterId = clusterStore.activeCluster; return (