1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Adding TopBar to catalog view

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2021-05-27 11:55:29 +03:00
parent 50d0b74dfd
commit f08e7e7758
11 changed files with 126 additions and 55 deletions

View File

@ -68,6 +68,10 @@
-webkit-font-smoothing: auto; -webkit-font-smoothing: auto;
} }
.tabs {
@apply flex flex-grow flex-col;
}
.tab { .tab {
@apply px-8 py-4; @apply px-8 py-4;
} }
@ -77,7 +81,7 @@
--color-active: var(--textColorTertiary); --color-active: var(--textColorTertiary);
} }
.tab:hover::after { .tab::after {
display: none; display: none;
} }

View File

@ -41,6 +41,10 @@ import { Notifications } from "../notifications";
import { Avatar } from "../avatar/avatar"; import { Avatar } from "../avatar/avatar";
import { MainLayout } from "../layout/main-layout"; import { MainLayout } from "../layout/main-layout";
import { cssNames } from "../../utils"; import { cssNames } from "../../utils";
import { TopBar } from "../layout/topbar";
import { welcomeURL } from "../+welcome";
import { Icon } from "../icon";
import { MaterialTooltip } from "./material-tooltip/material-tooltip";
enum sortBy { enum sortBy {
name = "name", name = "name",
@ -137,7 +141,7 @@ export class Catalog extends React.Component<Props> {
renderNavigation() { renderNavigation() {
return ( return (
<Tabs className="flex column" scrollable={false} onChange={this.onTabChange} value={this.activeTab}> <Tabs className={cssNames(styles.tabs, "flex column")} scrollable={false} onChange={this.onTabChange} value={this.activeTab}>
<div className="pt-4"> <div className="pt-4">
<Tab <Tab
value={undefined} value={undefined}
@ -205,44 +209,53 @@ export class Catalog extends React.Component<Props> {
} }
return ( return (
<MainLayout sidebar={this.renderNavigation()}> <>
<div className="p-6 h-full"> <TopBar sidebar={<div>Catalog</div>}>
<ItemListLayout <div>
renderHeaderTitle={this.catalogEntityStore.activeCategory?.metadata.name ?? "Browse All"} <MaterialTooltip title="Close Catalog" placement="left">
isClusterScoped <Icon style={{ cursor: "default" }} material="close" onClick={() => navigate(welcomeURL())}/>
isSearchable={true} </MaterialTooltip>
isSelectable={false} </div>
className="CatalogItemList" </TopBar>
store={this.catalogEntityStore} <MainLayout sidebar={this.renderNavigation()}>
tableId="catalog-items" <div className="p-6 h-full">
sortingCallbacks={{ <ItemListLayout
[sortBy.name]: (item: CatalogEntityItem) => item.name, renderHeaderTitle={this.catalogEntityStore.activeCategory?.metadata.name ?? "Browse All"}
[sortBy.source]: (item: CatalogEntityItem) => item.source, isClusterScoped
[sortBy.status]: (item: CatalogEntityItem) => item.phase, isSearchable={true}
}} isSelectable={false}
searchFilters={[ className="CatalogItemList"
(entity: CatalogEntityItem) => entity.searchFields, store={this.catalogEntityStore}
]} tableId="catalog-items"
renderTableHeader={[ sortingCallbacks={{
{ title: "", className: styles.iconCell }, [sortBy.name]: (item: CatalogEntityItem) => item.name,
{ title: "Name", className: styles.nameCell, sortBy: sortBy.name }, [sortBy.source]: (item: CatalogEntityItem) => item.source,
{ title: "Source", className: styles.sourceCell, sortBy: sortBy.source }, [sortBy.status]: (item: CatalogEntityItem) => item.phase,
{ title: "Labels", className: styles.labelsCell }, }}
{ title: "Status", className: styles.statusCell, sortBy: sortBy.status }, searchFilters={[
]} (entity: CatalogEntityItem) => entity.searchFields,
renderTableContents={(item: CatalogEntityItem) => [ ]}
this.renderIcon(item), renderTableHeader={[
item.name, { title: "", className: styles.iconCell },
item.source, { title: "Name", className: styles.nameCell, sortBy: sortBy.name },
item.labels.map((label) => <Badge className={styles.badge} key={label} label={label} title={label} />), { title: "Source", className: styles.sourceCell, sortBy: sortBy.source },
{ title: item.phase, className: cssNames({ [styles.connected]: item.phase == "connected" }) } { title: "Labels", className: styles.labelsCell },
]} { title: "Status", className: styles.statusCell, sortBy: sortBy.status },
onDetails={(item: CatalogEntityItem) => this.onDetails(item) } ]}
renderItemMenu={this.renderItemMenu} renderTableContents={(item: CatalogEntityItem) => [
/> this.renderIcon(item),
</div> item.name,
<CatalogAddButton category={this.catalogEntityStore.activeCategory} /> item.source,
</MainLayout> item.labels.map((label) => <Badge className={styles.badge} key={label} label={label} title={label} />),
{ title: item.phase, className: cssNames({ [styles.connected]: item.phase == "connected" }) }
]}
onDetails={(item: CatalogEntityItem) => this.onDetails(item) }
renderItemMenu={this.renderItemMenu}
/>
</div>
<CatalogAddButton category={this.catalogEntityStore.activeCategory} />
</MainLayout>
</>
); );
} }
} }

View File

@ -39,7 +39,8 @@
--font-weight-normal: 400; --font-weight-normal: 400;
--font-weight-bold: 500; --font-weight-bold: 500;
--main-layout-header: 40px; --main-layout-header: 40px;
--drag-region-height: 22px --drag-region-height: 22px;
--sidebar-width: 200px;
} }
*, *:before, *:after { *, *:before, *:after {

View File

@ -32,6 +32,7 @@
grid-area: main; grid-area: main;
position: relative; position: relative;
display: flex; display: flex;
flex-direction: column;
} }
.HotbarMenu { .HotbarMenu {

View File

@ -28,12 +28,14 @@
grid-template-columns: [sidebar] var(--sidebar-width) [contents] 1fr; grid-template-columns: [sidebar] var(--sidebar-width) [contents] 1fr;
width: 100%; width: 100%;
z-index: 1; z-index: 1;
height: calc(100% - var(--main-layout-header));
} }
.sidebar { .sidebar {
grid-area: sidebar; grid-area: sidebar;
display: flex;
position: relative;
background: var(--sidebarBackground); background: var(--sidebarBackground);
width: var(--sidebar-width);
} }
.contents { .contents {

View File

@ -29,6 +29,6 @@ export interface SidebarStorageState {
} }
export const sidebarStorage = createStorage<SidebarStorageState>("sidebar", { export const sidebarStorage = createStorage<SidebarStorageState>("sidebar", {
width: 200, // sidebar size in non-compact mode width: 200,
expanded: {}, expanded: {},
}); });

View File

@ -24,7 +24,6 @@ import type { TabLayoutRoute } from "./tab-layout";
import React from "react"; import React from "react";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import { NavLink } from "react-router-dom";
import { cssNames } from "../../utils"; import { cssNames } from "../../utils";
import { Icon } from "../icon"; import { Icon } from "../icon";
import { workloadsRoute, workloadsURL } from "../+workloads/workloads.route"; import { workloadsRoute, workloadsURL } from "../+workloads/workloads.route";
@ -175,12 +174,6 @@ export class Sidebar extends React.Component<Props> {
return ( return (
<div className={cssNames(Sidebar.displayName, "flex column", className)}> <div className={cssNames(Sidebar.displayName, "flex column", className)}>
<div className="header flex align-center">
<NavLink exact to="/" className="box grow">
<Icon svg="logo-lens" className="logo-icon"/>
<div className="logo-text">Lens</div>
</NavLink>
</div>
<div className={cssNames("sidebar-nav flex column box grow-fixed")}> <div className={cssNames("sidebar-nav flex column box grow-fixed")}>
<SidebarItem <SidebarItem
id="cluster" id="cluster"

View File

@ -21,18 +21,18 @@
.TabLayout { .TabLayout {
display: contents; display: flex;
flex-direction: column;
height: 100%;
> .Tabs { > .Tabs {
grid-area: tabs;
background: $layoutTabsBackground; background: $layoutTabsBackground;
} }
main { main {
$spacing: $margin * 2; $spacing: $margin * 2;
grid-area: main; flex-grow: 1;
overflow-y: scroll; // always reserve space for scrollbar (17px) overflow-y: scroll; // always reserve space for scrollbar (17px)
overflow-x: auto; overflow-x: auto;
margin: $spacing; margin: $spacing;

View File

@ -0,0 +1,16 @@
.topBar {
display: grid;
grid-template-columns: [sidebar] var(--sidebar-width) [contents] 1fr;
grid-template-rows: var(--main-layout-header);
grid-template-areas: "sidebar contents";
z-index: 1;
}
.sidebar {
width: var(--sidebar-width);
background-color: var(--sidebarLogoBackground);
}
.contents {
background-color: var(--layoutBackground);
}

View File

@ -0,0 +1,41 @@
/**
* Copyright (c) 2021 OpenLens Authors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import styles from "./topbar.module.css";
import React, { HTMLAttributes, ReactNode } from "react";
import { sidebarStorage } from "./sidebar-storage";
import { observer } from "mobx-react";
interface Props extends HTMLAttributes<any> {
sidebar: ReactNode;
}
export const TopBar = observer((props: Props) => {
const { width } = sidebarStorage.get();
const style = { "--sidebar-width": `${width}px` } as React.CSSProperties;
return (
<div className={styles.topBar} style={style}>
<div className={styles.sidebar}>{props.sidebar}</div>
<div className={styles.contents}>{props.children}</div>
</div>
);
});

View File

@ -68,7 +68,7 @@ body.resizing {
} }
&.horizontal { &.horizontal {
top: 0; top: calc(var(--main-layout-header) * -1); // Cover TopBar area also
bottom: 0; bottom: 0;
cursor: col-resize; cursor: col-resize;
width: $dimension; width: $dimension;