mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add activateCluster method for extensions
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
22baee10f6
commit
487e22789e
@ -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<string> {
|
||||
|
||||
@ -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<void> {
|
||||
const windowManager = WindowManager.getInstance<WindowManager>();
|
||||
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 }}));
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<void> {
|
||||
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`.
|
||||
*/
|
||||
|
||||
@ -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 {
|
||||
<Route component={AddCluster} {...addClusterRoute} />
|
||||
<Route component={ClusterView} {...clusterViewRoute} />
|
||||
<Route component={ClusterSettings} {...clusterSettingsRoute} />
|
||||
{globalPageRegistry.getItems().map(({ url, components: { Page } }) => {
|
||||
return <Route key={url} path={url} component={Page}/>;
|
||||
})}
|
||||
{
|
||||
globalPageRegistry
|
||||
.getItems()
|
||||
.map(({ url, components: { Page } }) => (
|
||||
<Route key={url} path={url} component={Page} />
|
||||
))
|
||||
}
|
||||
<Redirect exact to={this.startUrl}/>
|
||||
</Switch>
|
||||
</main>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user