e743a70dc5fa73f962120685404d8bbd76da7922
[aai/sparky-fe.git] / src / app / tierSupport / selectedNodeDetails / SelectedNodeDetailsReducer.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
31 export default (state = {}, action) => {
32   switch (action.type) {
33     case tierSupportActionTypes.TS_NODE_SEARCH_RESULTS:
34       for (const node of action.data.nodes) {
35         if (node.nodeMeta.searchTarget === true) {
36           return {
37             ...state,
38             nodeData: node.itemProperties,
39             nodeType: node.itemType,
40             uid: node.itemNameValue
41           };
42         }
43       }
44       return {
45         ...state,
46         nodeData: [],
47         nodeType: '',
48         uid: ''
49       };
50
51     case tierSupportActionTypes.TS_GRAPH_NODE_SELECTED:
52       return {
53         ...state,
54         nodeData: action.data.itemProperties,
55         nodeType: action.data.itemType,
56         uid: action.data.itemNameValue
57       };
58
59     // else fall through to the TIER_SUPPORT_CLEAR_DATA case
60     case globalAutoCompleteSearchBarActionTypes.SEARCH_WARNING_EVENT:
61     case tierSupportActionTypes.TIER_SUPPORT_NETWORK_ERROR:
62     case tierSupportActionTypes.TIER_SUPPORT_CLEAR_DATA:
63     case tierSupportActionTypes.TS_NODE_SEARCH_NO_RESULTS:
64       return {
65         ...state,
66         nodeData: [],
67         nodeType: '',
68         uid: ''
69       };
70   }
71   return state;
72 };