mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add extension-api facades to cluster & workspace stores (#1546)
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
245eab0120
commit
07e6df9fdc
@ -1,6 +1,8 @@
|
|||||||
export { ExtensionStore } from "../extension-store";
|
export { ExtensionStore } from "../extension-store";
|
||||||
export { clusterStore } from "../../common/cluster-store";
|
|
||||||
export type { ClusterModel } from "../../common/cluster-store";
|
export { clusterStore, Cluster } from "../stores/cluster-store";
|
||||||
export { Cluster } from "../../main/cluster";
|
export type { ClusterModel, ClusterId } from "../stores/cluster-store";
|
||||||
export { workspaceStore, Workspace } from "../../common/workspace-store";
|
|
||||||
export type { WorkspaceModel } from "../../common/workspace-store";
|
export { workspaceStore, Workspace } from "../stores/workspace-store";
|
||||||
|
export type { WorkspaceId, WorkspaceModel } from "../stores/workspace-store";
|
||||||
|
|
||||||
|
|||||||
125
src/extensions/stores/cluster-store.ts
Normal file
125
src/extensions/stores/cluster-store.ts
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
import { clusterStore as internalClusterStore, ClusterId } from "../../common/cluster-store";
|
||||||
|
import type { ClusterModel } from "../../common/cluster-store";
|
||||||
|
import { Cluster } from "../../main/cluster";
|
||||||
|
import { Singleton } from "../core-api/utils";
|
||||||
|
import { ObservableMap } from "mobx";
|
||||||
|
|
||||||
|
export { Cluster } from "../../main/cluster";
|
||||||
|
export type { ClusterModel, ClusterId } from "../../common/cluster-store";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store for all added clusters
|
||||||
|
*/
|
||||||
|
export class ClusterStore extends Singleton {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Active cluster id
|
||||||
|
*/
|
||||||
|
get activeClusterId(): string {
|
||||||
|
return internalClusterStore.activeCluster;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set active cluster id
|
||||||
|
*/
|
||||||
|
set activeClusterId(id : ClusterId) {
|
||||||
|
internalClusterStore.activeCluster = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map of all clusters
|
||||||
|
*/
|
||||||
|
get clusters(): ObservableMap<string, Cluster> {
|
||||||
|
return internalClusterStore.clusters;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get active cluster (a cluster which is currently visible)
|
||||||
|
*/
|
||||||
|
get activeCluster(): Cluster {
|
||||||
|
if (!this.activeClusterId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return this.getById(this.activeClusterId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array of all clusters
|
||||||
|
*/
|
||||||
|
get clustersList(): Cluster[] {
|
||||||
|
return internalClusterStore.clustersList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array of all enabled clusters
|
||||||
|
*/
|
||||||
|
get enabledClustersList(): Cluster[] {
|
||||||
|
return internalClusterStore.enabledClustersList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array of all clusters that have active connection to a Kubernetes cluster
|
||||||
|
*/
|
||||||
|
get connectedClustersList(): Cluster[] {
|
||||||
|
return internalClusterStore.connectedClustersList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get cluster object by cluster id
|
||||||
|
* @param id cluster id
|
||||||
|
*/
|
||||||
|
getById(id: ClusterId): Cluster {
|
||||||
|
return internalClusterStore.getById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all clusters belonging to a workspace
|
||||||
|
* @param workspaceId workspace id
|
||||||
|
*/
|
||||||
|
getByWorkspaceId(workspaceId: string): Cluster[] {
|
||||||
|
return internalClusterStore.getByWorkspaceId(workspaceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add clusters to store
|
||||||
|
* @param models list of cluster models
|
||||||
|
*/
|
||||||
|
addClusters(...models: ClusterModel[]): Cluster[] {
|
||||||
|
return internalClusterStore.addClusters(...models);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a cluster to store
|
||||||
|
* @param model cluster
|
||||||
|
*/
|
||||||
|
addCluster(model: ClusterModel | Cluster): Cluster {
|
||||||
|
return internalClusterStore.addCluster(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a cluster from store
|
||||||
|
* @param model cluster
|
||||||
|
*/
|
||||||
|
async removeCluster(model: ClusterModel) {
|
||||||
|
return this.removeById(model.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a cluster from store by id
|
||||||
|
* @param clusterId cluster id
|
||||||
|
*/
|
||||||
|
async removeById(clusterId: ClusterId) {
|
||||||
|
return internalClusterStore.removeById(clusterId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove all clusters belonging to a workspaces
|
||||||
|
* @param workspaceId workspace id
|
||||||
|
*/
|
||||||
|
removeByWorkspaceId(workspaceId: string) {
|
||||||
|
return internalClusterStore.removeByWorkspaceId(workspaceId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const clusterStore = ClusterStore.getInstance<ClusterStore>();
|
||||||
116
src/extensions/stores/workspace-store.ts
Normal file
116
src/extensions/stores/workspace-store.ts
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
import { Singleton } from "../core-api/utils";
|
||||||
|
import { workspaceStore as internalWorkspaceStore, WorkspaceStore as InternalWorkspaceStore, Workspace, WorkspaceId } from "../../common/workspace-store";
|
||||||
|
import { ObservableMap } from "mobx";
|
||||||
|
|
||||||
|
export { Workspace } from "../../common/workspace-store";
|
||||||
|
export type { WorkspaceId, WorkspaceModel } from "../../common/workspace-store";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores all workspaces
|
||||||
|
*/
|
||||||
|
export class WorkspaceStore extends Singleton {
|
||||||
|
/**
|
||||||
|
* Default workspace id, this workspace is always present
|
||||||
|
*/
|
||||||
|
static readonly defaultId: WorkspaceId = InternalWorkspaceStore.defaultId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Currently active workspace id
|
||||||
|
*/
|
||||||
|
get currentWorkspaceId(): string {
|
||||||
|
return internalWorkspaceStore.currentWorkspaceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set active workspace id
|
||||||
|
*/
|
||||||
|
set currentWorkspaceId(id: string) {
|
||||||
|
internalWorkspaceStore.currentWorkspaceId = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map of all workspaces
|
||||||
|
*/
|
||||||
|
get workspaces(): ObservableMap<string, Workspace> {
|
||||||
|
return internalWorkspaceStore.workspaces;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Currently active workspace
|
||||||
|
*/
|
||||||
|
get currentWorkspace(): Workspace {
|
||||||
|
return internalWorkspaceStore.currentWorkspace;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array of all workspaces
|
||||||
|
*/
|
||||||
|
get workspacesList(): Workspace[] {
|
||||||
|
return internalWorkspaceStore.workspacesList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array of all enabled (visible) workspaces
|
||||||
|
*/
|
||||||
|
get enabledWorkspacesList(): Workspace[] {
|
||||||
|
return internalWorkspaceStore.enabledWorkspacesList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get workspace by id
|
||||||
|
* @param id workspace id
|
||||||
|
*/
|
||||||
|
getById(id: WorkspaceId): Workspace {
|
||||||
|
return internalWorkspaceStore.getById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get workspace by name
|
||||||
|
* @param name workspace name
|
||||||
|
*/
|
||||||
|
getByName(name: string): Workspace {
|
||||||
|
return internalWorkspaceStore.getByName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set active workspace
|
||||||
|
* @param id workspace id
|
||||||
|
*/
|
||||||
|
setActive(id = WorkspaceStore.defaultId) {
|
||||||
|
return internalWorkspaceStore.setActive(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a workspace to store
|
||||||
|
* @param workspace workspace
|
||||||
|
*/
|
||||||
|
addWorkspace(workspace: Workspace) {
|
||||||
|
return internalWorkspaceStore.addWorkspace(workspace);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update a workspace in store
|
||||||
|
* @param workspace workspace
|
||||||
|
*/
|
||||||
|
updateWorkspace(workspace: Workspace) {
|
||||||
|
return internalWorkspaceStore.updateWorkspace(workspace);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove workspace from store
|
||||||
|
* @param workspace workspace
|
||||||
|
*/
|
||||||
|
removeWorkspace(workspace: Workspace) {
|
||||||
|
return internalWorkspaceStore.removeWorkspace(workspace);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove workspace by id
|
||||||
|
* @param id workspace
|
||||||
|
*/
|
||||||
|
removeWorkspaceById(id: WorkspaceId) {
|
||||||
|
return internalWorkspaceStore.removeWorkspaceById(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const workspaceStore = WorkspaceStore.getInstance<WorkspaceStore>();
|
||||||
Loading…
Reference in New Issue
Block a user