From a4ba77c58bbb592a518f62fd5dd5f879e43aa44e Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Tue, 30 Mar 2021 10:13:15 -0400 Subject: [PATCH] Restrict extension version of ClusterStore (#2256) --- src/common/__tests__/cluster-store.test.ts | 4 ++-- src/common/cluster-store.ts | 12 ++++++++---- src/extensions/stores/cluster-store.ts | 12 ++++-------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/common/__tests__/cluster-store.test.ts b/src/common/__tests__/cluster-store.test.ts index d1d2f76603..1183454d7b 100644 --- a/src/common/__tests__/cluster-store.test.ts +++ b/src/common/__tests__/cluster-store.test.ts @@ -99,7 +99,7 @@ describe("empty config", () => { it("removes cluster from store", async () => { await clusterStore.removeById("foo"); - expect(clusterStore.getById("foo")).toBeUndefined(); + expect(clusterStore.getById("foo")).toBeNull(); }); it("sets active cluster", () => { @@ -248,7 +248,7 @@ describe("config with existing clusters", () => { expect(storedCluster).toBeTruthy(); const storedCluster2 = clusterStore.getById("cluster2"); - expect(storedCluster2).toBeUndefined(); + expect(storedCluster2).toBeNull(); }); it("allows getting all of the clusters", async () => { diff --git a/src/common/cluster-store.ts b/src/common/cluster-store.ts index d1006f0a3d..4ac0ad9bdf 100644 --- a/src/common/cluster-store.ts +++ b/src/common/cluster-store.ts @@ -218,8 +218,12 @@ export class ClusterStore extends BaseStore { } @action - setActive(id: ClusterId) { - const clusterId = this.clusters.has(id) ? id : null; + setActive(clusterId: ClusterId) { + const cluster = this.clusters.get(clusterId); + + if (!cluster?.enabled) { + clusterId = null; + } this.activeCluster = clusterId; workspaceStore.setLastActiveClusterId(clusterId); @@ -251,8 +255,8 @@ export class ClusterStore extends BaseStore { return this.clusters.size > 0; } - getById(id: ClusterId): Cluster { - return this.clusters.get(id); + getById(id: ClusterId): Cluster | null { + return this.clusters.get(id) ?? null; } getByWorkspaceId(workspaceId: string): Cluster[] { diff --git a/src/extensions/stores/cluster-store.ts b/src/extensions/stores/cluster-store.ts index b2aba41c06..c1a18c453b 100644 --- a/src/extensions/stores/cluster-store.ts +++ b/src/extensions/stores/cluster-store.ts @@ -25,7 +25,7 @@ export class ClusterStore extends Singleton { * Set active cluster id */ set activeClusterId(id : ClusterId) { - internalClusterStore.activeCluster = id; + internalClusterStore.setActive(id); } /** @@ -38,12 +38,8 @@ export class ClusterStore extends Singleton { /** * Get active cluster (a cluster which is currently visible) */ - get activeCluster(): Cluster { - if (!this.activeClusterId) { - return null; - } - - return this.getById(this.activeClusterId); + get activeCluster(): Cluster | null { + return internalClusterStore.active; } /** @@ -104,7 +100,7 @@ export class ClusterStore extends Singleton { * @param model cluster */ async removeCluster(model: ClusterModel) { - return this.removeById(model.id); + return internalClusterStore.removeById(model.id); } /**