1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2020-09-12 16:19:37 +03:00
parent 5a53259873
commit 989beaede2

View File

@ -4,7 +4,6 @@ import React from "react";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import { _i18n } from "../../i18n"; import { _i18n } from "../../i18n";
import { t, Trans } from "@lingui/macro"; import { t, Trans } from "@lingui/macro";
import type { Cluster } from "../../../main/cluster";
import { userStore } from "../../../common/user-store"; import { userStore } from "../../../common/user-store";
import { ClusterId, clusterStore } from "../../../common/cluster-store"; import { ClusterId, clusterStore } from "../../../common/cluster-store";
import { workspaceStore } from "../../../common/workspace-store"; import { workspaceStore } from "../../../common/workspace-store";
@ -12,16 +11,16 @@ import { ClusterIcon } from "../cluster-icon";
import { Icon } from "../icon"; import { Icon } from "../icon";
import { cssNames, IClassName, autobind } from "../../utils"; import { cssNames, IClassName, autobind } from "../../utils";
import { Badge } from "../badge"; import { Badge } from "../badge";
import { navigate, navigation } from "../../navigation"; import { navigate } from "../../navigation";
import { addClusterURL } from "../+add-cluster"; import { addClusterURL } from "../+add-cluster";
import { clusterSettingsURL, clusterSettingsRoute } from "../+cluster-settings"; import { clusterSettingsURL } from "../+cluster-settings";
import { landingURL } from "../+landing-page"; import { landingURL } from "../+landing-page";
import { Tooltip } from "../tooltip"; import { Tooltip } from "../tooltip";
import { ConfirmDialog } from "../confirm-dialog"; import { ConfirmDialog } from "../confirm-dialog";
import { clusterIpc } from "../../../common/cluster-ipc"; import { clusterIpc } from "../../../common/cluster-ipc";
import { clusterViewURL, clusterViewRoute } from "./cluster-view.route"; import { clusterViewURL } from "./cluster-view.route";
import { DragDropContext, Droppable, Draggable, DropResult, DroppableProvided, DraggableProvided } from "react-beautiful-dnd"; import { DragDropContext, Droppable, Draggable, DropResult, DroppableProvided, DraggableProvided } from "react-beautiful-dnd";
import { matchPath } from "react-router"; import type { Cluster } from "../../../main/cluster";
interface Props { interface Props {
className?: IClassName; className?: IClassName;
@ -36,6 +35,7 @@ export class ClustersMenu extends React.Component<Props> {
addCluster = () => { addCluster = () => {
navigate(addClusterURL()); navigate(addClusterURL());
clusterStore.setActive(null);
} }
showContextMenu = (cluster: Cluster) => { showContextMenu = (cluster: Cluster) => {
@ -59,6 +59,7 @@ export class ClustersMenu extends React.Component<Props> {
click: async () => { click: async () => {
if (clusterStore.isActive(cluster.id)) { if (clusterStore.isActive(cluster.id)) {
navigate(landingURL()); navigate(landingURL());
clusterStore.setActive(null);
} }
await clusterIpc.disconnect.invokeFromRenderer(cluster.id); await clusterIpc.disconnect.invokeFromRenderer(cluster.id);
} }
@ -103,7 +104,6 @@ export class ClustersMenu extends React.Component<Props> {
render() { render() {
const { className } = this.props; const { className } = this.props;
const { newContexts } = userStore; const { newContexts } = userStore;
const { activeClusterId } = clusterStore;
const clusters = clusterStore.getByWorkspaceId(workspaceStore.currentWorkspaceId); const clusters = clusterStore.getByWorkspaceId(workspaceStore.currentWorkspaceId);
return ( return (
<div className={cssNames("ClustersMenu flex column", className)}> <div className={cssNames("ClustersMenu flex column", className)}>
@ -116,11 +116,7 @@ export class ClustersMenu extends React.Component<Props> {
{...provided.droppableProps} {...provided.droppableProps}
> >
{clusters.map((cluster, index) => { {clusters.map((cluster, index) => {
const matched = matchPath(navigation.location.pathname, { const isActive = cluster.id === clusterStore.activeClusterId;
path: [clusterViewRoute.path, clusterSettingsRoute.path].flat(),
exact: true
})
const isActive = activeClusterId === cluster.id && !!matched;
return ( return (
<Draggable draggableId={cluster.id} index={index} key={cluster.id}> <Draggable draggableId={cluster.id} index={index} key={cluster.id}>
{(provided: DraggableProvided) => ( {(provided: DraggableProvided) => (