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 React from 'react';
19 import { Theme } from '@mui/material/styles';
20 import classNames from 'classnames';
22 import { WithStyles } from '@mui/styles';
23 import withStyles from '@mui/styles/withStyles';
24 import createStyles from '@mui/styles/createStyles';
26 import Drawer from '@mui/material/Drawer';
27 import List from '@mui/material/List';
29 import Divider from '@mui/material/Divider';
31 import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
32 import { faProjectDiagram } from '@fortawesome/free-solid-svg-icons';
34 import ListItemLink from '../components/material-ui/listItemLink';
36 import { connect, Connect } from '../flux/connect';
37 import { MenuAction } from '../actions/menuAction';
38 import { transportPCEUrl } from '../app';
40 const aboutIcon = require('../assets/icons/About.svg');
41 const homeIcon = require('../assets/icons/Home.svg');
42 const loginIcon = require('../assets/icons/User.svg');
43 const settingsIcon = require('../assets/icons/Tools.svg');
45 const drawerWidth = 240;
47 const extraLinks = (window as any)._odluxExtraLinks as [string, string][];
49 const styles = (theme: Theme) => createStyles({
54 toolbar: theme.mixins.toolbar as any,
58 transition: theme.transitions.create('width', {
59 easing: theme.transitions.easing.sharp,
60 duration: theme.transitions.duration.enteringScreen,
64 transition: theme.transitions.create('width', {
65 easing: theme.transitions.easing.sharp,
66 duration: theme.transitions.duration.leavingScreen,
69 width: theme.spacing(7),
70 [theme.breakpoints.up('sm')]: {
71 width: theme.spacing(9),
81 borderTop: "2px solid #cfcfcf",
85 justifyContent: "space-around"
88 margin: theme.spacing(1)+1,
89 fontSize: theme.typography.fontSize-2,
93 const tabletWidthBreakpoint = 768;
95 export const NavigationMenu = withStyles(styles)(connect()(({ classes, state, dispatch }: WithStyles<typeof styles> & Connect & Connect) => {
96 const { user } = state.framework.authenticationState;
97 const isOpen = state.framework.applicationState.isMenuOpen;
98 const closedByUser = state.framework.applicationState.isMenuClosedByUser;
99 const transportUrl = state.framework.applicationState.transportpceUrl;
101 const [responsive, setResponsive] = React.useState(false);
103 //collapse menu on mount if necessary
104 React.useEffect(()=>{
106 if(isOpen && window.innerWidth <= tabletWidthBreakpoint){
109 dispatch(new MenuAction(false));
114 React.useEffect(() => {
116 function handleResize() {
117 if (user && user.isValid) {
118 if (window.innerWidth < tabletWidthBreakpoint && !responsive) {
121 dispatch(new MenuAction(false));
124 } else if (window.innerWidth > tabletWidthBreakpoint && responsive) {
125 setResponsive(false);
127 dispatch(new MenuAction(true));
133 window.addEventListener("resize", handleResize);
137 window.removeEventListener("resize", handleResize);
141 React.useEffect(()=>{
142 // trigger a resize if menu changed in case elements have to re-arrange
143 window.dispatchEvent(new Event('menu-resized'));
146 let menuItems = state.framework.applicationRegistration && Object.keys(state.framework.applicationRegistration).map(key => {
147 const reg = state.framework.applicationRegistration[key];
151 to={reg.path || `/${reg.name}`}
152 primary={reg.menuEntry || reg.name}
153 secondary={reg.subMenuEntry}
154 icon={reg.icon || null} />
158 if(transportUrl.length>0){
160 const transportPCELink = <ListItemLink
163 primary={"TransportPCE"}
164 icon={faProjectDiagram}
167 const linkFound = menuItems.find(obj => obj.key === "microwave");
170 const index = menuItems.indexOf(linkFound);
171 menuItems.splice(index + 1, 0, transportPCELink);
173 menuItems.push(transportPCELink);
182 classNames(classes.drawer, {
183 [classes.drawerOpen]: isOpen,
184 [classes.drawerClose]: !isOpen
188 paper: classes.drawerPaper,
191 {user && user.isValid && <>
192 <div className={classes.toolbar} />
193 { /* https://fiffty.github.io/react-treeview-mui/ */}
194 <List className={classes.menu} component="nav">
195 <ListItemLink exact to="/" primary="Home" icon={homeIcon} />
201 <ListItemLink to="/about" primary="About" icon={aboutIcon} />
202 {(false && process.env.NODE_ENV === "development")
205 <ListItemLink to="/test" primary="Test" icon={settingsIcon} />
210 {isOpen && extraLinks && <div className={classes.optLinks}>
211 {extraLinks.map(linkInfo => (<a className={classes.link} href={linkInfo[1]}>{linkInfo[0]}</a>))}
218 export default NavigationMenu;