diff --git a/src/extensions/renderer-api/components.ts b/src/extensions/renderer-api/components.ts index 49b3ef933c..96eaeb6db4 100644 --- a/src/extensions/renderer-api/components.ts +++ b/src/extensions/renderer-api/components.ts @@ -20,6 +20,7 @@ */ // layouts +export * from "../../renderer/components/layout/setting-layout"; export * from "../../renderer/components/layout/page-layout"; export * from "../../renderer/components/layout/wizard-layout"; export * from "../../renderer/components/layout/tab-layout"; diff --git a/src/renderer/components/+add-cluster/add-cluster.tsx b/src/renderer/components/+add-cluster/add-cluster.tsx index b04c9a2989..164106b517 100644 --- a/src/renderer/components/+add-cluster/add-cluster.tsx +++ b/src/renderer/components/+add-cluster/add-cluster.tsx @@ -38,8 +38,8 @@ import { navigate } from "../../navigation"; import { iter } from "../../utils"; import { AceEditor } from "../ace-editor"; import { Button } from "../button"; -import { PageLayout } from "../layout/page-layout"; import { Notifications } from "../notifications"; +import { SettingLayout } from "../layout/setting-layout"; interface Option { config: KubeConfig; @@ -108,7 +108,7 @@ export class AddCluster extends React.Component { render() { return ( - +

Add Clusters from Kubeconfig

Clusters added here are not merged into the ~/.kube/config file. @@ -144,7 +144,7 @@ export class AddCluster extends React.Component { tooltipOverrideDisabled /> - + ); } } diff --git a/src/renderer/components/+entity-settings/entity-settings.tsx b/src/renderer/components/+entity-settings/entity-settings.tsx index 16c79412cf..de38e6df2a 100644 --- a/src/renderer/components/+entity-settings/entity-settings.tsx +++ b/src/renderer/components/+entity-settings/entity-settings.tsx @@ -25,7 +25,6 @@ import React from "react"; import { observable, makeObservable } from "mobx"; import type { RouteComponentProps } from "react-router"; import { observer } from "mobx-react"; -import { PageLayout } from "../layout/page-layout"; import { navigation } from "../../navigation"; import { Tabs, Tab } from "../tabs"; import type { CatalogEntity } from "../../api/catalog-entity"; @@ -33,6 +32,7 @@ import { catalogEntityRegistry } from "../../api/catalog-entity-registry"; import { EntitySettingRegistry } from "../../../extensions/registries"; import type { EntitySettingsRouteParams } from "../../../common/routes"; import { groupBy } from "lodash"; +import { SettingLayout } from "../layout/setting-layout"; interface Props extends RouteComponentProps { } @@ -120,10 +120,9 @@ export class EntitySettings extends React.Component { const activeSetting = this.menuItems.find((setting) => setting.id === this.activeTab); return ( -

@@ -132,7 +131,7 @@ export class EntitySettings extends React.Component {
-
+ ); } } diff --git a/src/renderer/components/+extensions/extensions.tsx b/src/renderer/components/+extensions/extensions.tsx index 831ec6c1cd..6a2524da31 100644 --- a/src/renderer/components/+extensions/extensions.tsx +++ b/src/renderer/components/+extensions/extensions.tsx @@ -39,12 +39,12 @@ import logger from "../../../main/logger"; import { Button } from "../button"; import { ConfirmDialog } from "../confirm-dialog"; import { DropFileInput, InputValidators } from "../input"; -import { PageLayout } from "../layout/page-layout"; import { Notifications } from "../notifications"; import { ExtensionInstallationState, ExtensionInstallationStateStore } from "./extension-install.store"; import { Install } from "./install"; import { InstalledExtensions } from "./installed-extensions"; import { Notice } from "./notice"; +import { SettingLayout } from "../layout/setting-layout"; function getMessageFromError(error: any): string { if (!error || typeof error !== "object") { @@ -317,7 +317,7 @@ export async function attemptInstallByInfo({ name, version, requireConfirmation version = json["dist-tags"][version]; } else { Notifications.error(

The {name} extension does not have a version or tag {version}.

); - + return disposer(); } } @@ -510,7 +510,7 @@ export class Extensions extends React.Component { return ( - +

Extensions

@@ -533,7 +533,7 @@ export class Extensions extends React.Component { uninstall={confirmUninstallExtension} />
-
+
); } diff --git a/src/renderer/components/+preferences/preferences.tsx b/src/renderer/components/+preferences/preferences.tsx index 0a85c6369d..9bf82f9e4f 100644 --- a/src/renderer/components/+preferences/preferences.tsx +++ b/src/renderer/components/+preferences/preferences.tsx @@ -31,7 +31,6 @@ import { AppPreferenceRegistry, RegisteredAppPreference } from "../../../extensi import { UserStore } from "../../../common/user-store"; import { ThemeStore } from "../../theme.store"; import { Input } from "../input"; -import { PageLayout } from "../layout/page-layout"; import { SubTitle } from "../layout/sub-title"; import { Select, SelectOption } from "../select"; import { HelmCharts } from "./helm-charts"; @@ -40,6 +39,7 @@ import { navigation } from "../../navigation"; import { Tab, Tabs } from "../tabs"; import { FormSwitch, Switcher } from "../switch"; import { KubeconfigSyncs } from "./kubeconfig-syncs"; +import { SettingLayout } from "../layout/setting-layout"; enum Pages { Application = "application", @@ -136,8 +136,7 @@ export class Preferences extends React.Component { ); return ( - !e.showInPreferencesTab).map(this.renderExtension)} )} - + ); } } diff --git a/src/renderer/components/layout/page-layout.tsx b/src/renderer/components/layout/page-layout.tsx index 6978cdc218..a393603885 100644 --- a/src/renderer/components/layout/page-layout.tsx +++ b/src/renderer/components/layout/page-layout.tsx @@ -19,96 +19,11 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import "./page-layout.scss"; +import { SettingLayout } from "./setting-layout"; -import React from "react"; -import { observer } from "mobx-react"; -import { boundMethod, cssNames, IClassName } from "../../utils"; -import { navigation } from "../../navigation"; -import { Icon } from "../icon"; - -export interface PageLayoutProps extends React.DOMAttributes { - className?: IClassName; - contentClass?: IClassName; - provideBackButtonNavigation?: boolean; - contentGaps?: boolean; - showOnTop?: boolean; // covers whole app view - navigation?: React.ReactNode; - back?: (evt: React.MouseEvent | KeyboardEvent) => void; -} - -const defaultProps: Partial = { - provideBackButtonNavigation: true, - contentGaps: true, -}; - -@observer -export class PageLayout extends React.Component { - static defaultProps = defaultProps as object; - - @boundMethod - back(evt?: React.MouseEvent | KeyboardEvent) { - if (this.props.back) { - this.props.back(evt); - } else { - navigation.goBack(); - } - } - - async componentDidMount() { - window.addEventListener("keydown", this.onEscapeKey); - } - - componentWillUnmount() { - window.removeEventListener("keydown", this.onEscapeKey); - } - - onEscapeKey = (evt: KeyboardEvent) => { - if (!this.props.provideBackButtonNavigation) { - return; - } - - if (evt.code === "Escape") { - evt.stopPropagation(); - this.back(evt); - } - }; - - render() { - const { - contentClass, provideBackButtonNavigation, - contentGaps, showOnTop, navigation, children, ...elemProps - } = this.props; - const className = cssNames("PageLayout", { showOnTop, showNavigation: navigation }, this.props.className); - - return ( -
- { navigation && ( - - )} -
-
- {children} -
-
- { this.props.provideBackButtonNavigation && ( -
-
- -
- - -
- )} -
-
-
- ); - } -} +/** + * PageLayout is deprecated. See MainLayout & SettingLayout + * + * @deprecated + */ +export class PageLayout extends SettingLayout {} diff --git a/src/renderer/components/layout/page-layout.scss b/src/renderer/components/layout/setting-layout.scss similarity index 99% rename from src/renderer/components/layout/page-layout.scss rename to src/renderer/components/layout/setting-layout.scss index 8b2c30494e..198e7c9cb6 100644 --- a/src/renderer/components/layout/page-layout.scss +++ b/src/renderer/components/layout/setting-layout.scss @@ -19,12 +19,10 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -.PageLayout { +.SettingLayout { --width: 75%; --nav-width: 180px; --nav-column-width: 30vw; - - position: relative; width: 100%; height: 100%; display: grid !important; diff --git a/src/renderer/components/layout/setting-layout.tsx b/src/renderer/components/layout/setting-layout.tsx new file mode 100644 index 0000000000..45912f262c --- /dev/null +++ b/src/renderer/components/layout/setting-layout.tsx @@ -0,0 +1,116 @@ +/** + * 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 "./setting-layout.scss"; + +import React from "react"; +import { observer } from "mobx-react"; +import { boundMethod, cssNames, IClassName } from "../../utils"; +import { navigation } from "../../navigation"; +import { Icon } from "../icon"; + +export interface SettingLayoutProps extends React.DOMAttributes { + className?: IClassName; + contentClass?: IClassName; + provideBackButtonNavigation?: boolean; + contentGaps?: boolean; + navigation?: React.ReactNode; + back?: (evt: React.MouseEvent | KeyboardEvent) => void; +} + +const defaultProps: Partial = { + provideBackButtonNavigation: true, + contentGaps: true, +}; + +/** + * Layout for settings like pages with navigation + */ +@observer +export class SettingLayout extends React.Component { + static defaultProps = defaultProps as object; + + @boundMethod + back(evt?: React.MouseEvent | KeyboardEvent) { + if (this.props.back) { + this.props.back(evt); + } else { + navigation.goBack(); + } + } + + async componentDidMount() { + window.addEventListener("keydown", this.onEscapeKey); + } + + componentWillUnmount() { + window.removeEventListener("keydown", this.onEscapeKey); + } + + onEscapeKey = (evt: KeyboardEvent) => { + if (!this.props.provideBackButtonNavigation) { + return; + } + + if (evt.code === "Escape") { + evt.stopPropagation(); + this.back(evt); + } + }; + + render() { + const { + contentClass, provideBackButtonNavigation, + contentGaps, navigation, children, ...elemProps + } = this.props; + const className = cssNames("SettingLayout", "showOnTop", { showNavigation: navigation }, this.props.className); + + return ( +
+ { navigation && ( + + )} +
+
+ {children} +
+
+ { this.props.provideBackButtonNavigation && ( +
+
+ +
+ + +
+ )} +
+
+
+ ); + } +}