332cdcf449c8fdf674eb594d92fd7e9a3498bd0f
[aai/sparky-fe.git] / src / generic-components / dynamicViewLoader / dynamicViewLoader.jsx
1 /*
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 import React, {Component} from 'react';
22 import {connect} from 'react-redux';
23
24 import DateRangeSelector from 'generic-components/dateRangeSelector/DateRangeSelector.jsx';
25 import ComponentManager from 'generic-components/componentManager/ComponentManager.jsx';
26 import {DYNAMIC_VIEW_LOADER_TITLE} from 'generic-components/dynamicViewLoader/DynamicViewLoaderConstants.js';
27 import {processLayoutSourceChange} from 'generic-components/dynamicViewLoader/DynamicViewLoaderActions.js';
28 import {visualizationProviderProperties} from 'generic-components/dynamicViewLoader/VisualizationProvider.js';
29 import {LAYOUT_STATIC} from 'generic-components/componentManager/ComponentManagerConstants.js';
30
31 import i18n from 'utils/i18n/i18n';
32 import customViews from 'resources/views/customViews.json';
33
34 const mapStateToProps =
35         ({dynamicViewReducer: {dynamicViewLoadData}}) => {
36           let {
37                 viewTitle = i18n(DYNAMIC_VIEW_LOADER_TITLE),
38                 layoutSource = {}
39               } = dynamicViewLoadData;
40
41           return {
42             viewTitle,
43             layoutSource
44           };
45         };
46
47 let mapActionToProps = (dispatch) => {
48   return {
49     onLayoutSourceChange: (layoutSource) => {
50       dispatch(processLayoutSourceChange(layoutSource));
51     }
52   };
53 };
54
55 class DynamicViewLoader extends Component {
56   static propTypes = {
57     viewTitle: React.PropTypes.string,
58     layoutSource: React.PropTypes.object
59   };
60
61   componentWillMount() {
62     let viewName = this.props.location.pathname.split('/');
63
64     for (let view in customViews) {
65       if (customViews[view]['viewName'] === viewName[1]) {
66         this.props.onLayoutSourceChange(customViews[view]['layoutProperties']);
67       }
68     }
69   }
70
71   render() {
72     let {viewTitle, layoutSource} = this.props;
73
74     return (
75       <div>
76         <div className='secondary-header'>
77           <span className='secondary-title'>
78             {viewTitle}
79           </span>
80           <DateRangeSelector />
81         </div>
82         <ComponentManager
83           componentPropertiesProvider={visualizationProviderProperties}
84           layoutType={LAYOUT_STATIC}
85           layoutFormat={layoutSource}
86           showHeader={true}
87           showTitle={true}
88           showBorder={false}/>
89       </div>
90     );
91   }
92 }
93 export default connect(mapStateToProps, mapActionToProps)(DynamicViewLoader);