From 66a3746d422de0bbfd61aaa838f50dc5f59fccbb Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Thu, 26 Nov 2020 12:33:52 -0500 Subject: [PATCH] change to getting instance itself in helper functions Signed-off-by: Sebastian Malton --- src/common/cluster-store.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/common/cluster-store.ts b/src/common/cluster-store.ts index b9d77bd2de..c914c42d74 100644 --- a/src/common/cluster-store.ts +++ b/src/common/cluster-store.ts @@ -182,10 +182,10 @@ export class ClusterStore extends BaseStore { } move.mutate(clusters, from, to); - for (const i in clusters) { - // This resets the iconOrder to the current display order - clusters[i].preferences.iconOrder = +i; - } + clusters.map((cluster, index) => { + cluster.preferences ??= {}; + cluster.preferences.iconOrder = index; + }); } hasClusters() { @@ -336,8 +336,11 @@ export class ClusterStore extends BaseStore { export const clusterStore = ClusterStore.getInstance(); export function getRendererInfoByWorkspace(workspaceId: string): ClusterRenderInfo[] { - const aliveClusters: ClusterRenderInfo[] = clusterStore.clustersList.filter(c => c.workspace === workspaceId); - const deadClusters: ClusterRenderInfo[] = clusterStore.deadClustersList + const aliveClusters: ClusterRenderInfo[] = ClusterStore.getInstance() + .clustersList + .filter(c => c.workspace === workspaceId); + const deadClusters: ClusterRenderInfo[] = ClusterStore.getInstance() + .deadClustersList .filter(([c]) => c.workspace === workspaceId) .map(([cluster, error]) => ({ DeadError: error, @@ -350,8 +353,11 @@ export function getRendererInfoByWorkspace(workspaceId: string): ClusterRenderIn } export function getClusterModelByWorkspace(workspaceId: string): ClusterModel[] { - const aliveClusters: ClusterModel[] = clusterStore.clustersList.filter(c => c.workspace === workspaceId); - const deadClusters: ClusterModel[] = clusterStore.deadClustersList + const aliveClusters: ClusterModel[] = ClusterStore.getInstance() + .clustersList + .filter(c => c.workspace === workspaceId); + const deadClusters: ClusterModel[] = ClusterStore.getInstance() + .deadClustersList .filter(([c]) => c.workspace === workspaceId) .map(([cluster]) => cluster); @@ -372,5 +378,5 @@ export function getHostedClusterId() { } export function getHostedCluster(): Cluster { - return clusterStore.getById(getHostedClusterId()); + return ClusterStore.getInstance().getById(getHostedClusterId()); }