From f9dd20271320284840d6f5d440216cdb1ab9529d Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Fri, 19 Oct 2018 09:57:10 +0100 Subject: [PATCH] Apply header and sidebar layout navigation --- embark-ui/src/components/Layout.js | 168 +++++++++++++---------- embark-ui/src/containers/AppContainer.js | 6 +- 2 files changed, 99 insertions(+), 75 deletions(-) diff --git a/embark-ui/src/components/Layout.js b/embark-ui/src/components/Layout.js index d5b8ea92..3e17e69d 100644 --- a/embark-ui/src/components/Layout.js +++ b/embark-ui/src/components/Layout.js @@ -1,6 +1,7 @@ import React from 'react'; +import {Link} from 'react-router-dom'; import PropTypes from 'prop-types'; -import { DropdownItem, DropdownMenu, DropdownToggle, Nav, NavItem, NavLink, Container } from 'reactstrap'; +import {DropdownItem, DropdownMenu, DropdownToggle, Nav, NavItem, NavLink, Container} from 'reactstrap'; import {LIGHT_THEME, DARK_THEME} from '../constants'; import FontAwesome from 'react-fontawesome'; @@ -23,99 +24,120 @@ import SearchBar from './SearchBar'; import logo from '../images/logo-new.svg'; -const sidebarNavItems = {items: [ - {name: "Dashboard", url: "/embark", icon: 'fa fa-tachometer'}, - {name: "Deployment", url: "/embark/deployment", icon: "fa fa-arrow-up"}, - {name: "Contracts", url: "/embark/contracts", icon: "fa fa-file-text"}, - {name: "Explorer", url: "/embark/explorer", icon: "fa fa-compass", children: [ +const HEADER_NAV_ITEMS = [ + {name: "Dashboard", to: "/embark", icon: 'tachometer'}, + {name: "Deployment", to: "/embark/deployment", icon: "arrow-up"}, + {name: "Contracts", to: "/embark/contracts", icon: "file-text"}, + {name: "Explorer", to: "/embark/explorer/overview", icon: "compass"}, + {name: "Editor", to: "/embark/editor", icon: "codepen"}, + {name: "Utils", to: "/embark/utilities/converter", icon: "cog"} +]; + +const SIDEBAR_NAV_ITEMS = { + "/embark/explorer" : {items: [ {url: "/embark/explorer/overview", icon: "fa fa-signal", name: "Overview"}, {url: "/embark/explorer/accounts", icon: "fa fa-users", name: "Accounts"}, {url: "/embark/explorer/blocks", icon: "fa fa-stop", name: "Blocks"}, {url: "/embark/explorer/transactions", icon: "fa fa-tree", name: "Transactions"} ]}, - {name: "Editor", url: "/embark/editor", icon: "fa fa-codepen"}, - {name: "Documentation", url: "/embark/documentation", icon: "fa fa-book"}, - {name: "Utils", url: "/embark/utilities/converter", icon: "fa fa-cog", children: [ + "/embark/utilities/": {items: [ {url: "/embark/utilities/converter", icon: "fa fa-plug", name: "Converter"}, {url: "/embark/utilities/communication", icon: "fa fa-phone", name: "Communication"}, {url: "/embark/utilities/ens", icon: "fa fa-circle", name: "ENS"}, {url: "/embark/utilities/sign-and-verify", icon: "fa fa-edit", name: "Sign & Verify"}, {url: "/embark/utilities/transaction-decoder", icon: "fa fa-edit", name: "Transaction Decoder"} ]} -]}; +}; + +const removeCssClasses = () => { + document.body.classList.remove('sidebar-fixed'); + document.body.classList.remove('sidebar-lg-show'); +} + +const getSidebar = (location) => { + const currentItem = Object.keys(SIDEBAR_NAV_ITEMS).find(path => location.pathname.startsWith(path)); + return currentItem && SIDEBAR_NAV_ITEMS[currentItem]; +} function searchTheExplorer(value) { // TODO: search } -const Layout = ({children, logout, credentials, location, toggleTheme, currentTheme}) => ( -
- - - - - - - -
- - - - - - - -
- - {children} - -
- - +const Layout = ({children, logout, location, toggleTheme, currentTheme}) => { + const sidebar = getSidebar(location); + if (!sidebar) { + removeCssClasses(); + } + return ( +
+ + + + {sidebar && } + + + +
+ {sidebar && + + + + + + + + } +
+ + {children} + +
+ + +
+ + + Embark  + Documentation +  |  + Github + +
- - - Embark  - Documentation -  |  - Github - - -
-); + ); +} Layout.propTypes = { children: PropTypes.element, tabs: PropTypes.arrayOf(PropTypes.object), - credentials: PropTypes.object, location: PropTypes.object, logout: PropTypes.func, toggleTheme: PropTypes.func, diff --git a/embark-ui/src/containers/AppContainer.js b/embark-ui/src/containers/AppContainer.js index d5a47e02..6af1115a 100644 --- a/embark-ui/src/containers/AppContainer.js +++ b/embark-ui/src/containers/AppContainer.js @@ -80,8 +80,10 @@ class AppContainer extends Component { if (this.shouldRenderLogin()) { content = ; } else { - content = this.toggleTheme()} currentTheme={this.props.theme}> + content = this.toggleTheme()} + currentTheme={this.props.theme}> {routes} ; }