mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Save and restore lastActiveClusterId
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
d723474684
commit
f8841fa0a5
@ -7,10 +7,12 @@ import { broadcastIpc } from "../common/ipc";
|
|||||||
import logger from "../main/logger";
|
import logger from "../main/logger";
|
||||||
|
|
||||||
export type WorkspaceId = string;
|
export type WorkspaceId = string;
|
||||||
|
export type ClusterId = string;
|
||||||
|
|
||||||
export interface WorkspaceStoreModel {
|
export interface WorkspaceStoreModel {
|
||||||
|
workspaces: WorkspaceModel[];
|
||||||
currentWorkspace?: WorkspaceId;
|
currentWorkspace?: WorkspaceId;
|
||||||
workspaces: WorkspaceModel[]
|
lastActiveClusterId?: ClusterId;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface WorkspaceModel {
|
export interface WorkspaceModel {
|
||||||
@ -30,6 +32,7 @@ export class Workspace implements WorkspaceModel, WorkspaceState {
|
|||||||
@observable description?: string
|
@observable description?: string
|
||||||
@observable ownerRef?: string
|
@observable ownerRef?: string
|
||||||
@observable enabled: boolean
|
@observable enabled: boolean
|
||||||
|
@observable lastActiveClusterId?: ClusterId
|
||||||
|
|
||||||
constructor(data: WorkspaceModel) {
|
constructor(data: WorkspaceModel) {
|
||||||
Object.assign(this, data)
|
Object.assign(this, data)
|
||||||
@ -141,13 +144,12 @@ export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
setActive(id = WorkspaceStore.defaultId, reset = true) {
|
setActive(id = WorkspaceStore.defaultId) {
|
||||||
if (id === this.currentWorkspaceId) return;
|
if (id === this.currentWorkspaceId) return;
|
||||||
if (!this.getById(id)) {
|
if (!this.getById(id)) {
|
||||||
throw new Error(`workspace ${id} doesn't exist`);
|
throw new Error(`workspace ${id} doesn't exist`);
|
||||||
}
|
}
|
||||||
this.currentWorkspaceId = id;
|
this.currentWorkspaceId = id;
|
||||||
clusterStore.activeCluster = null; // fixme: handle previously selected cluster from current workspace
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
@ -187,6 +189,13 @@ export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
|
|||||||
clusterStore.removeByWorkspaceId(id)
|
clusterStore.removeByWorkspaceId(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
setLastActiveClusterId(clusterId: ClusterId, workspaceId = this.currentWorkspaceId) {
|
||||||
|
if (clusterId != null) {
|
||||||
|
this.getById(workspaceId).lastActiveClusterId = clusterId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
protected fromStore({ currentWorkspace, workspaces = [] }: WorkspaceStoreModel) {
|
protected fromStore({ currentWorkspace, workspaces = [] }: WorkspaceStoreModel) {
|
||||||
if (currentWorkspace) {
|
if (currentWorkspace) {
|
||||||
|
|||||||
@ -167,6 +167,7 @@ export class AddCluster extends React.Component {
|
|||||||
if (newClusters.length === 1) {
|
if (newClusters.length === 1) {
|
||||||
const clusterId = newClusters[0].id;
|
const clusterId = newClusters[0].id;
|
||||||
clusterStore.setActive(clusterId);
|
clusterStore.setActive(clusterId);
|
||||||
|
workspaceStore.setLastActiveClusterId(clusterId);
|
||||||
navigate(clusterViewURL({ params: { clusterId } }));
|
navigate(clusterViewURL({ params: { clusterId } }));
|
||||||
} else {
|
} else {
|
||||||
if (newClusters.length > 1) {
|
if (newClusters.length > 1) {
|
||||||
|
|||||||
@ -7,8 +7,11 @@ 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 { WorkspaceId, workspaceStore } from "../../../common/workspace-store";
|
||||||
import { cssNames } from "../../utils";
|
import { cssNames } from "../../utils";
|
||||||
|
import { navigate } from "../../navigation";
|
||||||
|
import { clusterViewURL } from "../cluster-manager/cluster-view.route";
|
||||||
|
import { landingURL } from "../+landing-page";
|
||||||
|
|
||||||
interface Props extends Partial<MenuProps> {
|
interface Props extends Partial<MenuProps> {
|
||||||
}
|
}
|
||||||
@ -17,6 +20,16 @@ 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) => {
|
||||||
|
const clusterId = workspaceStore.getById(id).lastActiveClusterId;
|
||||||
|
workspaceStore.setActive(id);
|
||||||
|
if (clusterId) {
|
||||||
|
navigate(clusterViewURL({ params: { clusterId } }));
|
||||||
|
} else {
|
||||||
|
navigate(landingURL());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { className, ...menuProps } = this.props;
|
const { className, ...menuProps } = this.props;
|
||||||
const { enabledWorkspacesList, currentWorkspace } = workspaceStore;
|
const { enabledWorkspacesList, currentWorkspace } = workspaceStore;
|
||||||
@ -38,7 +51,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>
|
||||||
|
|||||||
@ -31,6 +31,7 @@ interface Props {
|
|||||||
@observer
|
@observer
|
||||||
export class ClustersMenu extends React.Component<Props> {
|
export class ClustersMenu extends React.Component<Props> {
|
||||||
showCluster = (clusterId: ClusterId) => {
|
showCluster = (clusterId: ClusterId) => {
|
||||||
|
workspaceStore.setLastActiveClusterId(clusterId);
|
||||||
navigate(clusterViewURL({ params: { clusterId } }));
|
navigate(clusterViewURL({ params: { clusterId } }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +57,11 @@ 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 lastActiveClusterId = workspaceStore.currentWorkspace.lastActiveClusterId;
|
||||||
if (clusterStore.isActive(cluster.id)) {
|
if (clusterStore.isActive(cluster.id)) {
|
||||||
|
if (lastActiveClusterId === cluster.id) {
|
||||||
|
workspaceStore.setLastActiveClusterId("");
|
||||||
|
}
|
||||||
navigate(landingURL());
|
navigate(landingURL());
|
||||||
clusterStore.setActive(null);
|
clusterStore.setActive(null);
|
||||||
}
|
}
|
||||||
@ -74,6 +79,10 @@ export class ClustersMenu extends React.Component<Props> {
|
|||||||
label: _i18n._(t`Remove`),
|
label: _i18n._(t`Remove`),
|
||||||
},
|
},
|
||||||
ok: () => {
|
ok: () => {
|
||||||
|
const lastActiveClusterId = workspaceStore.currentWorkspace.lastActiveClusterId;
|
||||||
|
if (lastActiveClusterId === cluster.id) {
|
||||||
|
workspaceStore.setLastActiveClusterId("");
|
||||||
|
}
|
||||||
if (clusterStore.activeClusterId === cluster.id) {
|
if (clusterStore.activeClusterId === cluster.id) {
|
||||||
navigate(landingURL());
|
navigate(landingURL());
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user