mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Adding Topbar extension registries (#2997)
* Move topbars to cluster manager Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Adding topBar extension registries Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * topbar test clean up Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Removing unused class Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Expanding CSS Module typings Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Fixing welcomeURL path Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Remove unused import Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Fix TopBarRegistry references Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Fixing topbar test Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Init missing registry Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
1 parent
6f6ad9cc12
commit
d14a3e4a6d
16 files changed
+263
-60
No files matched your search
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* 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 React from "react";
|
||||
import { welcomeURL } from "../../../common/routes";
|
||||
import { navigate } from "../../navigation";
|
||||
import { Icon } from "../icon";
|
||||
import { TopBar } from "../layout/topbar";
|
||||
import { MaterialTooltip } from "../material-tooltip/material-tooltip";
|
||||
|
||||
export function CatalogTopbar() {
|
||||
return (
|
||||
<TopBar label="Catalog">
|
||||
<div>
|
||||
<MaterialTooltip title="Close Catalog" placement="left">
|
||||
<Icon style={{ cursor: "default" }} material="close" onClick={() => navigate(welcomeURL())}/>
|
||||
</MaterialTooltip>
|
||||
</div>
|
||||
</TopBar>
|
||||
);
|
||||
}
|
||||
@@ -23,10 +23,12 @@
|
||||
--bottom-bar-height: 22px;
|
||||
|
||||
display: grid;
|
||||
grid-template-areas: "menu main" "menu main" "bottom-bar bottom-bar";
|
||||
grid-template-areas:
|
||||
"menu topbar"
|
||||
"menu main"
|
||||
"bottom-bar bottom-bar";
|
||||
grid-template-rows: auto 1fr min-content;
|
||||
grid-template-columns: min-content 1fr;
|
||||
height: 100%;
|
||||
|
||||
main {
|
||||
grid-area: main;
|
||||
@@ -46,7 +48,7 @@
|
||||
#lens-views {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: var(--main-layout-header); // Move below the TopBar
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
display: flex;
|
||||
|
||||
@@ -34,6 +34,8 @@ import { Extensions } from "../+extensions";
|
||||
import { HotbarMenu } from "../hotbar/hotbar-menu";
|
||||
import { EntitySettings } from "../+entity-settings";
|
||||
import { Welcome } from "../+welcome";
|
||||
import { ClusterTopbar } from "./cluster-topbar";
|
||||
import { CatalogTopbar } from "./catalog-topbar";
|
||||
import * as routes from "../../../common/routes";
|
||||
|
||||
@observer
|
||||
@@ -41,6 +43,8 @@ export class ClusterManager extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
<div className="ClusterManager">
|
||||
<Route component={CatalogTopbar} {...routes.catalogRoute} />
|
||||
<Route component={ClusterTopbar} {...routes.clusterViewRoute} />
|
||||
<main>
|
||||
<div id="lens-views"/>
|
||||
<Switch>
|
||||
|
||||
@@ -19,21 +19,28 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { observer } from "mobx-react";
|
||||
import React from "react";
|
||||
import type { RouteComponentProps } from "react-router";
|
||||
import { catalogURL } from "../../../common/routes";
|
||||
import type { Cluster } from "../../../main/cluster";
|
||||
import { navigate } from "../../navigation";
|
||||
import { Icon } from "../icon";
|
||||
import { TopBar } from "../layout/topbar";
|
||||
import { MaterialTooltip } from "../material-tooltip/material-tooltip";
|
||||
import type { Cluster } from "../../../main/cluster";
|
||||
import { ClusterStore } from "../../../common/cluster-store";
|
||||
import type { ClusterViewRouteParams } from "../../../common/routes";
|
||||
|
||||
interface Props {
|
||||
cluster: Cluster
|
||||
interface Props extends RouteComponentProps<ClusterViewRouteParams> {
|
||||
}
|
||||
|
||||
export function ClusterTopbar({ cluster }: Props) {
|
||||
export const ClusterTopbar = observer((props: Props) => {
|
||||
const getCluster = (): Cluster | undefined => {
|
||||
return ClusterStore.getInstance().getById(props.match.params.clusterId);
|
||||
};
|
||||
|
||||
return (
|
||||
<TopBar label={cluster.name}>
|
||||
<TopBar label={getCluster()?.name}>
|
||||
<div>
|
||||
<MaterialTooltip title="Back to Catalog" placement="left">
|
||||
<Icon style={{ cursor: "default" }} material="close" onClick={() => navigate(catalogURL())}/>
|
||||
@@ -41,4 +48,4 @@ export function ClusterTopbar({ cluster }: Props) {
|
||||
</div>
|
||||
</TopBar>
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -32,7 +32,6 @@ import { requestMain } from "../../../common/ipc";
|
||||
import { clusterActivateHandler } from "../../../common/cluster-ipc";
|
||||
import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
|
||||
import { navigate } from "../../navigation";
|
||||
import { ClusterTopbar } from "./cluster-topbar";
|
||||
import { catalogURL, ClusterViewRouteParams } from "../../../common/routes";
|
||||
|
||||
interface Props extends RouteComponentProps<ClusterViewRouteParams> {
|
||||
@@ -104,7 +103,6 @@ export class ClusterView extends React.Component<Props> {
|
||||
render() {
|
||||
return (
|
||||
<div className="ClusterView flex column align-center">
|
||||
{this.cluster && <ClusterTopbar cluster={this.cluster}/>}
|
||||
{this.renderStatus()}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* 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 React from "react";
|
||||
import { render } from "@testing-library/react";
|
||||
import "@testing-library/jest-dom/extend-expect";
|
||||
import { TopBar } from "../layout/topbar";
|
||||
import { TopBarRegistry } from "../../../extensions/registries";
|
||||
|
||||
describe("<TopBar/>", () => {
|
||||
beforeEach(() => {
|
||||
TopBarRegistry.createInstance();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
TopBarRegistry.resetInstance();
|
||||
});
|
||||
|
||||
it("renders w/o errors", () => {
|
||||
const { container } = render(<TopBar label="test bar" />);
|
||||
|
||||
expect(container).toBeInstanceOf(HTMLElement);
|
||||
});
|
||||
|
||||
it("renders title", async () => {
|
||||
const { getByTestId } = render(<TopBar label="topbar" />);
|
||||
|
||||
expect(await getByTestId("topbarLabel")).toHaveTextContent("topbar");
|
||||
});
|
||||
|
||||
it("renders items", async () => {
|
||||
const testId = "testId";
|
||||
const text = "an item";
|
||||
|
||||
TopBarRegistry.getInstance().getItems = jest.fn().mockImplementationOnce(() => [
|
||||
{
|
||||
components: {
|
||||
Item: <span data-testid={testId}>{text}</span>
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
const { getByTestId } = render(<TopBar label="topbar" />);
|
||||
|
||||
expect(await getByTestId(testId)).toHaveTextContent(text);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user