29682c295dfd531e2cd2754b8ec726d4bb952b84
[aai/sparky-fe.git] / src / generic-components / dynamicViewLoader / dynamicViewLoader.jsx
1 /*
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017 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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23 import React, {Component} from 'react';
24 import {connect} from 'react-redux';
25
26 import DateRangeSelector from 'generic-components/dateRangeSelector/DateRangeSelector.jsx';
27 import ComponentManager from 'generic-components/componentManager/ComponentManager.jsx';
28 import {DYNAMIC_VIEW_LOADER_TITLE} from 'generic-components/dynamicViewLoader/DynamicViewLoaderConstants.js';
29 import {processLayoutSourceChange} from 'generic-components/dynamicViewLoader/DynamicViewLoaderActions.js';
30 import {visualizationProviderProperties} from 'generic-components/dynamicViewLoader/VisualizationProvider.js';
31 import {LAYOUT_STATIC} from 'generic-components/componentManager/ComponentManagerConstants.js';
32
33 import i18n from 'utils/i18n/i18n';
34 import customViews from 'resources/views/customViews.json';
35
36 const mapStateToProps =
37         ({dynamicViewReducer: {dynamicViewLoadData}}) => {
38           let {
39                 viewTitle = i18n(DYNAMIC_VIEW_LOADER_TITLE),
40                 layoutSource = {}
41               } = dynamicViewLoadData;
42
43           return {
44             viewTitle,
45             layoutSource
46           };
47         };
48
49 let mapActionToProps = (dispatch) => {
50   return {
51     onLayoutSourceChange: (layoutSource) => {
52       dispatch(processLayoutSourceChange(layoutSource));
53     }
54   };
55 };
56
57 class DynamicViewLoader extends Component {
58   static propTypes = {
59     viewTitle: React.PropTypes.string,
60     layoutSource: React.PropTypes.object
61   };
62
63   componentWillMount() {
64     let viewName = this.props.location.pathname.split('/');
65
66     for (let view in customViews) {
67       if (customViews[view]['viewName'] === viewName[1]) {
68         this.props.onLayoutSourceChange(customViews[view]['layoutProperties']);
69       }
70     }
71   }
72
73   render() {
74     let {viewTitle, layoutSource} = this.props;
75
76     return (
77       <div>
78         <div className='secondary-header'>
79           <span className='secondary-title'>
80             {viewTitle}
81           </span>
82           <DateRangeSelector />
83         </div>
84         <ComponentManager
85           componentPropertiesProvider={visualizationProviderProperties}
86           layoutType={LAYOUT_STATIC}
87           layoutFormat={layoutSource}
88           showHeader={true}
89           showTitle={true}
90           showBorder={false}/>
91       </div>
92     );
93   }
94 }
95 export default connect(mapStateToProps, mapActionToProps)(DynamicViewLoader);