ba2a0e92d20e2208bea65269b427d8cec47a4d89
[aai/sparky-fe.git] / src / app / MainScreenWrapper.jsx
1 /*
2  * ============LICENSE_START===================================================
3  * SPARKY (AAI UI service)
4  * ============================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
8  * ============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=====================================================
21  *
22  * ECOMP and OpenECOMP are trademarks
23  * and service marks of AT&T Intellectual Property.
24  */
25
26 import React, {Component} from 'react';
27 import {connect} from 'react-redux';
28
29 import TierSupport from './tierSupport/TierSupport.jsx';
30 import VnfSearch from './vnfSearch/VnfSearch.jsx';
31 import MainScreenHeader from './MainScreenHeader.jsx';
32
33 import DynamicViewLoader from
34   'generic-components/dynamicViewLoader/dynamicViewLoader.jsx';
35
36 import {
37   Route,
38   HashRouter as Router,
39   Switch,
40   Redirect
41 } from 'react-router-dom';
42
43 import {
44   windowResize
45 } from './MainScreenWrapperActionHelper.js';
46
47 import customViews from 'resources/views/customViews.json';
48
49 const mapStateToProps = ({mainWrapper}) => {
50   let {
51         showMenu = false,
52         toggleButtonActive = false
53       } = mainWrapper;
54
55   return {
56     showMenu,
57     toggleButtonActive
58   };
59 };
60
61 const mapActionsToProps = (dispatch) => {
62   return {
63     onWindowSizeChange: () => dispatch(windowResize())
64   };
65 };
66
67 class MainScreenWrapper extends Component {
68
69   constructor() {
70     super();
71     window.addEventListener('resize', () => {
72       this.props.onWindowSizeChange();
73     });
74   }
75
76   render() {
77     let customViewList = [];
78
79     // add all custom views
80     for (let view in customViews) {
81       customViewList.push(
82         <Route path={'/' + customViews[view]['viewName']}
83                component={DynamicViewLoader}/>
84       );
85     }
86
87     return (
88       <Router>
89         <div>
90           <Switch>
91             <Redirect from='/' exact to='/viewInspect'/>
92           </Switch>
93           <Route path='/' component={MainScreenHeader}/>
94           <Route path='/viewInspect/:viParam?' component={TierSupport}/>
95           <Route path='/vnfSearch/:vnfParam?' component={VnfSearch}/>
96           {customViewList}
97         </div>
98       </Router>
99     );
100   }
101 }
102
103 export default connect(mapStateToProps, mapActionsToProps)(MainScreenWrapper);