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