1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fix managed Workspaces and overview

- Workspaces that are managed can now be enabled without the store
  removing that flag unconditionally via a roundtrip to the FS

- Workspace overview should be reactive to the current workspace

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-03-16 10:23:22 -04:00
parent a9a5766920
commit 18758bffc2
2 changed files with 34 additions and 23 deletions

View File

@ -114,7 +114,7 @@ export class Workspace implements WorkspaceModel, WorkspaceState {
/**
* Push state
*
* @interal
* @internal
* @param state workspace state
*/
pushState(state = this.getState()) {
@ -130,6 +130,10 @@ export class Workspace implements WorkspaceModel, WorkspaceState {
Object.assign(this, state);
}
@action updateModel(model: WorkspaceModel) {
Object.assign(this, model);
}
toJSON(): WorkspaceModel {
return toJS({
id: this.id,
@ -247,9 +251,10 @@ export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
@action
addWorkspace(workspace: Workspace) {
workspace.name = workspace.name.trim();
const { id, name } = workspace;
if (!name.trim() || this.getByName(name.trim())) {
if (!name || this.getByName(name)) {
return;
}
this.workspaces.set(id, workspace);
@ -303,16 +308,14 @@ export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
this.currentWorkspaceId = currentWorkspace;
}
if (workspaces.length) {
this.workspaces.clear();
workspaces.forEach(ws => {
const workspace = new Workspace(ws);
for (const workspaceModel of workspaces) {
const oldWorkspace = this.workspaces.get(workspaceModel.id);
if (!workspace.isManaged) {
workspace.enabled = true;
}
this.workspaces.set(workspace.id, workspace);
});
if (oldWorkspace) {
oldWorkspace.updateModel(workspaceModel);
} else {
this.workspaces.set(workspaceModel.id, new Workspace(workspaceModel));
}
}
}

View File

@ -1,8 +1,7 @@
import "./workspace-overview.scss";
import React, { Component } from "react";
import { Workspace } from "../../../common/workspace-store";
import { observer } from "mobx-react";
import { disposeOnUnmount, observer } from "mobx-react";
import { ItemListLayout } from "../item-object-list/item-list-layout";
import { ClusterItem, WorkspaceClusterStore } from "./workspace-cluster.store";
import { navigate } from "../../navigation";
@ -10,9 +9,8 @@ import { clusterViewURL } from "../cluster-manager/cluster-view.route";
import { WorkspaceClusterMenu } from "./workspace-cluster-menu";
import { kebabCase } from "lodash";
import { addClusterURL } from "../+add-cluster";
interface Props {
workspace: Workspace;
}
import { observable, reaction } from "mobx";
import { workspaceStore } from "../../../common/workspace-store";
enum sortBy {
name = "name",
@ -22,20 +20,30 @@ enum sortBy {
}
@observer
export class WorkspaceOverview extends Component<Props> {
private workspaceClusterStore = new WorkspaceClusterStore(this.props.workspace.id);
export class WorkspaceOverview extends Component {
@observable private workspaceClusterStore?: WorkspaceClusterStore;
componentDidMount() {
this.workspaceClusterStore.loadAll();
disposeOnUnmount(this, [
reaction(() => workspaceStore.currentWorkspaceId, workspaceId => {
this.workspaceClusterStore = new WorkspaceClusterStore(workspaceId);
this.workspaceClusterStore.loadAll().catch(error => console.log("workspaceClusterStore.loadAll", error));
}, {
fireImmediately: true,
})
]);
}
showCluster = ({ clusterId }: ClusterItem) => {
navigate(clusterViewURL({ params: { clusterId } }));
};
render() {
const { workspace } = this.props;
const { workspaceClusterStore } = this;
if (!workspaceClusterStore) {
return null;
}
return (
<ItemListLayout
@ -44,7 +52,7 @@ export class WorkspaceOverview extends Component<Props> {
isSearchable={false}
isSelectable={false}
className="WorkspaceOverview"
store={this.workspaceClusterStore}
store={workspaceClusterStore}
sortingCallbacks={{
[sortBy.name]: (item: ClusterItem) => item.name,
[sortBy.distribution]: (item: ClusterItem) => item.distribution,
@ -69,7 +77,7 @@ export class WorkspaceOverview extends Component<Props> {
onAdd: () => navigate(addClusterURL()),
}}
renderItemMenu={(clusterItem: ClusterItem) => (
<WorkspaceClusterMenu clusterItem={clusterItem} workspace={workspace} workspaceClusterStore={this.workspaceClusterStore}/>
<WorkspaceClusterMenu clusterItem={clusterItem} workspace={workspaceStore.currentWorkspace} workspaceClusterStore={workspaceClusterStore}/>
)}
/>
);