2 * ============LICENSE_START========================================================================
\r
3 * ONAP : ccsdk feature sdnr wt odlux
\r
4 * =================================================================================================
\r
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
\r
6 * =================================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
\r
8 * in compliance with the License. You may obtain a copy of the License at
\r
10 * http://www.apache.org/licenses/LICENSE-2.0
\r
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
\r
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
\r
14 * or implied. See the License for the specific language governing permissions and limitations under
\r
16 * ============LICENSE_END==========================================================================
\r
18 import * as React from 'react';
\r
19 import { withStyles, WithStyles, createStyles, Theme } from '@material-ui/core/styles';
\r
21 import { faHome, faAddressBook } from '@fortawesome/free-solid-svg-icons';
\r
23 import Drawer from '@material-ui/core/Drawer';
\r
24 import List from '@material-ui/core/List';
\r
26 import Divider from '@material-ui/core/Divider';
\r
28 import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
\r
30 import ListItemLink from '../components/material-ui/listItemLink';
\r
32 import connect, { Connect, IDispatcher } from '../flux/connect';
\r
33 import { MenuAction } from '../actions/menuAction';
\r
34 import * as classNames from 'classnames';
\r
36 const drawerWidth = 240;
\r
38 const styles = (theme: Theme) => createStyles({
\r
40 position: 'relative',
\r
43 toolbar: theme.mixins.toolbar as any,
\r
46 transition: theme.transitions.create('width', {
\r
47 easing: theme.transitions.easing.sharp,
\r
48 duration: theme.transitions.duration.enteringScreen,
\r
52 transition: theme.transitions.create('width', {
\r
53 easing: theme.transitions.easing.sharp,
\r
54 duration: theme.transitions.duration.leavingScreen,
\r
56 overflowX: 'hidden',
\r
57 width: theme.spacing(7) + 1,
\r
58 [theme.breakpoints.up('sm')]: {
\r
59 width: theme.spacing(9) + 1,
\r
64 const tabletWidthBreakpoint = 768;
\r
66 export const NavigationMenu = withStyles(styles)(connect()(({ classes, state, dispatch }: WithStyles<typeof styles> & Connect & Connect) => {
\r
67 const { user } = state.framework.authenticationState
\r
68 const isOpen = state.framework.applicationState.isMenuOpen
\r
69 const closedByUser = state.framework.applicationState.isMenuClosedByUser
\r
71 const [responsive, setResponsive] = React.useState(false);
\r
73 React.useEffect(() => {
\r
75 function handleResize() {
\r
76 if (user && user.isValid) {
\r
77 if (window.innerWidth < tabletWidthBreakpoint && !responsive) {
\r
78 setResponsive(true);
\r
79 if (!closedByUser) {
\r
80 console.log("responsive menu collapsed")
\r
81 dispatch(new MenuAction(false));
\r
84 } else if (window.innerWidth > tabletWidthBreakpoint && responsive) {
\r
85 setResponsive(false);
\r
86 if (!closedByUser) {
\r
87 console.log("responsive menu restored")
\r
88 dispatch(new MenuAction(true));
\r
94 window.addEventListener("resize", handleResize);
\r
98 window.removeEventListener("resize", handleResize);
\r
104 variant="permanent"
\r
107 [classes.drawerOpen]: isOpen,
\r
108 [classes.drawerClose]: !isOpen
\r
112 paper: classes.drawerPaper,
\r
115 {user && user.isValid && <>
\r
116 <div className={classes.toolbar} />
\r
117 { /* https://fiffty.github.io/react-treeview-mui/ */}
\r
118 <List component="nav">
\r
119 <ListItemLink exact to="/" primary="Home" icon={<FontAwesomeIcon icon={faHome} />} />
\r
122 state.framework.applicationRegistraion && Object.keys(state.framework.applicationRegistraion).map(key => {
\r
123 const reg = state.framework.applicationRegistraion[key];
\r
127 to={reg.path || `/${reg.name}`}
\r
128 primary={reg.menuEntry || reg.name}
\r
129 secondary={reg.subMenuEntry}
\r
130 icon={reg.icon && <FontAwesomeIcon icon={reg.icon} /> || null} />
\r
135 <ListItemLink to="/about" primary="About" icon={<FontAwesomeIcon icon={faAddressBook} />} />
\r
136 {(false && process.env.NODE_ENV === "development")
\r
139 <ListItemLink to="/test" primary="Test" icon={<FontAwesomeIcon icon={faHome} />} />
\r
149 export default NavigationMenu;