1
0
mirror of https://github.com/lensapp/lens.git synced 2024-11-10 10:36:25 +03:00

Sidebar cluster avatar (#3765)

This commit is contained in:
Alex Andreev 2021-09-13 18:33:30 +03:00 committed by GitHub
parent 8e9dd50828
commit 4fa0b8e329
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 137 additions and 141 deletions

View File

@ -36,7 +36,7 @@ function getSidebarSelectors(itemId: string) {
return { return {
expandSubMenu: `${root} .nav-item`, expandSubMenu: `${root} .nav-item`,
subMenuLink: (href: string) => `.Sidebar .sub-menu a[href^="/${href}"]`, subMenuLink: (href: string) => `[data-testid=cluster-sidebar] .sub-menu a[href^="/${href}"]`,
}; };
} }

View File

@ -113,7 +113,7 @@ export async function lauchMinikubeClusterFromCatalog(window: Page): Promise<Fra
const frame = await minikubeFrame.contentFrame(); const frame = await minikubeFrame.contentFrame();
await frame.waitForSelector("div.Sidebar"); await frame.waitForSelector("[data-testid=cluster-sidebar]");
return frame; return frame;
} }

View File

@ -82,7 +82,7 @@ export class WindowManager extends Singleton {
show: false, show: false,
minWidth: 700, // accommodate 800 x 600 display minimum minWidth: 700, // accommodate 800 x 600 display minimum
minHeight: 500, // accommodate 800 x 600 display minimum minHeight: 500, // accommodate 800 x 600 display minimum
titleBarStyle: "hidden", titleBarStyle: "hiddenInset",
backgroundColor: "#1e2124", backgroundColor: "#1e2124",
webPreferences: { webPreferences: {
preload: path.join(__static, "build", "preload.js"), preload: path.join(__static, "build", "preload.js"),

View File

@ -43,7 +43,6 @@ import { catalogURL, CatalogViewRouteParam } from "../../../common/routes";
import { CatalogMenu } from "./catalog-menu"; import { CatalogMenu } from "./catalog-menu";
import { HotbarIcon } from "../hotbar/hotbar-icon"; import { HotbarIcon } from "../hotbar/hotbar-icon";
import { RenderDelay } from "../render-delay/render-delay"; import { RenderDelay } from "../render-delay/render-delay";
import { TopBar } from "../layout/topbar";
export const previousActiveTab = createAppStorage("catalog-previous-active-tab", ""); export const previousActiveTab = createAppStorage("catalog-previous-active-tab", "");
@ -259,8 +258,6 @@ export class Catalog extends React.Component<Props> {
} }
return ( return (
<>
<TopBar/>
<MainLayout sidebar={this.renderNavigation()}> <MainLayout sidebar={this.renderNavigation()}>
<div className="p-6 h-full"> <div className="p-6 h-full">
{ this.renderList() } { this.renderList() }
@ -280,7 +277,6 @@ export class Catalog extends React.Component<Props> {
) )
} }
</MainLayout> </MainLayout>
</>
); );
} }
} }

View File

@ -51,23 +51,6 @@ describe("<Welcome/>", () => {
WelcomeBannerRegistry.resetInstance(); WelcomeBannerRegistry.resetInstance();
}); });
it("renders items in the top bar", async () => {
const testId = "testId";
const text = "topBarItem";
TopBarRegistry.getInstance().getItems = jest.fn().mockImplementationOnce(() => [
{
components: {
Item: () => <span data-testid={testId}>{text}</span>
}
}
]);
render(<Welcome />);
expect(screen.getByTestId(testId)).toHaveTextContent(text);
});
it("renders <Banner /> registered in WelcomeBannerRegistry and hide logo", async () => { it("renders <Banner /> registered in WelcomeBannerRegistry and hide logo", async () => {
const testId = "testId"; const testId = "testId";

View File

@ -27,7 +27,6 @@ import { Icon } from "../icon";
import { productName, slackUrl } from "../../../common/vars"; import { productName, slackUrl } from "../../../common/vars";
import { WelcomeMenuRegistry } from "../../../extensions/registries"; import { WelcomeMenuRegistry } from "../../../extensions/registries";
import { WelcomeBannerRegistry } from "../../../extensions/registries"; import { WelcomeBannerRegistry } from "../../../extensions/registries";
import { TopBar } from "../layout/topbar";
export const defaultWidth = 320; export const defaultWidth = 320;
@ -48,8 +47,6 @@ export class Welcome extends React.Component {
}, defaultWidth); }, defaultWidth);
return ( return (
<>
<TopBar/>
<div className="flex justify-center Welcome align-center"> <div className="flex justify-center Welcome align-center">
<div style={{ width: `${maxWidth}px` }} data-testid="welcome-banner-container"> <div style={{ width: `${maxWidth}px` }} data-testid="welcome-banner-container">
{welcomeBanner.length > 0 ? ( {welcomeBanner.length > 0 ? (
@ -97,7 +94,6 @@ export class Welcome extends React.Component {
</div> </div>
</div> </div>
</div> </div>
</>
); );
} }
} }

View File

@ -21,10 +21,11 @@
.ClusterManager { .ClusterManager {
--bottom-bar-height: 22px; --bottom-bar-height: 22px;
--hotbar-width: 75px;
display: grid; display: grid;
grid-template-areas: grid-template-areas:
"menu topbar" "topbar topbar"
"menu main" "menu main"
"bottom-bar bottom-bar"; "bottom-bar bottom-bar";
grid-template-rows: auto 1fr min-content; grid-template-rows: auto 1fr min-content;
@ -48,7 +49,7 @@
#lens-views { #lens-views {
position: absolute; position: absolute;
left: 0; left: 0;
top: 40px; // Move below top bar top: 0;
right: 0; right: 0;
bottom: 0; bottom: 0;
display: flex; display: flex;

View File

@ -39,6 +39,7 @@ import { DeleteClusterDialog } from "../delete-cluster-dialog";
import { reaction } from "mobx"; import { reaction } from "mobx";
import { navigation } from "../../navigation"; import { navigation } from "../../navigation";
import { setEntityOnRouteMatch } from "../../../main/catalog-sources/helpers/general-active-sync"; import { setEntityOnRouteMatch } from "../../../main/catalog-sources/helpers/general-active-sync";
import { TopBar } from "../layout/topbar";
@observer @observer
export class ClusterManager extends React.Component { export class ClusterManager extends React.Component {
@ -51,6 +52,7 @@ export class ClusterManager extends React.Component {
render() { render() {
return ( return (
<div className="ClusterManager"> <div className="ClusterManager">
<TopBar/>
<main> <main>
<div id="lens-views"/> <div id="lens-views"/>
<Switch> <Switch>

View File

@ -34,7 +34,6 @@ import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
import { navigate } from "../../navigation"; import { navigate } from "../../navigation";
import { catalogURL, ClusterViewRouteParams } from "../../../common/routes"; import { catalogURL, ClusterViewRouteParams } from "../../../common/routes";
import { previousActiveTab } from "../+catalog"; import { previousActiveTab } from "../+catalog";
import { TopBar } from "../layout/topbar";
interface Props extends RouteComponentProps<ClusterViewRouteParams> { interface Props extends RouteComponentProps<ClusterViewRouteParams> {
} }
@ -105,7 +104,6 @@ export class ClusterView extends React.Component<Props> {
render() { render() {
return ( return (
<div className="ClusterView flex column align-center"> <div className="ClusterView flex column align-center">
<TopBar/>
{this.renderStatus()} {this.renderStatus()}
</div> </div>
); );

View File

@ -25,13 +25,9 @@
position: relative; position: relative;
text-align: center; text-align: center;
background: $clusterMenuBackground; background: $clusterMenuBackground;
padding-top: 28px; padding-top: 1px;
width: 75px; width: var(--hotbar-width);
overflow: hidden;
.is-mac &:before {
content: "";
height: 4px; // extra spacing for mac-os "traffic-light" buttons
}
.HotbarItems { .HotbarItems {
--cellWidth: 40px; --cellWidth: 40px;

View File

@ -19,38 +19,38 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
.Sidebar { .sidebarNav {
$iconSize: 24px; @apply flex overflow-auto flex-col;
$itemSpacing: floor($unit / 2.6) floor($unit / 1.6);
.sidebar-nav {
width: var(--sidebar-width); width: var(--sidebar-width);
padding-bottom: calc(var(--padding) * 3); padding-bottom: calc(var(--padding) * 3);
overflow: auto;
.Icon { /* Shadow above scrolling content from https://gist.github.com/distinctgrey/7548778 */
--size: #{$iconSize}; background:
linear-gradient(var(--sidebarBackground) 30%, rgba(255,255,255,0)),
box-sizing: content-box; linear-gradient(rgba(255,255,255,0), var(--sidebarBackground) 70%) 0 100%,
padding: floor($padding / 2.6); radial-gradient(farthest-side at 50% 0, rgba(0,0,0,.2), rgba(0,0,0,0)),
border-radius: 50%; radial-gradient(farthest-side at 50% 100%, rgba(0,0,0,.2), rgba(0,0,0,0)) 0 100%;
} background-repeat: no-repeat;
background-size: 100% 40px, 100% 40px, 100% 12px, 100% 12px;
hr { background-attachment: local, local, scroll, scroll;
background-color: transparent; }
}
} .sidebarNav :global(.Icon) {
box-sizing: content-box;
.loading { padding: 3px;
padding: $padding; border-radius: 50%;
text-align: center; }
}
.cluster {
.cluster-name { @apply flex items-center m-5;
padding: 1.25rem; }
font-weight: bold;
font-size: 1.5rem; .clusterName {
word-break: break-all; @apply font-bold overflow-hidden;
color: var(--textColorAccent); word-break: break-word;
} color: var(--textColorAccent);
display: -webkit-box;
/* Simulate text-overflow:ellipsis styles but for multiple text lines */
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
} }

View File

@ -19,7 +19,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
import "./sidebar.scss"; import styles from "./sidebar.module.css";
import type { TabLayoutRoute } from "./tab-layout"; import type { TabLayoutRoute } from "./tab-layout";
import React from "react"; import React from "react";
@ -41,6 +41,7 @@ import { Apps } from "../+apps";
import * as routes from "../../../common/routes"; import * as routes from "../../../common/routes";
import { Config } from "../+config"; import { Config } from "../+config";
import { catalogEntityRegistry } from "../../api/catalog-entity-registry"; import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
import { HotbarIcon } from "../hotbar/hotbar-icon";
interface Props { interface Props {
className?: string; className?: string;
@ -177,6 +178,29 @@ export class Sidebar extends React.Component<Props> {
}); });
} }
renderCluster() {
if (!this.clusterEntity) {
return null;
}
const { metadata, spec } = this.clusterEntity;
return (
<div className={styles.cluster}>
<HotbarIcon
uid={metadata.uid}
title={metadata.name}
source={metadata.source}
src={spec.icon?.src}
className="mr-5"
/>
<div className={styles.clusterName}>
{metadata.name}
</div>
</div>
);
}
get clusterEntity() { get clusterEntity() {
return catalogEntityRegistry.activeEntity; return catalogEntityRegistry.activeEntity;
} }
@ -185,13 +209,9 @@ export class Sidebar extends React.Component<Props> {
const { className } = this.props; const { className } = this.props;
return ( return (
<div className={cssNames(Sidebar.displayName, "flex column", className)}> <div className={cssNames("flex flex-col", className)} data-testid="cluster-sidebar">
{this.clusterEntity && ( {this.renderCluster()}
<div className="cluster-name"> <div className={styles.sidebarNav}>
{this.clusterEntity.metadata.name}
</div>
)}
<div className={cssNames("sidebar-nav flex column box grow-fixed")}>
<SidebarItem <SidebarItem
id="cluster" id="cluster"
text="Cluster" text="Cluster"

View File

@ -30,6 +30,10 @@
grid-area: topbar; grid-area: topbar;
} }
:global(.is-mac) .topBar {
padding-left: var(--hotbar-width);
}
.history { .history {
@apply flex items-center; @apply flex items-center;
} }

View File

@ -95,7 +95,7 @@ export const TopBar = observer(({ children, ...rest }: Props) => {
<Icon <Icon
data-testid="home-button" data-testid="home-button"
material="home" material="home"
className="ml-5" className="ml-4"
onClick={goHome} onClick={goHome}
disabled={isActiveRoute(catalogRoute)} disabled={isActiveRoute(catalogRoute)}
/> />