/** * 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 "./dock.scss"; import React from "react"; import { observer } from "mobx-react"; import { cssNames, prevDefault } from "../../utils"; import { Icon } from "../icon"; import { MenuItem } from "../menu"; import { MenuActions } from "../menu/menu-actions"; import { ResizeDirection, ResizingAnchor } from "../resizing-anchor"; import { CreateResource } from "./create-resource"; import { createResourceTab } from "./create-resource.store"; import { DockTabs } from "./dock-tabs"; import { dockStore, IDockTab, TabKind } from "./dock.store"; import { EditResource } from "./edit-resource"; import { InstallChart } from "./install-chart"; import { Logs } from "./logs"; import { TerminalWindow } from "./terminal-window"; import { createTerminalTab } from "./terminal.store"; import { UpgradeChart } from "./upgrade-chart"; interface Props { className?: string; } @observer export class Dock extends React.Component { onKeydown = (evt: React.KeyboardEvent) => { const { close, closeTab, selectedTab } = dockStore; if (!selectedTab) return; const { code, ctrlKey, shiftKey } = evt.nativeEvent; if (shiftKey && code === "Escape") { close(); } if (ctrlKey && code === "KeyW") { if (selectedTab.pinned) close(); else closeTab(selectedTab.id); } }; onChangeTab = (tab: IDockTab) => { const { open, selectTab } = dockStore; open(); selectTab(tab.id); }; renderTab(tab: IDockTab) { switch (tab.kind) { case TabKind.CREATE_RESOURCE: return ; case TabKind.EDIT_RESOURCE: return ; case TabKind.INSTALL_CHART: return ; case TabKind.UPGRADE_CHART: return ; case TabKind.POD_LOGS: return ; case TabKind.TERMINAL: return ; } } renderTabContent() { const { isOpen, height, selectedTab } = dockStore; if (!isOpen || !selectedTab) return null; return (
{this.renderTab(selectedTab)}
); } render() { const { className } = this.props; const { isOpen, toggle, tabs, toggleFillSize, selectedTab, hasTabs, fullSize } = dockStore; return (
dockStore.height} minExtent={dockStore.minHeight} maxExtent={dockStore.maxHeight} direction={ResizeDirection.VERTICAL} onStart={dockStore.open} onMinExtentSubceed={dockStore.close} onMinExtentExceed={dockStore.open} onDrag={extent => dockStore.height = extent} />
createTerminalTab()}> Terminal session createResourceTab()}> Create resource
{hasTabs() && ( <> )}
{this.renderTabContent()}
); } }