import "./main-layout.scss"; import * as React from "react"; import { observable, reaction } from "mobx"; import { disposeOnUnmount, observer } from "mobx-react"; import { matchPath, RouteProps } from "react-router-dom"; import { createStorage, cssNames } from "../../utils"; import { Tab, Tabs } from "../tabs"; import { Sidebar } from "./sidebar"; import { configStore } from "../../config.store"; import { ErrorBoundary } from "../error-boundary"; import { Dock } from "../dock"; import { navigate, navigation } from "../../navigation"; import { themeStore } from "../../theme.store"; export interface TabRoute extends RouteProps { title: React.ReactNode; url: string; } interface Props { className?: any; tabs?: TabRoute[]; footer?: React.ReactNode; headerClass?: string; contentClass?: string; footerClass?: string; } @observer export class MainLayout extends React.Component { public storage = createStorage("main_layout", { pinnedSidebar: true }); @observable isPinned = this.storage.get().pinnedSidebar; @observable isAccessible = true; @disposeOnUnmount syncPinnedStateWithStorage = reaction( () => this.isPinned, isPinned => this.storage.merge({ pinnedSidebar: isPinned }) ); toggleSidebar = () => { this.isPinned = !this.isPinned; this.isAccessible = false; setTimeout(() => this.isAccessible = true, 250); } render() { const { className, contentClass, headerClass, tabs, footer, footerClass, children } = this.props; const { clusterName } = configStore.config; const { pathname } = navigation.location; return (
{clusterName && {clusterName}}
{tabs && ( navigate(url)}> {tabs.map(({ title, path, url, ...routeProps }) => { const isActive = !!matchPath(pathname, { path, ...routeProps }); return })} )}
{children}
); } }