e0f6a941b6864ff1332e689a1ce3723df02a489c
[aai/sparky-fe.git] / src / generic-components / dynamicViewLoader / dynamicViewLoader.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 DateRangeSelector from 'generic-components/dateRangeSelector/DateRangeSelector.jsx';
30 import ComponentManager from 'generic-components/componentManager/ComponentManager.jsx';
31 import {DYNAMIC_VIEW_LOADER_TITLE} from 'generic-components/dynamicViewLoader/DynamicViewLoaderConstants.js';
32 import {processLayoutSourceChange} from 'generic-components/dynamicViewLoader/DynamicViewLoaderActions.js';
33 import {visualizationProviderProperties} from 'generic-components/dynamicViewLoader/VisualizationProvider.js';
34 import {LAYOUT_STATIC} from 'generic-components/componentManager/ComponentManagerConstants.js';
35
36 import i18n from 'utils/i18n/i18n';
37 import customViews from 'resources/views/customViews.json';
38
39 const mapStateToProps =
40         ({dynamicViewReducer: {dynamicViewLoadData}}) => {
41           let {
42                 viewTitle = i18n(DYNAMIC_VIEW_LOADER_TITLE),
43                 layoutSource = {}
44               } = dynamicViewLoadData;
45
46           return {
47             viewTitle,
48             layoutSource
49           };
50         };
51
52 let mapActionToProps = (dispatch) => {
53   return {
54     onLayoutSourceChange: (layoutSource) => {
55       dispatch(processLayoutSourceChange(layoutSource));
56     }
57   };
58 };
59
60 class DynamicViewLoader extends Component {
61   static propTypes = {
62     viewTitle: React.PropTypes.string,
63     layoutSource: React.PropTypes.object
64   };
65
66   componentWillMount() {
67     let viewName = this.props.location.pathname.split('/');
68
69     for (let view in customViews) {
70       if (customViews[view]['viewName'] === viewName[1]) {
71         this.props.onLayoutSourceChange(customViews[view]['layoutProperties']);
72       }
73     }
74   }
75
76   render() {
77     let {viewTitle, layoutSource} = this.props;
78
79     return (
80       <div>
81         <div className='secondary-header'>
82           <span className='secondary-title'>
83             {viewTitle}
84           </span>
85           <DateRangeSelector />
86         </div>
87         <ComponentManager
88           componentPropertiesProvider={visualizationProviderProperties}
89           layoutType={LAYOUT_STATIC}
90           layoutFormat={layoutSource}
91           showHeader={true}
92           showTitle={true}
93           showBorder={false}/>
94       </div>
95     );
96   }
97 }
98 export default connect(mapStateToProps, mapActionToProps)(DynamicViewLoader);