Initial coomit for AAI-UI(sparky-fe)
[aai/sparky-fe.git] / src / app / vnfSearch / VnfSearch.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 import React, {Component} from 'react';
26 import {connect} from 'react-redux';
27 import {
28   VNF_TITLE,
29   VNFS_ROUTE,
30   DEFAULT_VNFS_SEARCH_HASH
31 } from 'app/vnfSearch/VnfSearchConstants.js';
32 import {
33   processTotalVnfVisualizationOnSearchChange,
34   processOrchStatusVisualizationOnSearchChange,
35   processProvStatusVisualizationOnSearchChange,
36   setNotificationText
37 } from 'app/vnfSearch/VnfSearchActions.js';
38 import VnfSearchOrchStatusVisualizations from 'app/vnfSearch/VnfSearchOrchestratedStatusVisualization.jsx';
39 import VnfSearchProvStatusVisualizations from 'app/vnfSearch/VnfSearchProvStatusVisualization.jsx';
40 import VnfSearchTotalCountVisualization from 'app/vnfSearch/VnfSearchTotalCountVisualization.jsx';
41 import i18n from 'utils/i18n/i18n';
42 import {changeUrlAddress, buildRouteObj} from 'utils/Routes.js';
43
44 const mapStateToProps = ({vnfSearch}) => {
45   let {
46         feedbackMsgText = '',
47         feedbackMsgSeverity = ''
48       } = vnfSearch;
49
50   return {
51     feedbackMsgText,
52     feedbackMsgSeverity
53   };
54 };
55
56 let mapActionToProps = (dispatch) => {
57   return {
58     onReceiveNewParams: (vnfParam) => {
59       dispatch(processTotalVnfVisualizationOnSearchChange(vnfParam));
60       dispatch(processOrchStatusVisualizationOnSearchChange(vnfParam));
61       dispatch(processProvStatusVisualizationOnSearchChange(vnfParam));
62     },
63     onMessageStateChange: (msgText, msgSeverity) => {
64       dispatch(setNotificationText(msgText, msgSeverity));
65     }
66   };
67 };
68
69 class vnfSearch extends Component {
70   componentWillMount() {
71     if (this.props.match &&
72       this.props.match.params &&
73       this.props.match.params.vnfParam) {
74       this.props.onReceiveNewParams(this.props.match.params.vnfParam);
75     } else {
76       // render using default search params (hash for "VNFs")
77       this.props.onReceiveNewParams(DEFAULT_VNFS_SEARCH_HASH);
78       changeUrlAddress(buildRouteObj(VNFS_ROUTE, DEFAULT_VNFS_SEARCH_HASH),
79         this.props.history);
80     }
81
82     if (this.props.feedbackMsgText) {
83       this.props.onMessageStateChange(this.props.feedbackMsgText,
84         this.props.feedbackMsgSeverity);
85     }
86   }
87
88   componentWillReceiveProps(nextProps) {
89     if (nextProps.match.params.vnfParam) {
90       if (nextProps.match.params.vnfParam !==
91         this.props.match.params.vnfParam) {
92         this.props.onReceiveNewParams(nextProps.match.params.vnfParam);
93       }
94     } else if (this.props.match.params.vnfParam) {
95       // currently on VNF page and somebody has clicked the VNF NavLink
96       // want to reload the view with the default params (hash for "NFVs")
97       this.props.onReceiveNewParams(DEFAULT_VNFS_SEARCH_HASH);
98       changeUrlAddress(buildRouteObj(VNFS_ROUTE, DEFAULT_VNFS_SEARCH_HASH),
99         this.props.history);
100     }
101
102     if (nextProps.feedbackMsgText &&
103       nextProps.feedbackMsgText !==
104       this.props.feedbackMsgText) {
105       this.props.onMessageStateChange(nextProps.feedbackMsgText,
106         nextProps.feedbackMsgSeverity);
107     }
108   }
109
110   componentWillUnmount() {
111     // resetting to default params so on relaunch there will be no
112     // visibility of old searches
113     this.props.onReceiveNewParams(DEFAULT_VNFS_SEARCH_HASH);
114   }
115
116   render() {
117     return (
118       <div>
119         <div className='secondary-header'>
120           <span className='secondary-title'>{i18n(VNF_TITLE)}</span>
121         </div>
122         <VnfSearchTotalCountVisualization />
123         <VnfSearchProvStatusVisualizations />
124         <VnfSearchOrchStatusVisualizations />
125       </div>
126     );
127   }
128 }
129 export default connect(mapStateToProps, mapActionToProps)(vnfSearch);