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