mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix workspace overview switching and enabled state storage (#2342)
This commit is contained in:
parent
a9a5766920
commit
1aff341f0e
@ -26,6 +26,8 @@ export interface WorkspaceState {
|
|||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const updateFromModel = Symbol("updateFromModel");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Workspace
|
* Workspace
|
||||||
*
|
*
|
||||||
@ -114,7 +116,7 @@ export class Workspace implements WorkspaceModel, WorkspaceState {
|
|||||||
/**
|
/**
|
||||||
* Push state
|
* Push state
|
||||||
*
|
*
|
||||||
* @interal
|
* @internal
|
||||||
* @param state workspace state
|
* @param state workspace state
|
||||||
*/
|
*/
|
||||||
pushState(state = this.getState()) {
|
pushState(state = this.getState()) {
|
||||||
@ -130,6 +132,10 @@ export class Workspace implements WorkspaceModel, WorkspaceState {
|
|||||||
Object.assign(this, state);
|
Object.assign(this, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[updateFromModel] = action((model: WorkspaceModel) => {
|
||||||
|
Object.assign(this, model);
|
||||||
|
});
|
||||||
|
|
||||||
toJSON(): WorkspaceModel {
|
toJSON(): WorkspaceModel {
|
||||||
return toJS({
|
return toJS({
|
||||||
id: this.id,
|
id: this.id,
|
||||||
@ -303,16 +309,26 @@ export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
|
|||||||
this.currentWorkspaceId = currentWorkspace;
|
this.currentWorkspaceId = currentWorkspace;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (workspaces.length) {
|
const currentWorkspaces = this.workspaces.toJS();
|
||||||
this.workspaces.clear();
|
const newWorkspaceIds = new Set<WorkspaceId>([WorkspaceStore.defaultId]); // never delete default
|
||||||
workspaces.forEach(ws => {
|
|
||||||
const workspace = new Workspace(ws);
|
|
||||||
|
|
||||||
if (!workspace.isManaged) {
|
for (const workspaceModel of workspaces) {
|
||||||
workspace.enabled = true;
|
const oldWorkspace = this.workspaces.get(workspaceModel.id);
|
||||||
}
|
|
||||||
this.workspaces.set(workspace.id, workspace);
|
if (oldWorkspace) {
|
||||||
});
|
oldWorkspace[updateFromModel](workspaceModel);
|
||||||
|
} else {
|
||||||
|
this.workspaces.set(workspaceModel.id, new Workspace(workspaceModel));
|
||||||
|
}
|
||||||
|
|
||||||
|
newWorkspaceIds.add(workspaceModel.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove deleted workspaces
|
||||||
|
for (const workspaceId of currentWorkspaces.keys()) {
|
||||||
|
if (!newWorkspaceIds.has(workspaceId)) {
|
||||||
|
this.workspaces.delete(workspaceId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import React from "react";
|
|||||||
import { computed, observable } from "mobx";
|
import { computed, observable } from "mobx";
|
||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import { clusterStore } from "../../../common/cluster-store";
|
import { clusterStore } from "../../../common/cluster-store";
|
||||||
import { Workspace, workspaceStore } from "../../../common/workspace-store";
|
import { workspaceStore } from "../../../common/workspace-store";
|
||||||
import { WorkspaceOverview } from "./workspace-overview";
|
import { WorkspaceOverview } from "./workspace-overview";
|
||||||
import { PageLayout } from "../layout/page-layout";
|
import { PageLayout } from "../layout/page-layout";
|
||||||
import { Notifications } from "../notifications";
|
import { Notifications } from "../notifications";
|
||||||
@ -13,13 +13,9 @@ import { Icon } from "../icon";
|
|||||||
export class LandingPage extends React.Component {
|
export class LandingPage extends React.Component {
|
||||||
@observable showHint = true;
|
@observable showHint = true;
|
||||||
|
|
||||||
get workspace(): Workspace {
|
|
||||||
return workspaceStore.currentWorkspace;
|
|
||||||
}
|
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
get clusters() {
|
get clusters() {
|
||||||
return clusterStore.getByWorkspaceId(this.workspace.id);
|
return clusterStore.getByWorkspaceId(workspaceStore.currentWorkspaceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@ -36,11 +32,11 @@ export class LandingPage extends React.Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const showBackButton = this.clusters.length > 0;
|
const showBackButton = this.clusters.length > 0;
|
||||||
const header = <><Icon svg="logo-lens" big /> <h2>{this.workspace.name}</h2></>;
|
const header = <><Icon svg="logo-lens" big /> <h2>{workspaceStore.currentWorkspace.name}</h2></>;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageLayout className="LandingOverview flex" header={header} provideBackButtonNavigation={showBackButton} showOnTop={true}>
|
<PageLayout className="LandingOverview flex" header={header} provideBackButtonNavigation={showBackButton} showOnTop={true}>
|
||||||
<WorkspaceOverview workspace={this.workspace}/>
|
<WorkspaceOverview />
|
||||||
</PageLayout>
|
</PageLayout>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
import "./workspace-overview.scss";
|
import "./workspace-overview.scss";
|
||||||
|
|
||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import { Workspace } from "../../../common/workspace-store";
|
import { disposeOnUnmount, observer } from "mobx-react";
|
||||||
import { observer } from "mobx-react";
|
|
||||||
import { ItemListLayout } from "../item-object-list/item-list-layout";
|
import { ItemListLayout } from "../item-object-list/item-list-layout";
|
||||||
import { ClusterItem, WorkspaceClusterStore } from "./workspace-cluster.store";
|
import { ClusterItem, WorkspaceClusterStore } from "./workspace-cluster.store";
|
||||||
import { navigate } from "../../navigation";
|
import { navigate } from "../../navigation";
|
||||||
@ -10,9 +9,8 @@ import { clusterViewURL } from "../cluster-manager/cluster-view.route";
|
|||||||
import { WorkspaceClusterMenu } from "./workspace-cluster-menu";
|
import { WorkspaceClusterMenu } from "./workspace-cluster-menu";
|
||||||
import { kebabCase } from "lodash";
|
import { kebabCase } from "lodash";
|
||||||
import { addClusterURL } from "../+add-cluster";
|
import { addClusterURL } from "../+add-cluster";
|
||||||
interface Props {
|
import { observable, reaction } from "mobx";
|
||||||
workspace: Workspace;
|
import { workspaceStore } from "../../../common/workspace-store";
|
||||||
}
|
|
||||||
|
|
||||||
enum sortBy {
|
enum sortBy {
|
||||||
name = "name",
|
name = "name",
|
||||||
@ -22,20 +20,30 @@ enum sortBy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class WorkspaceOverview extends Component<Props> {
|
export class WorkspaceOverview extends Component {
|
||||||
private workspaceClusterStore = new WorkspaceClusterStore(this.props.workspace.id);
|
@observable private workspaceClusterStore?: WorkspaceClusterStore;
|
||||||
|
|
||||||
componentDidMount() {
|
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) => {
|
showCluster = ({ clusterId }: ClusterItem) => {
|
||||||
navigate(clusterViewURL({ params: { clusterId } }));
|
navigate(clusterViewURL({ params: { clusterId } }));
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { workspace } = this.props;
|
const { workspaceClusterStore } = this;
|
||||||
|
|
||||||
|
if (!workspaceClusterStore) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ItemListLayout
|
<ItemListLayout
|
||||||
@ -44,7 +52,7 @@ export class WorkspaceOverview extends Component<Props> {
|
|||||||
isSearchable={false}
|
isSearchable={false}
|
||||||
isSelectable={false}
|
isSelectable={false}
|
||||||
className="WorkspaceOverview"
|
className="WorkspaceOverview"
|
||||||
store={this.workspaceClusterStore}
|
store={workspaceClusterStore}
|
||||||
sortingCallbacks={{
|
sortingCallbacks={{
|
||||||
[sortBy.name]: (item: ClusterItem) => item.name,
|
[sortBy.name]: (item: ClusterItem) => item.name,
|
||||||
[sortBy.distribution]: (item: ClusterItem) => item.distribution,
|
[sortBy.distribution]: (item: ClusterItem) => item.distribution,
|
||||||
@ -69,7 +77,7 @@ export class WorkspaceOverview extends Component<Props> {
|
|||||||
onAdd: () => navigate(addClusterURL()),
|
onAdd: () => navigate(addClusterURL()),
|
||||||
}}
|
}}
|
||||||
renderItemMenu={(clusterItem: ClusterItem) => (
|
renderItemMenu={(clusterItem: ClusterItem) => (
|
||||||
<WorkspaceClusterMenu clusterItem={clusterItem} workspace={workspace} workspaceClusterStore={this.workspaceClusterStore}/>
|
<WorkspaceClusterMenu clusterItem={clusterItem} workspace={workspaceStore.currentWorkspace} workspaceClusterStore={workspaceClusterStore}/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user