Skip to content

Commit

Permalink
feat(web): mount terminal in a bottom drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid committed Jun 21, 2024
1 parent b0dfce3 commit 4a56e6d
Showing 1 changed file with 40 additions and 6 deletions.
46 changes: 40 additions & 6 deletions web/src/MainLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,23 @@
* find current contact information at www.suse.com.
*/

import React from "react";
import React, { useState } from "react";
import { Outlet, NavLink, useNavigate } from "react-router-dom";
import {
Button,
Drawer, DrawerActions, DrawerCloseButton, DrawerContent, DrawerHead, DrawerPanelBody, DrawerPanelContent,
Masthead, MastheadContent, MastheadToggle, MastheadMain, MastheadBrand,
Nav, NavItem, NavList,
Page, PageSidebar, PageSidebarBody, PageToggleButton,
Toolbar, ToolbarContent, ToolbarGroup, ToolbarItem
Toolbar, ToolbarContent, ToolbarGroup, ToolbarItem,
} from "@patternfly/react-core";
import { Icon } from "~/components/layout";
import { About, InstallerOptions } from "~/components/core";
import { About, InstallerOptions, TerminalDialog, Terminal } from "~/components/core";
import { _ } from "~/i18n";
import { rootRoutes } from "~/router";
import { useProduct } from "~/context/product";

const Header = () => {
const Header = ({ onTerminalClick }) => {
const { selectedProduct } = useProduct();
// NOTE: Agama is a name, do not translate
const title = selectedProduct?.name || _("Agama");
Expand All @@ -60,6 +61,12 @@ const Header = () => {
<ToolbarContent>
<ToolbarGroup align={{ default: "alignRight" }}>
<ToolbarItem>
<Button
variant="plain"
icon={<Icon name="terminal" />}
onClick={onTerminalClick}
aria-label={_("Show terminal")}
/>
<InstallerOptions />
</ToolbarItem>
</ToolbarGroup>
Expand Down Expand Up @@ -122,13 +129,40 @@ const Sidebar = () => {
* Root application component for laying out the content.
*/
export default function Root() {
const [showTerminal, setShowTerminal] = useState();

const openTerminal = () => setShowTerminal(true);
const closeTerminal = () => setShowTerminal(false);

return (
<Page
isManagedSidebar
header={<Header />}
header={<Header onTerminalClick={openTerminal} />}
sidebar={<Sidebar />}
>
<Outlet />
<Drawer isExpanded={showTerminal} position="bottom">
<DrawerContent
panelContent={
<DrawerPanelContent
isResizable
minSize="66%"
colorVariant="dark-200"
>
<DrawerHead>
<h2>{_("Terminal")}</h2>
<DrawerActions>
<DrawerCloseButton onClick={closeTerminal} />
</DrawerActions>
</DrawerHead>
<DrawerPanelBody>
<Terminal />
</DrawerPanelBody>
</DrawerPanelContent>
}
>
<Outlet />
</DrawerContent>
</Drawer>
</Page>
);
}

0 comments on commit 4a56e6d

Please sign in to comment.