2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt odlux
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
18 import * as React from 'react';
19 import { Theme } from '@mui/material/styles';
21 import { WithStyles } from '@mui/styles';
22 import withStyles from '@mui/styles/withStyles';
23 import createStyles from '@mui/styles/createStyles';
25 import { faHome, faAddressBook } from '@fortawesome/free-solid-svg-icons';
27 import Drawer from '@mui/material/Drawer';
28 import List from '@mui/material/List';
30 import Divider from '@mui/material/Divider';
32 import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
33 import { faProjectDiagram } from '@fortawesome/free-solid-svg-icons';
35 import ListItemLink from '../components/material-ui/listItemLink';
37 import connect, { Connect } from '../flux/connect';
38 import { MenuAction } from '../actions/menuAction';
39 import * as classNames from 'classnames';
40 import { transportPCEUrl } from '../app';
43 const drawerWidth = 240;
45 const extraLinks = (window as any)._odluxExtraLinks as [string, string][];
47 const styles = (theme: Theme) => createStyles({
52 toolbar: theme.mixins.toolbar as any,
56 transition: theme.transitions.create('width', {
57 easing: theme.transitions.easing.sharp,
58 duration: theme.transitions.duration.enteringScreen,
62 transition: theme.transitions.create('width', {
63 easing: theme.transitions.easing.sharp,
64 duration: theme.transitions.duration.leavingScreen,
67 width: theme.spacing(7),
68 [theme.breakpoints.up('sm')]: {
69 width: theme.spacing(9),
79 borderTop: "2px solid #cfcfcf",
83 justifyContent: "space-around"
86 margin: theme.spacing(1)+1,
87 fontSize: theme.typography.fontSize-2,
91 const tabletWidthBreakpoint = 768;
93 export const NavigationMenu = withStyles(styles)(connect()(({ classes, state, dispatch }: WithStyles<typeof styles> & Connect & Connect) => {
94 const { user } = state.framework.authenticationState;
95 const isOpen = state.framework.applicationState.isMenuOpen;
96 const closedByUser = state.framework.applicationState.isMenuClosedByUser;
97 const transportUrl = state.framework.applicationState.transportpceUrl;
99 const [responsive, setResponsive] = React.useState(false);
101 //collapse menu on mount if necessary
102 React.useEffect(()=>{
104 if(isOpen && window.innerWidth <= tabletWidthBreakpoint){
107 dispatch(new MenuAction(false));
112 React.useEffect(() => {
114 function handleResize() {
115 if (user && user.isValid) {
116 if (window.innerWidth < tabletWidthBreakpoint && !responsive) {
119 dispatch(new MenuAction(false));
122 } else if (window.innerWidth > tabletWidthBreakpoint && responsive) {
123 setResponsive(false);
125 dispatch(new MenuAction(true));
131 window.addEventListener("resize", handleResize);
135 window.removeEventListener("resize", handleResize);
139 React.useEffect(()=>{
140 // trigger a resize if menu changed in case elements have to re-arrange
141 window.dispatchEvent(new Event('menu-resized'));
144 let menuItems = state.framework.applicationRegistraion && Object.keys(state.framework.applicationRegistraion).map(key => {
145 const reg = state.framework.applicationRegistraion[key];
146 const icon = !reg.icon ? null :( typeof reg.icon === 'string' ? <img height={22} src={reg.icon} /> : <FontAwesomeIcon icon={reg.icon} /> )
150 to={reg.path || `/${reg.name}`}
151 primary={reg.menuEntry || reg.name}
152 secondary={reg.subMenuEntry}
157 if(transportUrl.length>0){
159 const transportPCELink = <ListItemLink
162 primary={"TransportPCE"}
163 icon={<FontAwesomeIcon icon={faProjectDiagram} />}
166 const linkFound = menuItems.find(obj => obj.key === "linkCalculation");
169 const index = menuItems.indexOf(linkFound);
170 menuItems.splice(index + 1, 0, transportPCELink);
172 menuItems.push(transportPCELink);
181 classNames(classes.drawer, {
182 [classes.drawerOpen]: isOpen,
183 [classes.drawerClose]: !isOpen
187 paper: classes.drawerPaper,
190 {user && user.isValid && <>
191 <div className={classes.toolbar} />
192 { /* https://fiffty.github.io/react-treeview-mui/ */}
193 <List className={classes.menu} component="nav">
194 <ListItemLink exact to="/" primary="Home" icon={<FontAwesomeIcon icon={faHome} />} />
200 <ListItemLink to="/about" primary="About" icon={<FontAwesomeIcon icon={faAddressBook} />} />
201 {(false && process.env.NODE_ENV === "development")
204 <ListItemLink to="/test" primary="Test" icon={<FontAwesomeIcon icon={faHome} />} />
209 {isOpen && extraLinks && <div className={classes.optLinks}>
210 {extraLinks.map(linkInfo => (<a className={classes.link} href={linkInfo[1]}>{linkInfo[0]}</a>))}
217 export default NavigationMenu;