493afaa9e62c9b8d05aa749b9735265ec7172957
[aai/sparky-fe.git] / src / app / tierSupport / launchExternalResource / LaunchExternalResourceReducer.js
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 {tierSupportActionTypes} from 'app/tierSupport/TierSupportConstants.js';
27 import {
28   globalAutoCompleteSearchBarActionTypes
29 } from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarConstants.js';
30 import {isEmpty} from 'lodash';
31
32 export default (state = {}, action) => {
33   switch (action.type) {
34     case tierSupportActionTypes.TS_NODE_SEARCH_RESULTS:
35       if(!isEmpty(action.data.nodes)){
36         for (const node of action.data.nodes) {
37           if (node.nodeMeta.searchTarget === true) {
38             let externalResourcePayload = {};
39             if(!isEmpty(node.externalResourcePayload)){
40               externalResourcePayload = node.externalResourcePayload;
41             }
42             return {
43               ...state,
44               externalResourcePayload: externalResourcePayload
45             };
46           }
47         }
48       }
49       return {
50         ...state,
51         externalResourcePayload: {}
52       };
53
54     case tierSupportActionTypes.TS_GRAPH_NODE_SELECTED:
55       let externalResourcePayload;
56       if(action.data.externalResourcePayload){
57         externalResourcePayload = action.data.externalResourcePayload;
58       } else {
59         externalResourcePayload = {};
60       }
61       return {
62         ...state,
63         externalResourcePayload: externalResourcePayload
64       };
65
66     case globalAutoCompleteSearchBarActionTypes.SEARCH_WARNING_EVENT:
67     case tierSupportActionTypes.TIER_SUPPORT_NETWORK_ERROR:
68     case tierSupportActionTypes.TIER_SUPPORT_CLEAR_DATA:
69     case tierSupportActionTypes.TS_NODE_SEARCH_NO_RESULTS:
70       return {
71         ...state,
72         externalResourcePayload: {}
73       };
74   }
75   return state;
76 };