From 17cd886ce6dae78bd2720a4c8e535fa3683b6c87 Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 6 Jul 2020 17:07:17 +0300 Subject: [PATCH] cluster-store refactoring -- part 2 Signed-off-by: Roman --- src/common/cluster-store.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/common/cluster-store.ts b/src/common/cluster-store.ts index 3d7483db09..9a008c9551 100644 --- a/src/common/cluster-store.ts +++ b/src/common/cluster-store.ts @@ -55,6 +55,13 @@ export class ClusterStore extends BaseStore { return toJS(this.data.clusters).map(model => new Cluster(model)); } + @computed get clustersMap(): Map { + return this.clusters.reduce((map, cluster) => { + map.set(cluster.id, cluster); + return map; + }, new Map); + } + getById(clusterId: ClusterId): Cluster { return this.clusters.find(cluster => cluster.id === clusterId) } @@ -79,6 +86,21 @@ export class ClusterStore extends BaseStore { } }) } + + toJSON(): ClusterStoreModel { + const clusters: ClusterModel[] = this.clusters.map(cluster => { + return { + id: cluster.id, + contextName: cluster.contextName, + kubeConfigPath: cluster.kubeConfigPath, + preferences: cluster.preferences, + workspace: cluster.workspace, + } + }) + return { + clusters + } + } } export const clusterStore: ClusterStore = ClusterStore.getInstance();