import { AppBar, Collapse, Divider, Drawer, IconButton, ListItem, ListItemIcon, ListItemText, MenuItem, MenuList, Toolbar, Typography } from '@material-ui/core'; import { githubIcon, linkerdWordLogo, slackIcon } from './util/SvgWrappers.jsx'; import BreadcrumbHeader from './BreadcrumbHeader.jsx'; import ChevronLeftIcon from '@material-ui/icons/ChevronLeft'; import CloudQueueIcon from '@material-ui/icons/CloudQueue'; import EmailIcon from '@material-ui/icons/Email'; import ExpandLess from '@material-ui/icons/ExpandLess'; import ExpandMore from '@material-ui/icons/ExpandMore'; import HelpIcon from '@material-ui/icons/HelpOutline'; import HomeIcon from '@material-ui/icons/Home'; import LibraryBooksIcon from '@material-ui/icons/LibraryBooks'; import { Link } from 'react-router-dom'; import MenuIcon from '@material-ui/icons/Menu'; import NavigateNextIcon from '@material-ui/icons/NavigateNext'; import NetworkCheckIcon from '@material-ui/icons/NetworkCheck'; import PropTypes from 'prop-types'; import React from 'react'; import ReactRouterPropTypes from 'react-router-prop-types'; import Version from './Version.jsx'; import ViewListIcon from '@material-ui/icons/ViewList'; import VisibilityIcon from '@material-ui/icons/Visibility'; import classNames from 'classnames'; import { withContext } from './util/AppContext.jsx'; import { withStyles } from '@material-ui/core/styles'; const drawerWidth = 250; const styles = theme => ({ root: { flexGrow: 1, height: "100vh", width: "100%", zIndex: 1, overflowX: 'scroll', position: 'relative', display: 'flex', }, appBar: { color: 'white', zIndex: theme.zIndex.drawer + 1, transition: theme.transitions.create(['width', 'margin'], { easing: theme.transitions.easing.sharp, duration: theme.transitions.duration.leavingScreen, }), }, appBarShift: { marginLeft: drawerWidth, width: `calc(100% - ${drawerWidth}px)`, transition: theme.transitions.create(['width', 'margin'], { easing: theme.transitions.easing.sharp, duration: theme.transitions.duration.enteringScreen, }), }, menuButton: { marginLeft: 12, marginRight: 36, }, hide: { display: 'none', }, drawerPaper: { position: 'relative', whiteSpace: 'nowrap', width: drawerWidth, transition: theme.transitions.create('width', { easing: theme.transitions.easing.sharp, duration: theme.transitions.duration.enteringScreen, }), }, drawerPaperClose: { overflowX: 'hidden', transition: theme.transitions.create('width', { easing: theme.transitions.easing.sharp, duration: theme.transitions.duration.leavingScreen, }), width: theme.spacing.unit * 7, [theme.breakpoints.up('sm')]: { width: theme.spacing.unit * 9, }, }, toolbar: { display: 'flex', alignItems: 'center', justifyContent: 'flex-end', padding: '0 8px', ...theme.mixins.toolbar, }, content: { flexGrow: 1, width: `calc(100% - ${drawerWidth}px)`, backgroundColor: theme.palette.background.default, padding: theme.spacing.unit * 3, }, linkerdLogoContainer: { backgroundColor: theme.palette.primary.main, }, linkerdNavLogo: { minWidth: "180px", }, navMenuItem: { paddingLeft: "24px", paddingRight: "24px", }, }); class NavigationBase extends React.Component { constructor(props) { super(props); this.api = this.props.api; this.handleApiError = this.handleApiError.bind(this); this.state = this.getInitialState(); } getInitialState() { return { drawerOpen: true, resourceMenuOpen: false, helpMenuOpen: false, latestVersion: '', isLatest: true, namespaceFilter: "all" }; } componentDidMount() { this.fetchVersion(); } fetchVersion() { let versionUrl = `https://versioncheck.linkerd.io/version.json?version=${this.props.releaseVersion}&uuid=${this.props.uuid}&source=web`; this.versionPromise = fetch(versionUrl, { credentials: 'include' }) .then(rsp => rsp.json()) .then(versionRsp => { let latestVersion; let parts = this.props.releaseVersion.split("-", 2); if (parts.length === 2) { latestVersion = versionRsp[parts[0]]; } this.setState({ latestVersion, isLatest: latestVersion === this.props.releaseVersion }); }).catch(this.handleApiError); } handleApiError(e) { this.setState({ error: e }); } handleDrawerOpen = () => { this.setState({ drawerOpen: true }); }; handleDrawerClose = () => { this.setState({ drawerOpen: false }); }; handleResourceMenuClick = () => { this.setState(state => ({ resourceMenuOpen: !state.resourceMenuOpen })); }; handleHelpMenuClick = () => { this.setState(state => ({ helpMenuOpen: !state.helpMenuOpen })); } menuItem(path, title, icon) { const { classes, api } = this.props; let normalizedPath = this.props.location.pathname.replace(this.props.pathPrefix, ""); let isCurrentPage = path => path === normalizedPath; return ( {icon} ); } render() { const { classes, ChildComponent } = this.props; return (
{linkerdWordLogo}
{ this.menuItem("/overview", "Overview", ) } { this.menuItem("/tap", "Tap", ) } { this.menuItem("/top", "Top", ) } { this.menuItem("/servicemesh", "Service Mesh", ) } {this.state.resourceMenuOpen ? : } { this.menuItem("/authorities", "Authorities", ) } { this.menuItem("/deployments", "Deployments", ) } { this.menuItem("/namespaces", "Namespaces", ) } { this.menuItem("/pods", "Pods", ) } { this.menuItem("/replicationcontrollers", "Replication Controllers", ) } {this.state.helpMenuOpen ? : } {slackIcon} {githubIcon} { !this.state.drawerOpen ? null : }
); } } NavigationBase.propTypes = { api: PropTypes.shape({ PrefixedLink: PropTypes.func.isRequired, }).isRequired, ChildComponent: PropTypes.func.isRequired, classes: PropTypes.shape({}).isRequired, location: ReactRouterPropTypes.location.isRequired, pathPrefix: PropTypes.string.isRequired, releaseVersion: PropTypes.string.isRequired, theme: PropTypes.shape({}).isRequired, uuid: PropTypes.string.isRequired, }; export default withContext(withStyles(styles, { withTheme: true })(NavigationBase));