mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
* wip: command palette Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * register shortcut to global menu Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * introduce openCommandDialog & closeCommandDialog Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix ipc broadcast to frames from renderer Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * tweak Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * add more commands Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * cleanup Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * ipc fix Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * add integration tests Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * ipc fix Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * implement workspace edit Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * workspace edit fixes Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * make tests green Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fixes from code review Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * cleanup ipc Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * cleanup CommandRegistry Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * ipc fix Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix ClusterManager cluster auto-init Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * ensure cluster view is active before sending a command Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * switch to last active cluster when workspace change Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * tweak integration tests Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * run integration tests serially Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * cleanup Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fixes based on code review Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * cleanup Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * cleanup more Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * cleanup Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * add workspace fixes Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * cleanup Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
223 lines
7.3 KiB
TypeScript
223 lines
7.3 KiB
TypeScript
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 { userStore } from "../../../common/user-store";
|
|
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 { Badge } from "../badge";
|
|
import { isActiveRoute, navigate } from "../../navigation";
|
|
import { addClusterURL } from "../+add-cluster";
|
|
import { clusterSettingsURL } from "../+cluster-settings";
|
|
import { landingURL } from "../+landing-page";
|
|
import { Tooltip } from "../tooltip";
|
|
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 } from "mobx";
|
|
import { Select } from "../select";
|
|
|
|
interface Props {
|
|
className?: IClassName;
|
|
}
|
|
|
|
@observer
|
|
export class ClustersMenu extends React.Component<Props> {
|
|
showCluster = (clusterId: ClusterId) => {
|
|
navigate(clusterViewURL({ params: { clusterId } }));
|
|
};
|
|
|
|
addCluster = () => {
|
|
navigate(addClusterURL());
|
|
};
|
|
|
|
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: <p>Are you sure want to remove cluster <b title={cluster.id}>{cluster.contextName}</b>?</p>,
|
|
});
|
|
}
|
|
}));
|
|
}
|
|
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 { newContexts } = userStore;
|
|
const workspace = workspaceStore.getById(workspaceStore.currentWorkspaceId);
|
|
const clusters = clusterStore.getByWorkspaceId(workspace.id).filter(cluster => cluster.enabled);
|
|
const activeClusterId = clusterStore.activeCluster;
|
|
|
|
return (
|
|
<div className={cssNames("ClustersMenu flex column", className)}>
|
|
<div className="clusters flex column gaps">
|
|
<DragDropContext onDragEnd={this.swapClusterIconOrder}>
|
|
<Droppable droppableId="cluster-menu" type="CLUSTER">
|
|
{({ innerRef, droppableProps, placeholder }: DroppableProvided) => (
|
|
<div ref={innerRef} {...droppableProps}>
|
|
{clusters.map((cluster, index) => {
|
|
const isActive = cluster.id === activeClusterId;
|
|
|
|
return (
|
|
<Draggable draggableId={cluster.id} index={index} key={cluster.id}>
|
|
{({ draggableProps, dragHandleProps, innerRef }: DraggableProvided) => (
|
|
<div ref={innerRef} {...draggableProps} {...dragHandleProps}>
|
|
<ClusterIcon
|
|
key={cluster.id}
|
|
showErrors={true}
|
|
cluster={cluster}
|
|
isActive={isActive}
|
|
onClick={() => this.showCluster(cluster.id)}
|
|
onContextMenu={() => this.showContextMenu(cluster)}
|
|
/>
|
|
</div>
|
|
)}
|
|
</Draggable>
|
|
);
|
|
})}
|
|
{placeholder}
|
|
</div>
|
|
)}
|
|
</Droppable>
|
|
</DragDropContext>
|
|
</div>
|
|
<div className="add-cluster">
|
|
<Tooltip targetId="add-cluster-icon">
|
|
Add Cluster
|
|
</Tooltip>
|
|
<Icon big material="add" id="add-cluster-icon" disabled={workspace.isManaged} onClick={this.addCluster}/>
|
|
{newContexts.size > 0 && (
|
|
<Badge className="counter" label={newContexts.size} tooltip="new"/>
|
|
)}
|
|
</div>
|
|
<div className="extensions">
|
|
{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 (
|
|
<Icon
|
|
key={pageUrl}
|
|
tooltip={title}
|
|
active={isActive}
|
|
onClick={() => navigate(pageUrl)}
|
|
/>
|
|
);
|
|
})}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
@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 (
|
|
<Select
|
|
onChange={(v) => this.onChange(v.value)}
|
|
components={{ DropdownIndicator: null, IndicatorSeparator: null }}
|
|
menuIsOpen={true}
|
|
options={this.options}
|
|
autoFocus={true}
|
|
escapeClearsValue={false}
|
|
placeholder="Switch to cluster" />
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
commandRegistry.add({
|
|
id: "workspace.chooseCluster",
|
|
title: "Workspace: Switch to cluster ...",
|
|
scope: "global",
|
|
action: () => CommandOverlay.open(<ChooseCluster />)
|
|
});
|