1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen 2020-10-30 08:07:16 +02:00
parent 205864f66c
commit a0682302eb
5 changed files with 24 additions and 20 deletions

View File

@ -87,7 +87,7 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
}
}
@observable activeClusterId: ClusterId;
@observable activeCluster: ClusterId;
@observable removedClusters = observable.map<ClusterId, Cluster>();
@observable clusters = observable.map<ClusterId, Cluster>();
@ -110,8 +110,8 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
})
}
@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<ClusterStoreModel> {
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<ClusterStoreModel> {
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<ClusterStoreModel> {
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<ClusterStoreModel> {
}
});
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

View File

@ -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<WorkspaceStoreModel> {
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<WorkspaceStoreModel> {
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<WorkspaceStoreModel> {
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)

View File

@ -97,7 +97,7 @@ export class Cluster implements ClusterModel, ClusterState {
}
}
isManaged(): boolean {
get isManaged(): boolean {
return !!this.ownerRef
}

View File

@ -30,7 +30,7 @@ export class RemoveClusterButton extends React.Component<Props> {
render() {
const { cluster } = this.props;
return (
<Button accent onClick={this.confirmRemoveCluster} className="button-area" disabled={cluster.isManaged()}>
<Button accent onClick={this.confirmRemoveCluster} className="button-area" disabled={cluster.isManaged}>
Remove Cluster
</Button>
);

View File

@ -101,10 +101,11 @@ export class ClustersMenu extends React.Component<Props> {
}
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 (
<div className={cssNames("ClustersMenu flex column", className)}>
<div className="clusters flex column gaps">
@ -113,7 +114,7 @@ export class ClustersMenu extends React.Component<Props> {
{({ innerRef, droppableProps, placeholder }: DroppableProvided) => (
<div ref={innerRef} {...droppableProps}>
{clusters.map((cluster, index) => {
const isActive = cluster.id === clusterStore.activeClusterId;
const isActive = cluster.id === activeClusterId;
return (
<Draggable draggableId={cluster.id} index={index} key={cluster.id}>
{({ draggableProps, dragHandleProps, innerRef }: DraggableProvided) => (
@ -141,7 +142,7 @@ export class ClustersMenu extends React.Component<Props> {
<Tooltip targetId="add-cluster-icon">
<Trans>Add Cluster</Trans>
</Tooltip>
<Icon big material="add" id="add-cluster-icon" disabled={workspace.isManaged()} onClick={this.addCluster}/>
<Icon big material="add" id="add-cluster-icon" disabled={workspace.isManaged} onClick={this.addCluster}/>
{newContexts.size > 0 && (
<Badge className="counter" label={newContexts.size} tooltip={<Trans>new</Trans>}/>
)}