import "./clusters-menu.scss"; import React from "react"; import { remote } from "electron"; import { requestMain } from "../../../common/ipc"; import type { Cluster } from "../../../main/cluster"; import { DragDropContext, Draggable, DraggableProvided, Droppable, DroppableProvided, DropResult } from "react-beautiful-dnd"; import { observer } from "mobx-react"; import { ClusterId, clusterStore } from "../../../common/cluster-store"; import { workspaceStore } from "../../../common/workspace-store"; import { ClusterIcon } from "../cluster-icon"; import { Icon } from "../icon"; import { autobind, cssNames, IClassName } from "../../utils"; import { isActiveRoute, navigate } from "../../navigation"; import { addClusterURL } from "../+add-cluster"; import { clusterSettingsURL } from "../+cluster-settings"; import { landingURL } from "../+landing-page"; import { ConfirmDialog } from "../confirm-dialog"; import { clusterViewURL } from "./cluster-view.route"; import { getExtensionPageUrl, globalPageMenuRegistry, globalPageRegistry } from "../../../extensions/registries"; import { clusterDisconnectHandler } from "../../../common/cluster-ipc"; import { commandRegistry } from "../../../extensions/registries/command-registry"; import { CommandOverlay } from "../command-palette/command-container"; import { computed, observable } from "mobx"; import { Select } from "../select"; import { Menu, MenuItem } from "../menu"; interface Props { className?: IClassName; } @observer export class ClustersMenu extends React.Component { @observable workspaceMenuVisible = false; showCluster = (clusterId: ClusterId) => { navigate(clusterViewURL({ params: { clusterId } })); }; showContextMenu = (cluster: Cluster) => { const { Menu, MenuItem } = remote; const menu = new Menu(); menu.append(new MenuItem({ label: `Settings`, click: () => { navigate(clusterSettingsURL({ params: { clusterId: cluster.id } })); } })); if (cluster.online) { menu.append(new MenuItem({ label: `Disconnect`, click: async () => { if (clusterStore.isActive(cluster.id)) { navigate(landingURL()); clusterStore.setActive(null); } await requestMain(clusterDisconnectHandler, cluster.id); } })); } if (!cluster.isManaged) { menu.append(new MenuItem({ label: `Remove`, click: () => { ConfirmDialog.open({ okButtonProps: { primary: false, accent: true, label: `Remove`, }, ok: () => { if (clusterStore.activeClusterId === cluster.id) { navigate(landingURL()); clusterStore.setActive(null); } clusterStore.removeById(cluster.id); }, message:

Are you sure want to remove cluster {cluster.contextName}?

, }); } })); } menu.popup({ window: remote.getCurrentWindow() }); }; @autobind() swapClusterIconOrder(result: DropResult) { if (result.reason === "DROP") { const { currentWorkspaceId } = workspaceStore; const { source: { index: from }, destination: { index: to }, } = result; clusterStore.swapIconOrders(currentWorkspaceId, from, to); } } render() { const { className } = this.props; const workspace = workspaceStore.getById(workspaceStore.currentWorkspaceId); const clusters = clusterStore.getByWorkspaceId(workspace.id).filter(cluster => cluster.enabled); const activeClusterId = clusterStore.activeCluster; return (
{({ innerRef, droppableProps, placeholder }: DroppableProvided) => (
{clusters.map((cluster, index) => { const isActive = cluster.id === activeClusterId; return ( {({ draggableProps, dragHandleProps, innerRef }: DraggableProvided) => (
this.showCluster(cluster.id)} onContextMenu={() => this.showContextMenu(cluster)} />
)}
); })} {placeholder}
)}
this.workspaceMenuVisible = true} close={() => this.workspaceMenuVisible = false} toggleEvent="click" > navigate(addClusterURL())} data-test-id="add-cluster-menu-item"> Add Cluster navigate(landingURL())} data-test-id="workspace-overview-menu-item"> Workspace Overview
{globalPageMenuRegistry.getItems().map(({ title, target, components: { Icon } }) => { const registeredPage = globalPageRegistry.getByPageTarget(target); if (!registeredPage){ return; } const pageUrl = getExtensionPageUrl(target); const isActive = isActiveRoute(registeredPage.url); return ( navigate(pageUrl)} /> ); })}
); } } @observer export class ChooseCluster extends React.Component { @computed get options() { const clusters = clusterStore.getByWorkspaceId(workspaceStore.currentWorkspaceId).filter(cluster => cluster.enabled); const options = clusters.map((cluster) => { return { value: cluster.id, label: cluster.name }; }); return options; } onChange(clusterId: string) { navigate(clusterViewURL({ params: { clusterId } })); CommandOverlay.close(); } render() { return (