diff --git a/src/common/workspace-store.ts b/src/common/workspace-store.ts index 1272402a10..454163d22f 100644 --- a/src/common/workspace-store.ts +++ b/src/common/workspace-store.ts @@ -8,6 +8,7 @@ import logger from "../main/logger"; import type { ClusterId } from "./cluster-store"; import { Cluster } from "../main/cluster"; import migrations from "../migrations/workspace-store"; +import { clusterViewURL } from "../renderer/components/cluster-manager/cluster-view.route"; export type WorkspaceId = string; @@ -345,9 +346,34 @@ export class WorkspaceStore extends BaseStore { if (!this.getById(id)) { throw new Error(`workspace ${id} doesn't exist`); } + this.currentWorkspaceId = id; } + @action + async setActiveCluster(clusterOrId: ClusterId | Cluster): Promise { + 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 addWorkspace(workspace: Workspace) { const { id, name } = workspace; diff --git a/src/extensions/stores/workspace-store.ts b/src/extensions/stores/workspace-store.ts index 2ff4a830fd..7e66f617e8 100644 --- a/src/extensions/stores/workspace-store.ts +++ b/src/extensions/stores/workspace-store.ts @@ -1,6 +1,7 @@ import { Singleton } from "../core-api/utils"; import { workspaceStore as internalWorkspaceStore, WorkspaceStore as InternalWorkspaceStore, Workspace, WorkspaceId } from "../../common/workspace-store"; import { ObservableMap } from "mobx"; +import { Cluster, ClusterId } from "../core-api/stores"; export { Workspace } from "../../common/workspace-store"; export type { WorkspaceId, WorkspaceModel } from "../../common/workspace-store"; @@ -113,6 +114,14 @@ export class WorkspaceStore extends Singleton { removeWorkspaceById(id: WorkspaceId) { 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();