diff --git a/src/extensions/lens-extension.ts b/src/extensions/lens-extension.ts index a00e289e17..972278f864 100644 --- a/src/extensions/lens-extension.ts +++ b/src/extensions/lens-extension.ts @@ -45,7 +45,7 @@ export class LensExtension { * getExtensionFileFolder returns the path to an already created folder. This * folder is for the sole use of this extension. * - * Note: there is no security done on this folder, only obfiscation of the + * Note: there is no security done on this folder, only obfuscation of the * folder name. */ async getExtensionFileFolder(): Promise { diff --git a/src/extensions/lens-main-extension.ts b/src/extensions/lens-main-extension.ts index f0e943540d..f68a097209 100644 --- a/src/extensions/lens-main-extension.ts +++ b/src/extensions/lens-main-extension.ts @@ -2,6 +2,11 @@ import type { MenuRegistration } from "./registries/menu-registry"; import { LensExtension } from "./lens-extension"; import { WindowManager } from "../main/window-manager"; import { getExtensionPageUrl } from "./registries/page-registry"; +import { Cluster } from "../main/cluster"; +import { ClusterId, clusterStore } from "../common/cluster-store"; +import logger from "../main/logger"; +import { workspaceStore } from "../common/workspace-store"; +import { clusterViewURL } from "../renderer/components/cluster-manager/cluster-view.route"; export class LensMainExtension extends LensExtension { appMenus: MenuRegistration[] = []; @@ -16,4 +21,18 @@ export class LensMainExtension extends LensExtension { await windowManager.navigate(pageUrl, frameId); } + + async activateCluster(clusterOrId: ClusterId | Cluster): Promise { + const windowManager = WindowManager.getInstance(); + const cluster = typeof clusterOrId === "string" + ? clusterStore.getById(clusterOrId) + : clusterOrId; + + if (!(cluster instanceof Cluster)) { + return void logger.warn(`[${this.name.toUpperCase()}]: tried to activate a cluster. Provided invalid ID or not a cluster`, { clusterOrId }); + } + + workspaceStore.getById(cluster.workspace).setActiveCluster(cluster); + await windowManager.navigate(clusterViewURL({ params: { clusterId: cluster.id }})); + } } diff --git a/src/extensions/lens-renderer-extension.ts b/src/extensions/lens-renderer-extension.ts index 982830d8af..38d45c80a8 100644 --- a/src/extensions/lens-renderer-extension.ts +++ b/src/extensions/lens-renderer-extension.ts @@ -1,8 +1,12 @@ import type { AppPreferenceRegistration, ClusterFeatureRegistration, ClusterPageMenuRegistration, KubeObjectDetailRegistration, KubeObjectMenuRegistration, KubeObjectStatusRegistration, PageMenuRegistration, PageRegistration, StatusBarRegistration, } from "./registries"; -import type { Cluster } from "../main/cluster"; +import { Cluster } from "../main/cluster"; import { LensExtension } from "./lens-extension"; import { getExtensionPageUrl } from "./registries/page-registry"; import { CommandRegistration } from "./registries/command-registry"; +import { clusterViewURL } from "../renderer/components/cluster-manager/cluster-view.route"; +import { workspaceStore } from "../common/workspace-store"; +import logger from "../main/logger"; +import { ClusterId, clusterStore } from "../common/cluster-store"; export class LensRendererExtension extends LensExtension { globalPages: PageRegistration[] = []; @@ -28,6 +32,20 @@ export class LensRendererExtension extends LensExtension { navigate(pageUrl); } + async activateCluster(clusterOrId: ClusterId | Cluster): Promise { + const { navigate } = await import("../renderer/navigation"); + const cluster = typeof clusterOrId === "string" + ? clusterStore.getById(clusterOrId) + : clusterOrId; + + if (!(cluster instanceof Cluster)) { + return void logger.warn(`[${this.name.toUpperCase()}]: tried to activate a cluster. Provided invalid ID or not a cluster`, { clusterOrId }); + } + + workspaceStore.getById(cluster.workspace).setActiveCluster(cluster); + navigate(clusterViewURL({ params: { clusterId: cluster.id } })); + } + /** * Defines if extension is enabled for a given cluster. Defaults to `true`. */ diff --git a/src/renderer/components/cluster-manager/cluster-manager.tsx b/src/renderer/components/cluster-manager/cluster-manager.tsx index bedaa74024..e1bdc5cd1f 100644 --- a/src/renderer/components/cluster-manager/cluster-manager.tsx +++ b/src/renderer/components/cluster-manager/cluster-manager.tsx @@ -2,7 +2,7 @@ import "./cluster-manager.scss"; import React from "react"; import { Redirect, Route, Switch } from "react-router"; -import { comparer, reaction } from "mobx"; +import { comparer, computed, reaction } from "mobx"; import { disposeOnUnmount, observer } from "mobx-react"; import { ClustersMenu } from "./clusters-menu"; import { BottomBar } from "./bottom-bar"; @@ -44,7 +44,7 @@ export class ClusterManager extends React.Component { lensViews.clear(); } - get startUrl() { + @computed get startUrl() { const { currentWorkspace } = workspaceStore; if (currentWorkspace.activeClusterId) { @@ -70,9 +70,13 @@ export class ClusterManager extends React.Component { - {globalPageRegistry.getItems().map(({ url, components: { Page } }) => { - return ; - })} + { + globalPageRegistry + .getItems() + .map(({ url, components: { Page } }) => ( + + )) + }