mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Adding cluster settings icon into dashboard (#1672)
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
831fb80bfe
commit
665ed94128
@ -0,0 +1,49 @@
|
|||||||
|
jest.mock("../../../../common/ipc");
|
||||||
|
|
||||||
|
import React from "react";
|
||||||
|
import { fireEvent, render } from "@testing-library/react";
|
||||||
|
import "@testing-library/jest-dom/extend-expect";
|
||||||
|
|
||||||
|
import { MainLayoutHeader } from "../main-layout-header";
|
||||||
|
import { Cluster } from "../../../../main/cluster";
|
||||||
|
import { workspaceStore } from "../../../../common/workspace-store";
|
||||||
|
import { broadcastMessage } from "../../../../common/ipc";
|
||||||
|
|
||||||
|
const mockBroadcastIpc = broadcastMessage as jest.MockedFunction<typeof broadcastMessage>;
|
||||||
|
|
||||||
|
const cluster: Cluster = new Cluster({
|
||||||
|
id: "foo",
|
||||||
|
contextName: "minikube",
|
||||||
|
kubeConfigPath: "minikube-config.yml",
|
||||||
|
workspace: workspaceStore.currentWorkspaceId
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("<MainLayoutHeader />", () => {
|
||||||
|
it("renders w/o errors", () => {
|
||||||
|
const { container } = render(<MainLayoutHeader cluster={cluster} />);
|
||||||
|
|
||||||
|
expect(container).toBeInstanceOf(HTMLElement);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("renders gear icon", () => {
|
||||||
|
const { container } = render(<MainLayoutHeader cluster={cluster} />);
|
||||||
|
const icon = container.querySelector(".Icon .icon");
|
||||||
|
|
||||||
|
expect(icon).toBeInstanceOf(HTMLElement);
|
||||||
|
expect(icon).toHaveTextContent("settings");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("navigates to cluster settings", () => {
|
||||||
|
const { container } = render(<MainLayoutHeader cluster={cluster} />);
|
||||||
|
const icon = container.querySelector(".Icon");
|
||||||
|
|
||||||
|
fireEvent.click(icon);
|
||||||
|
expect(mockBroadcastIpc).toBeCalledWith("renderer:navigate", "/cluster/foo/settings");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("renders cluster name", async () => {
|
||||||
|
const { getByText } = render(<MainLayoutHeader cluster={cluster} />);
|
||||||
|
|
||||||
|
expect(await getByText("minikube")).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
33
src/renderer/components/layout/main-layout-header.tsx
Normal file
33
src/renderer/components/layout/main-layout-header.tsx
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import React from "react";
|
||||||
|
import { Trans } from "@lingui/macro";
|
||||||
|
|
||||||
|
import { clusterSettingsURL } from "../+cluster-settings";
|
||||||
|
import { broadcastMessage } from "../../../common/ipc";
|
||||||
|
import { Cluster } from "../../../main/cluster";
|
||||||
|
import { cssNames } from "../../utils";
|
||||||
|
import { Icon } from "../icon";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
cluster: Cluster
|
||||||
|
className?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function MainLayoutHeader({ cluster, className }: Props) {
|
||||||
|
return (
|
||||||
|
<header className={cssNames("flex gaps align-center justify-space-between", className)}>
|
||||||
|
<span className="cluster">{cluster.name}</span>
|
||||||
|
<Icon
|
||||||
|
material="settings"
|
||||||
|
tooltip={<Trans>Open cluster settings</Trans>}
|
||||||
|
interactive
|
||||||
|
onClick={() => {
|
||||||
|
broadcastMessage("renderer:navigate", clusterSettingsURL({
|
||||||
|
params: {
|
||||||
|
clusterId: cluster.id
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</header>
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -14,15 +14,6 @@
|
|||||||
grid-area: header;
|
grid-area: header;
|
||||||
background: $layoutBackground;
|
background: $layoutBackground;
|
||||||
padding: $padding $padding * 2;
|
padding: $padding $padding * 2;
|
||||||
|
|
||||||
span + .lens-version {
|
|
||||||
margin-left: $margin;
|
|
||||||
}
|
|
||||||
|
|
||||||
.lens-version {
|
|
||||||
font-size: x-small;
|
|
||||||
text-transform: uppercase;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
> aside {
|
> aside {
|
||||||
|
|||||||
@ -3,12 +3,13 @@ import "./main-layout.scss";
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { observable, reaction } from "mobx";
|
import { observable, reaction } from "mobx";
|
||||||
import { disposeOnUnmount, observer } from "mobx-react";
|
import { disposeOnUnmount, observer } from "mobx-react";
|
||||||
import { autobind, createStorage, cssNames } from "../../utils";
|
|
||||||
import { Sidebar } from "./sidebar";
|
|
||||||
import { ErrorBoundary } from "../error-boundary";
|
|
||||||
import { Dock } from "../dock";
|
|
||||||
import { getHostedCluster } from "../../../common/cluster-store";
|
import { getHostedCluster } from "../../../common/cluster-store";
|
||||||
|
import { autobind, createStorage, cssNames } from "../../utils";
|
||||||
|
import { Dock } from "../dock";
|
||||||
|
import { ErrorBoundary } from "../error-boundary";
|
||||||
import { ResizeDirection, ResizeGrowthDirection, ResizeSide, ResizingAnchor } from "../resizing-anchor";
|
import { ResizeDirection, ResizeGrowthDirection, ResizeSide, ResizingAnchor } from "../resizing-anchor";
|
||||||
|
import { MainLayoutHeader } from "./main-layout-header";
|
||||||
|
import { Sidebar } from "./sidebar";
|
||||||
|
|
||||||
export interface MainLayoutProps {
|
export interface MainLayoutProps {
|
||||||
className?: any;
|
className?: any;
|
||||||
@ -66,9 +67,7 @@ export class MainLayout extends React.Component<MainLayoutProps> {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cssNames("MainLayout", className)} style={this.getSidebarSize() as any}>
|
<div className={cssNames("MainLayout", className)} style={this.getSidebarSize() as any}>
|
||||||
<header className={cssNames("flex gaps align-center", headerClass)}>
|
<MainLayoutHeader className={headerClass} cluster={cluster} />
|
||||||
<span className="cluster">{cluster.name}</span>
|
|
||||||
</header>
|
|
||||||
|
|
||||||
<aside className={cssNames("flex column", { pinned: this.isPinned, accessible: this.isAccessible })}>
|
<aside className={cssNames("flex column", { pinned: this.isPinned, accessible: this.isAccessible })}>
|
||||||
<Sidebar className="box grow" isPinned={this.isPinned} toggle={this.toggleSidebar} />
|
<Sidebar className="box grow" isPinned={this.isPinned} toggle={this.toggleSidebar} />
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user