From a0682302eb28ab714259e448d0a14a3c4b3ace2a Mon Sep 17 00:00:00 2001 From: Jari Kolehmainen Date: Fri, 30 Oct 2020 08:07:16 +0200 Subject: [PATCH] fixes Signed-off-by: Jari Kolehmainen --- src/common/cluster-store.ts | 22 +++++++++++-------- src/common/workspace-store.ts | 7 +++--- src/main/cluster.ts | 2 +- .../components/remove-cluster-button.tsx | 2 +- .../cluster-manager/clusters-menu.tsx | 11 +++++----- 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/common/cluster-store.ts b/src/common/cluster-store.ts index 066bb8f851..543eed512d 100644 --- a/src/common/cluster-store.ts +++ b/src/common/cluster-store.ts @@ -87,7 +87,7 @@ export class ClusterStore extends BaseStore { } } - @observable activeClusterId: ClusterId; + @observable activeCluster: ClusterId; @observable removedClusters = observable.map(); @observable clusters = observable.map(); @@ -110,8 +110,8 @@ export class ClusterStore extends BaseStore { }) } - @computed get activeCluster(): Cluster | null { - return this.getById(this.activeClusterId); + get activeClusterId() { + return this.activeCluster } @computed get clustersList(): Cluster[] { @@ -122,13 +122,17 @@ export class ClusterStore extends BaseStore { return this.clustersList.filter((c) => c.enabled) } + @computed get active(): Cluster | null { + return this.getById(this.activeCluster); + } + isActive(id: ClusterId) { - return this.activeClusterId === id; + return this.activeCluster === id; } @action setActive(id: ClusterId) { - this.activeClusterId = this.clusters.has(id) ? id : null; + this.activeCluster = this.clusters.has(id) ? id : null; } @action @@ -190,7 +194,7 @@ export class ClusterStore extends BaseStore { const cluster = this.getById(clusterId); if (cluster) { this.clusters.delete(clusterId); - if (this.activeClusterId === clusterId) { + if (this.activeCluster === clusterId) { this.setActive(null); } // remove only custom kubeconfigs (pasted as text) @@ -220,7 +224,7 @@ export class ClusterStore extends BaseStore { cluster.updateModel(clusterModel); } else { cluster = new Cluster(clusterModel); - if (!cluster.isManaged()) { + if (!cluster.isManaged) { cluster.enabled = true } } @@ -234,14 +238,14 @@ export class ClusterStore extends BaseStore { } }); - this.activeClusterId = newClusters.has(activeCluster) ? activeCluster : null; + this.activeCluster = newClusters.has(activeCluster) ? activeCluster : null; this.clusters.replace(newClusters); this.removedClusters.replace(removedClusters); } toJSON(): ClusterStoreModel { return toJS({ - activeCluster: this.activeClusterId, + activeCluster: this.activeCluster, clusters: this.clustersList.map(cluster => cluster.toJSON()), }, { recurseEverything: true diff --git a/src/common/workspace-store.ts b/src/common/workspace-store.ts index bc469c3c61..97611a01d3 100644 --- a/src/common/workspace-store.ts +++ b/src/common/workspace-store.ts @@ -41,7 +41,7 @@ export class Workspace implements WorkspaceModel, WorkspaceState { } } - isManaged(): boolean { + get isManaged(): boolean { return !!this.ownerRef } @@ -92,7 +92,6 @@ export class WorkspaceStore extends BaseStore { registerIpcListener() { logger.info("[WORKSPACE-STORE] starting to listen state events") ipcRenderer.on("workspace:state", (event, workspaceId: string, state: WorkspaceState) => { - console.log(workspaceId, state) this.getById(workspaceId)?.setState(state) }) } @@ -148,7 +147,7 @@ export class WorkspaceStore extends BaseStore { throw new Error(`workspace ${id} doesn't exist`); } this.currentWorkspaceId = id; - clusterStore.activeClusterId = null; // fixme: handle previously selected cluster from current workspace + clusterStore.activeCluster = null; // fixme: handle previously selected cluster from current workspace } @action @@ -197,7 +196,7 @@ export class WorkspaceStore extends BaseStore { this.workspaces.clear(); workspaces.forEach(ws => { const workspace = new Workspace(ws) - if (!workspace.ownerRef) { + if (!workspace.isManaged) { workspace.enabled = true } this.workspaces.set(workspace.id, workspace) diff --git a/src/main/cluster.ts b/src/main/cluster.ts index 692ebb2c7c..57b9e219c3 100644 --- a/src/main/cluster.ts +++ b/src/main/cluster.ts @@ -97,7 +97,7 @@ export class Cluster implements ClusterModel, ClusterState { } } - isManaged(): boolean { + get isManaged(): boolean { return !!this.ownerRef } diff --git a/src/renderer/components/+cluster-settings/components/remove-cluster-button.tsx b/src/renderer/components/+cluster-settings/components/remove-cluster-button.tsx index 0231391958..dda3e7c137 100644 --- a/src/renderer/components/+cluster-settings/components/remove-cluster-button.tsx +++ b/src/renderer/components/+cluster-settings/components/remove-cluster-button.tsx @@ -30,7 +30,7 @@ export class RemoveClusterButton extends React.Component { render() { const { cluster } = this.props; return ( - ); diff --git a/src/renderer/components/cluster-manager/clusters-menu.tsx b/src/renderer/components/cluster-manager/clusters-menu.tsx index 2b3bc956e2..3d1e6debaf 100644 --- a/src/renderer/components/cluster-manager/clusters-menu.tsx +++ b/src/renderer/components/cluster-manager/clusters-menu.tsx @@ -101,10 +101,11 @@ export class ClustersMenu extends React.Component { } render() { - const { className } = this.props; - const { newContexts } = userStore; + const { className } = this.props + const { newContexts } = userStore const workspace = workspaceStore.getById(workspaceStore.currentWorkspaceId) - const clusters = clusterStore.getByWorkspaceId(workspaceStore.currentWorkspaceId); + const clusters = clusterStore.getByWorkspaceId(workspace.id) + const activeClusterId = clusterStore.activeCluster return (
@@ -113,7 +114,7 @@ export class ClustersMenu extends React.Component { {({ innerRef, droppableProps, placeholder }: DroppableProvided) => (
{clusters.map((cluster, index) => { - const isActive = cluster.id === clusterStore.activeClusterId; + const isActive = cluster.id === activeClusterId; return ( {({ draggableProps, dragHandleProps, innerRef }: DraggableProvided) => ( @@ -141,7 +142,7 @@ export class ClustersMenu extends React.Component { Add Cluster - + {newContexts.size > 0 && ( new}/> )}