mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
* A bit of cleaning in Add Cluster page Signed-off-by: alexfront <alex.andreev.email@gmail.com> * Adding head-col to WizardLayout Signed-off-by: alexfront <alex.andreev.email@gmail.com> * Fixing Cluster Settings general layout bugs Signed-off-by: alexfront <alex.andreev.email@gmail.com> * Cluster Status view refactoring Signed-off-by: alexfront <alex.andreev.email@gmail.com> * Install Metrics component refactoring Using notifications for error, removed picking button icon method, simplified button generation. Signed-off-by: alexfront <alex.andreev.email@gmail.com> * Remove icons / checks from RemoveClusterButton Signed-off-by: alexfront <alex.andreev.email@gmail.com> * Fixing colorError in Input styles Signed-off-by: alexfront <alex.andreev.email@gmail.com> * Preventing Input's spellchecking Signed-off-by: alexfront <alex.andreev.email@gmail.com> * ClusterNameSettings refactoring Signed-off-by: alexfront <alex.andreev.email@gmail.com> * ClusterWorkspaceSettings refactoring/fixing Signed-off-by: alexfront <alex.andreev.email@gmail.com> * ClusterProxySetting refactoring Signed-off-by: alexfront <alex.andreev.email@gmail.com> * ClusterPrometheusSetting refactoring Signed-off-by: alexfront <alex.andreev.email@gmail.com> * Clean up Removal section Signed-off-by: alexfront <alex.andreev.email@gmail.com> * Glued InstallMetrics & InstallUserMode into 1 component Signed-off-by: alexfront <alex.andreev.email@gmail.com> * Removing unused styles in Cluster Settings Signed-off-by: alexfront <alex.andreev.email@gmail.com> * Cluster Settings styling Signed-off-by: alexfront <alex.andreev.email@gmail.com> * Adding close button to settings header Signed-off-by: alexfront <alex.andreev.email@gmail.com> * ClusterHomeDirSetting refactoring Signed-off-by: alexfront <alex.andreev.email@gmail.com> * FilePicker restyling Signed-off-by: alexfront <alex.andreev.email@gmail.com> * Fixing Prometheus selector Signed-off-by: alexfront <alex.andreev.email@gmail.com> * Fixing Hashicon Passing cluster name instead of cluster id to prevent icon changing while typing new cluster name Signed-off-by: alexfront <alex.andreev.email@gmail.com> * Minor ClusterSettings fixes Signed-off-by: alexfront <alex.andreev.email@gmail.com> * Increasing opacity for non-interactive icons Signed-off-by: alexfront <alex.andreev.email@gmail.com> * Keep feature install loading state Waiting for props to change before disabling loading state (gray button width spinner) Signed-off-by: alexfront <alex.andreev.email@gmail.com> * Remove arrays in disposeOnUnmount() Signed-off-by: alexfront <alex.andreev.email@gmail.com> * Fix Cluster select behavior Now clicking cluster icon in sidebar always leads to / dashboard. And 'Settings' submenu switches active cluster at first and only the showing Cluster Settings Signed-off-by: alexfront <alex.andreev.email@gmail.com> * Using structuralComparator in feature installer Signed-off-by: alexfront <alex.andreev.email@gmail.com> * Saving input fields on blur Signed-off-by: alexfront <alex.andreev.email@gmail.com> * Setting Select color same as Input color Signed-off-by: alexfront <alex.andreev.email@gmail.com>
133 lines
4.3 KiB
TypeScript
133 lines
4.3 KiB
TypeScript
import "./clusters-menu.scss"
|
|
import { remote } from "electron"
|
|
import React from "react";
|
|
import { observer } from "mobx-react";
|
|
import { observable } from "mobx";
|
|
import { _i18n } from "../../i18n";
|
|
import { t, Trans } from "@lingui/macro";
|
|
import type { Cluster } from "../../../main/cluster";
|
|
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 { cssNames, IClassName } from "../../utils";
|
|
import { Badge } from "../badge";
|
|
import { navigate, navigation } 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 { clusterIpc } from "../../../common/cluster-ipc";
|
|
import { clusterStatusURL } from "./cluster-status.route";
|
|
|
|
// fixme: allow to rearrange clusters with drag&drop
|
|
|
|
interface Props {
|
|
className?: IClassName;
|
|
}
|
|
|
|
@observer
|
|
export class ClustersMenu extends React.Component<Props> {
|
|
@observable showHint = true;
|
|
|
|
showCluster = (clusterId: ClusterId) => {
|
|
clusterStore.setActive(clusterId);
|
|
navigate("/"); // redirect to index
|
|
}
|
|
|
|
addCluster = () => {
|
|
navigate(addClusterURL());
|
|
}
|
|
|
|
showContextMenu = (cluster: Cluster) => {
|
|
const { Menu, MenuItem } = remote
|
|
const menu = new Menu();
|
|
|
|
menu.append(new MenuItem({
|
|
label: _i18n._(t`Settings`),
|
|
click: () => {
|
|
clusterStore.setActive(cluster.id);
|
|
navigate(clusterSettingsURL())
|
|
}
|
|
}));
|
|
if (cluster.online) {
|
|
menu.append(new MenuItem({
|
|
label: _i18n._(t`Disconnect`),
|
|
click: async () => {
|
|
await clusterIpc.disconnect.invokeFromRenderer(cluster.id);
|
|
if (cluster.id === clusterStore.activeClusterId) {
|
|
navigate(clusterStatusURL());
|
|
}
|
|
}
|
|
}))
|
|
}
|
|
menu.append(new MenuItem({
|
|
label: _i18n._(t`Remove`),
|
|
click: () => {
|
|
ConfirmDialog.open({
|
|
okButtonProps: {
|
|
primary: false,
|
|
accent: true,
|
|
label: _i18n._(t`Remove`),
|
|
},
|
|
ok: () => 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()
|
|
})
|
|
}
|
|
|
|
render() {
|
|
const { className } = this.props;
|
|
const { newContexts } = userStore;
|
|
const { currentWorkspaceId } = workspaceStore;
|
|
const clusters = clusterStore.getByWorkspaceId(currentWorkspaceId);
|
|
const noClusters = !clusterStore.clusters.size;
|
|
const isLanding = navigation.getPath() === landingURL();
|
|
const showStartupHint = this.showHint && isLanding && noClusters;
|
|
return (
|
|
<div
|
|
className={cssNames("ClustersMenu flex column gaps", className)}
|
|
onMouseEnter={() => this.showHint = false}
|
|
>
|
|
{showStartupHint && (
|
|
<div className="startup-tooltip flex column gaps">
|
|
<p><Trans>This is the quick launch menu.</Trans></p>
|
|
<p>
|
|
<Trans>
|
|
Associate clusters and choose the ones you want to access via quick launch menu by clicking the + button.
|
|
</Trans>
|
|
</p>
|
|
</div>
|
|
)}
|
|
{clusters.map(cluster => {
|
|
return (
|
|
<ClusterIcon
|
|
key={cluster.id}
|
|
showErrors={true}
|
|
cluster={cluster}
|
|
isActive={cluster.id === clusterStore.activeClusterId}
|
|
onClick={() => this.showCluster(cluster.id)}
|
|
onContextMenu={() => this.showContextMenu(cluster)}
|
|
/>
|
|
)
|
|
})}
|
|
<div className="add-cluster" onClick={this.addCluster}>
|
|
<Tooltip targetId="add-cluster-icon">
|
|
<Trans>Add Cluster</Trans>
|
|
</Tooltip>
|
|
<Icon big material="add" id="add-cluster-icon"/>
|
|
{newContexts.size > 0 && (
|
|
<Badge className="counter" label={newContexts.size} tooltip={<Trans>new</Trans>}/>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
}
|