mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Issue-827: Enhancement to bring back last active cluster view
This enhancement will store the last active cluster used in a workspace. If you then switch to a different workspace and switch back the cluster view will be restored Signed-off-by: Steve Richards <srichards@mirantis.com>
This commit is contained in:
parent
abe6a4e0b1
commit
d8f972a02e
@ -3,8 +3,10 @@ import { BaseStore } from "./base-store";
|
|||||||
import { clusterStore } from "./cluster-store"
|
import { clusterStore } from "./cluster-store"
|
||||||
import { landingURL } from "../renderer/components/+landing-page/landing-page.route";
|
import { landingURL } from "../renderer/components/+landing-page/landing-page.route";
|
||||||
import { navigate } from "../renderer/navigation";
|
import { navigate } from "../renderer/navigation";
|
||||||
|
import { clusterViewURL } from "../renderer/components/cluster-manager/cluster-view.route";
|
||||||
|
|
||||||
export type WorkspaceId = string;
|
export type WorkspaceId = string;
|
||||||
|
export type ClusterId = string;
|
||||||
|
|
||||||
export interface WorkspaceStoreModel {
|
export interface WorkspaceStoreModel {
|
||||||
currentWorkspace?: WorkspaceId;
|
currentWorkspace?: WorkspaceId;
|
||||||
@ -15,6 +17,7 @@ export interface Workspace {
|
|||||||
id: WorkspaceId;
|
id: WorkspaceId;
|
||||||
name: string;
|
name: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
|
lastActiveClusterId?: ClusterId;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
|
export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
|
||||||
@ -31,7 +34,8 @@ export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
|
|||||||
@observable workspaces = observable.map<WorkspaceId, Workspace>({
|
@observable workspaces = observable.map<WorkspaceId, Workspace>({
|
||||||
[WorkspaceStore.defaultId]: {
|
[WorkspaceStore.defaultId]: {
|
||||||
id: WorkspaceStore.defaultId,
|
id: WorkspaceStore.defaultId,
|
||||||
name: "default"
|
name: "default",
|
||||||
|
lastActiveClusterId: ""
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -55,18 +59,36 @@ export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
|
|||||||
return this.workspacesList.find(workspace => workspace.name === name);
|
return this.workspacesList.find(workspace => workspace.name === name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
setLastActiveClusterId(id: WorkspaceId, clusterId: ClusterId) {
|
||||||
|
if (clusterId != null) {
|
||||||
|
this.getById(id).lastActiveClusterId = clusterId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
setActive(id = WorkspaceStore.defaultId, { redirectToLanding = true, resetActiveCluster = true } = {}) {
|
setActive(id = WorkspaceStore.defaultId, { redirectToLanding = true, resetActiveCluster = true } = {}) {
|
||||||
|
this.setLastActiveClusterId(this.currentWorkspaceId, clusterStore.activeClusterId)
|
||||||
|
|
||||||
if (id === this.currentWorkspaceId) return;
|
if (id === this.currentWorkspaceId) return;
|
||||||
if (!this.getById(id)) {
|
const workspaceToUse = this.getById(id);
|
||||||
|
|
||||||
|
if (!workspaceToUse) {
|
||||||
throw new Error(`workspace ${id} doesn't exist`);
|
throw new Error(`workspace ${id} doesn't exist`);
|
||||||
}
|
}
|
||||||
this.currentWorkspaceId = id;
|
|
||||||
|
this.currentWorkspaceId = workspaceToUse.id;
|
||||||
|
const clusterId = workspaceToUse.lastActiveClusterId;
|
||||||
if (resetActiveCluster) {
|
if (resetActiveCluster) {
|
||||||
clusterStore.setActive(null)
|
if (clusterId) {
|
||||||
}
|
clusterStore.setActive(clusterId)
|
||||||
if (redirectToLanding) {
|
navigate(clusterViewURL({ params: { clusterId } }));
|
||||||
navigate(landingURL())
|
} else {
|
||||||
|
clusterStore.setActive(null)
|
||||||
|
if (redirectToLanding) {
|
||||||
|
navigate(landingURL())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -146,7 +146,9 @@ export class AddCluster extends React.Component {
|
|||||||
clusterStore.addCluster(...newClusters);
|
clusterStore.addCluster(...newClusters);
|
||||||
if (newClusters.length === 1) {
|
if (newClusters.length === 1) {
|
||||||
const clusterId = newClusters[0].id;
|
const clusterId = newClusters[0].id;
|
||||||
|
const wsId = workspaceStore.currentWorkspace.id;
|
||||||
clusterStore.setActive(clusterId);
|
clusterStore.setActive(clusterId);
|
||||||
|
workspaceStore.setLastActiveClusterId(wsId, clusterStore.activeClusterId);
|
||||||
navigate(clusterViewURL({ params: { clusterId } }));
|
navigate(clusterViewURL({ params: { clusterId } }));
|
||||||
} else {
|
} else {
|
||||||
Notifications.ok(
|
Notifications.ok(
|
||||||
|
|||||||
@ -7,8 +7,9 @@ import { Trans } from "@lingui/macro";
|
|||||||
import { Menu, MenuItem, MenuProps } from "../menu";
|
import { Menu, MenuItem, MenuProps } from "../menu";
|
||||||
import { Icon } from "../icon";
|
import { Icon } from "../icon";
|
||||||
import { observable } from "mobx";
|
import { observable } from "mobx";
|
||||||
import { workspaceStore } from "../../../common/workspace-store";
|
import { workspaceStore, WorkspaceId } from "../../../common/workspace-store";
|
||||||
import { cssNames } from "../../utils";
|
import { cssNames } from "../../utils";
|
||||||
|
import { clusterStore } from "../../../common/cluster-store";
|
||||||
|
|
||||||
interface Props extends Partial<MenuProps> {
|
interface Props extends Partial<MenuProps> {
|
||||||
}
|
}
|
||||||
@ -17,6 +18,13 @@ interface Props extends Partial<MenuProps> {
|
|||||||
export class WorkspaceMenu extends React.Component<Props> {
|
export class WorkspaceMenu extends React.Component<Props> {
|
||||||
@observable menuVisible = false;
|
@observable menuVisible = false;
|
||||||
|
|
||||||
|
activateWorkspace = (id: WorkspaceId) => {
|
||||||
|
if (clusterStore.activeClusterId) {
|
||||||
|
workspaceStore.setLastActiveClusterId(workspaceStore.currentWorkspace.id, clusterStore.activeClusterId);
|
||||||
|
}
|
||||||
|
workspaceStore.setActive(id);
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { className, ...menuProps } = this.props;
|
const { className, ...menuProps } = this.props;
|
||||||
const { workspacesList, currentWorkspace } = workspaceStore;
|
const { workspacesList, currentWorkspace } = workspaceStore;
|
||||||
@ -38,7 +46,7 @@ export class WorkspaceMenu extends React.Component<Props> {
|
|||||||
key={workspaceId}
|
key={workspaceId}
|
||||||
title={description}
|
title={description}
|
||||||
active={workspaceId === currentWorkspace.id}
|
active={workspaceId === currentWorkspace.id}
|
||||||
onClick={() => workspaceStore.setActive(workspaceId)}
|
onClick={() => this.activateWorkspace(workspaceId)}
|
||||||
>
|
>
|
||||||
<Icon small material="layers"/>
|
<Icon small material="layers"/>
|
||||||
<span className="workspace">{name}</span>
|
<span className="workspace">{name}</span>
|
||||||
|
|||||||
@ -54,6 +54,7 @@ export class Workspaces extends React.Component {
|
|||||||
id: workspaceId,
|
id: workspaceId,
|
||||||
name: "",
|
name: "",
|
||||||
description: "",
|
description: "",
|
||||||
|
lastActiveClusterId: ""
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -29,6 +29,10 @@ interface Props {
|
|||||||
@observer
|
@observer
|
||||||
export class ClustersMenu extends React.Component<Props> {
|
export class ClustersMenu extends React.Component<Props> {
|
||||||
showCluster = (clusterId: ClusterId) => {
|
showCluster = (clusterId: ClusterId) => {
|
||||||
|
const wsId = workspaceStore.currentWorkspace.id;
|
||||||
|
if(clusterId) {
|
||||||
|
workspaceStore.setLastActiveClusterId(wsId, clusterId);
|
||||||
|
}
|
||||||
clusterStore.setActive(clusterId);
|
clusterStore.setActive(clusterId);
|
||||||
navigate(clusterViewURL({ params: { clusterId } }));
|
navigate(clusterViewURL({ params: { clusterId } }));
|
||||||
}
|
}
|
||||||
@ -57,7 +61,12 @@ export class ClustersMenu extends React.Component<Props> {
|
|||||||
menu.append(new MenuItem({
|
menu.append(new MenuItem({
|
||||||
label: _i18n._(t`Disconnect`),
|
label: _i18n._(t`Disconnect`),
|
||||||
click: async () => {
|
click: async () => {
|
||||||
|
const wsId = workspaceStore.currentWorkspace.id;
|
||||||
|
const wsLastActiveClusterId = workspaceStore.currentWorkspace.lastActiveClusterId
|
||||||
if (clusterStore.isActive(cluster.id)) {
|
if (clusterStore.isActive(cluster.id)) {
|
||||||
|
if (wsLastActiveClusterId === cluster.id) {
|
||||||
|
workspaceStore.setLastActiveClusterId(wsId, "");
|
||||||
|
}
|
||||||
navigate(landingURL());
|
navigate(landingURL());
|
||||||
clusterStore.setActive(null);
|
clusterStore.setActive(null);
|
||||||
}
|
}
|
||||||
@ -75,6 +84,12 @@ export class ClustersMenu extends React.Component<Props> {
|
|||||||
label: _i18n._(t`Remove`),
|
label: _i18n._(t`Remove`),
|
||||||
},
|
},
|
||||||
ok: () => {
|
ok: () => {
|
||||||
|
const wsId = workspaceStore.currentWorkspace.id;
|
||||||
|
const wsLastActiveClusterId = workspaceStore.currentWorkspace.lastActiveClusterId
|
||||||
|
|
||||||
|
if (wsLastActiveClusterId === cluster.id) {
|
||||||
|
workspaceStore.setLastActiveClusterId(wsId, "");
|
||||||
|
}
|
||||||
if (clusterStore.activeClusterId === cluster.id) {
|
if (clusterStore.activeClusterId === cluster.id) {
|
||||||
navigate(landingURL());
|
navigate(landingURL());
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user