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 removedClusters = observable.map<ClusterId, Cluster>();
@observable clusters = 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 { get activeClusterId() {
return this.getById(this.activeClusterId); return this.activeCluster
} }
@computed get clustersList(): Cluster[] { @computed get clustersList(): Cluster[] {
@ -122,13 +122,17 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
return this.clustersList.filter((c) => c.enabled) return this.clustersList.filter((c) => c.enabled)
} }
@computed get active(): Cluster | null {
return this.getById(this.activeCluster);
}
isActive(id: ClusterId) { isActive(id: ClusterId) {
return this.activeClusterId === id; return this.activeCluster === id;
} }
@action @action
setActive(id: ClusterId) { setActive(id: ClusterId) {
this.activeClusterId = this.clusters.has(id) ? id : null; this.activeCluster = this.clusters.has(id) ? id : null;
} }
@action @action
@ -190,7 +194,7 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
const cluster = this.getById(clusterId); const cluster = this.getById(clusterId);
if (cluster) { if (cluster) {
this.clusters.delete(clusterId); this.clusters.delete(clusterId);
if (this.activeClusterId === clusterId) { if (this.activeCluster === clusterId) {
this.setActive(null); this.setActive(null);
} }
// remove only custom kubeconfigs (pasted as text) // remove only custom kubeconfigs (pasted as text)
@ -220,7 +224,7 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
cluster.updateModel(clusterModel); cluster.updateModel(clusterModel);
} else { } else {
cluster = new Cluster(clusterModel); cluster = new Cluster(clusterModel);
if (!cluster.isManaged()) { if (!cluster.isManaged) {
cluster.enabled = true 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.clusters.replace(newClusters);
this.removedClusters.replace(removedClusters); this.removedClusters.replace(removedClusters);
} }
toJSON(): ClusterStoreModel { toJSON(): ClusterStoreModel {
return toJS({ return toJS({
activeCluster: this.activeClusterId, activeCluster: this.activeCluster,
clusters: this.clustersList.map(cluster => cluster.toJSON()), clusters: this.clustersList.map(cluster => cluster.toJSON()),
}, { }, {
recurseEverything: true recurseEverything: true

View File

@ -41,7 +41,7 @@ export class Workspace implements WorkspaceModel, WorkspaceState {
} }
} }
isManaged(): boolean { get isManaged(): boolean {
return !!this.ownerRef return !!this.ownerRef
} }
@ -92,7 +92,6 @@ export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
registerIpcListener() { registerIpcListener() {
logger.info("[WORKSPACE-STORE] starting to listen state events") logger.info("[WORKSPACE-STORE] starting to listen state events")
ipcRenderer.on("workspace:state", (event, workspaceId: string, state: WorkspaceState) => { ipcRenderer.on("workspace:state", (event, workspaceId: string, state: WorkspaceState) => {
console.log(workspaceId, state)
this.getById(workspaceId)?.setState(state) this.getById(workspaceId)?.setState(state)
}) })
} }
@ -148,7 +147,7 @@ export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
throw new Error(`workspace ${id} doesn't exist`); throw new Error(`workspace ${id} doesn't exist`);
} }
this.currentWorkspaceId = id; 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 @action
@ -197,7 +196,7 @@ export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
this.workspaces.clear(); this.workspaces.clear();
workspaces.forEach(ws => { workspaces.forEach(ws => {
const workspace = new Workspace(ws) const workspace = new Workspace(ws)
if (!workspace.ownerRef) { if (!workspace.isManaged) {
workspace.enabled = true workspace.enabled = true
} }
this.workspaces.set(workspace.id, workspace) 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 return !!this.ownerRef
} }

View File

@ -30,7 +30,7 @@ export class RemoveClusterButton extends React.Component<Props> {
render() { render() {
const { cluster } = this.props; const { cluster } = this.props;
return ( 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 Remove Cluster
</Button> </Button>
); );

View File

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