mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
add reliable mechanism for extensions to activate a cluster
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
13a06c8df9
commit
872280d57f
@ -8,6 +8,7 @@ import logger from "../main/logger";
|
|||||||
import type { ClusterId } from "./cluster-store";
|
import type { ClusterId } from "./cluster-store";
|
||||||
import { Cluster } from "../main/cluster";
|
import { Cluster } from "../main/cluster";
|
||||||
import migrations from "../migrations/workspace-store";
|
import migrations from "../migrations/workspace-store";
|
||||||
|
import { clusterViewURL } from "../renderer/components/cluster-manager/cluster-view.route";
|
||||||
|
|
||||||
export type WorkspaceId = string;
|
export type WorkspaceId = string;
|
||||||
|
|
||||||
@ -345,9 +346,34 @@ export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
|
|||||||
if (!this.getById(id)) {
|
if (!this.getById(id)) {
|
||||||
throw new Error(`workspace ${id} doesn't exist`);
|
throw new Error(`workspace ${id} doesn't exist`);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.currentWorkspaceId = id;
|
this.currentWorkspaceId = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
async setActiveCluster(clusterOrId: ClusterId | Cluster): Promise<void> {
|
||||||
|
const cluster = typeof clusterOrId === "string"
|
||||||
|
? clusterStore.getById(clusterOrId)
|
||||||
|
: clusterOrId;
|
||||||
|
|
||||||
|
if (!cluster?.enabled) {
|
||||||
|
throw new Error(`cluster ${(clusterOrId as Cluster)?.id ?? clusterOrId} doesn't exist`);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setActive(this.getById(cluster.workspace).id);
|
||||||
|
|
||||||
|
if (ipcRenderer) {
|
||||||
|
const { navigate } = await import("../renderer/navigation");
|
||||||
|
|
||||||
|
navigate(clusterViewURL({ params: { clusterId: cluster.id } }));
|
||||||
|
} else {
|
||||||
|
const { WindowManager } = await import("../main/window-manager");
|
||||||
|
const windowManager = WindowManager.getInstance() as any;
|
||||||
|
|
||||||
|
await windowManager.navigate(clusterViewURL({ params: { clusterId: cluster.id } }));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
addWorkspace(workspace: Workspace) {
|
addWorkspace(workspace: Workspace) {
|
||||||
const { id, name } = workspace;
|
const { id, name } = workspace;
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { Singleton } from "../core-api/utils";
|
import { Singleton } from "../core-api/utils";
|
||||||
import { workspaceStore as internalWorkspaceStore, WorkspaceStore as InternalWorkspaceStore, Workspace, WorkspaceId } from "../../common/workspace-store";
|
import { workspaceStore as internalWorkspaceStore, WorkspaceStore as InternalWorkspaceStore, Workspace, WorkspaceId } from "../../common/workspace-store";
|
||||||
import { ObservableMap } from "mobx";
|
import { ObservableMap } from "mobx";
|
||||||
|
import { Cluster, ClusterId } from "../core-api/stores";
|
||||||
|
|
||||||
export { Workspace } from "../../common/workspace-store";
|
export { Workspace } from "../../common/workspace-store";
|
||||||
export type { WorkspaceId, WorkspaceModel } from "../../common/workspace-store";
|
export type { WorkspaceId, WorkspaceModel } from "../../common/workspace-store";
|
||||||
@ -113,6 +114,14 @@ export class WorkspaceStore extends Singleton {
|
|||||||
removeWorkspaceById(id: WorkspaceId) {
|
removeWorkspaceById(id: WorkspaceId) {
|
||||||
return internalWorkspaceStore.removeWorkspaceById(id);
|
return internalWorkspaceStore.removeWorkspaceById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the cluster and its workspace as active
|
||||||
|
* @param clusterOrId the cluster's ID or instance to set as the active cluster
|
||||||
|
*/
|
||||||
|
setActiveCluster(clusterOrId: ClusterId | Cluster) {
|
||||||
|
return internalWorkspaceStore.setActiveCluster(clusterOrId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const workspaceStore = WorkspaceStore.getInstance<WorkspaceStore>();
|
export const workspaceStore = WorkspaceStore.getInstance<WorkspaceStore>();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user