[AAI] Remove Robby Maharajh & Harish Kajur as committers
[aai/sparky-fe.git] / src / app / tierSupport / TierSupportReducer.js
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 {combineReducers} from 'redux';
22 import ForceDirectedGraph from 'generic-components/graph/ForceDirectedGraph.jsx';
23 import {aaiActionTypes} from 'app/MainScreenWrapperConstants.js';
24 import {
25   tierSupportActionTypes, TSUI_GRAPH_MENU_NODE_DETAILS
26 } from 'app/tierSupport/TierSupportConstants.js';
27 import SelectedNodeDetailsReducer from 'app/tierSupport/selectedNodeDetails/SelectedNodeDetailsReducer.js';
28 import GlobalAutoCompleteSearchBarReducer from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarReducer.js';
29 import LaunchInContextReducer from 'app/tierSupport/launchExternalResource/LaunchExternalResourceReducer.js';
30 import {
31   MESSAGE_LEVEL_DANGER, MESSAGE_LEVEL_WARNING
32 } from 'utils/GlobalConstants.js';
33 import {
34   globalAutoCompleteSearchBarActionTypes
35 } from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarConstants.js';
36
37 export default combineReducers({
38   selectedNodeDetails: SelectedNodeDetailsReducer,
39   launchExternalResourceReducer: LaunchInContextReducer,
40   globalAutoCompleteSearchBar: GlobalAutoCompleteSearchBarReducer,
41   tierSupportReducer: (state = {}, action) => {
42     switch (action.type) {
43       case tierSupportActionTypes.TS_NODE_SEARCH_RESULTS:
44         let graphData = ForceDirectedGraph.generateNewProps(action.data.nodes, action.data.links,
45           action.data.graphMeta);
46
47         return {
48           ...state,
49           forceDirectedGraphRawData: graphData,
50           feedbackMsgText: '',
51           feedbackMsgSeverity: ''
52         };
53       case tierSupportActionTypes.TS_GRAPH_NODE_MENU_SELECTED:
54         return {
55           ...state, graphNodeSelectedMenu: action.data
56         };
57       case tierSupportActionTypes.TS_NODE_SEARCH_NO_RESULTS:
58         let emptyNodesAndLinksNoResults = ForceDirectedGraph.generateNewProps([], [], {});
59         return {
60           ...state,
61           forceDirectedGraphRawData: emptyNodesAndLinksNoResults,
62           graphNodeSelectedMenu: TSUI_GRAPH_MENU_NODE_DETAILS,
63           feedbackMsgText: action.data.errorMsg,
64           feedbackMsgSeverity: MESSAGE_LEVEL_WARNING
65         };
66       case tierSupportActionTypes.TIER_SUPPORT_NETWORK_ERROR:
67         let emptyNodesAndLinksNetworkError = ForceDirectedGraph.generateNewProps([], [], {});
68         return {
69           ...state,
70           forceDirectedGraphRawData: emptyNodesAndLinksNetworkError,
71           graphNodeSelectedMenu: TSUI_GRAPH_MENU_NODE_DETAILS,
72           feedbackMsgText: action.data.errorMsg,
73           feedbackMsgSeverity: MESSAGE_LEVEL_DANGER
74         };
75       case tierSupportActionTypes.TIER_SUPPORT_CLEAR_DATA:
76         let emptyNodesAndLinksClearData = ForceDirectedGraph.generateNewProps([], [], {});
77         return {
78           ...state,
79           forceDirectedGraphRawData: emptyNodesAndLinksClearData,
80           graphNodeSelectedMenu: TSUI_GRAPH_MENU_NODE_DETAILS,
81           feedbackMsgText: '',
82           feedbackMsgSeverity: ''
83         };
84       case tierSupportActionTypes.TS_GRAPH_NODE_SELECTED:
85         return {
86           ...state,
87           nodeData: action.data
88         };
89       case tierSupportActionTypes.TIER_SUPPORT_ACTIVATE_BUSY_FEEDBACK:
90         return {
91           ...state,
92           enableBusyFeedback: true
93         };
94       case tierSupportActionTypes.TIER_SUPPORT_DISABLE_BUSY_FEEDBACK:
95         return {
96           ...state,
97           enableBusyFeedback: false
98         };
99       case globalAutoCompleteSearchBarActionTypes.SEARCH_WARNING_EVENT:
100         let emptyNodesAndLinksWarningEvent = ForceDirectedGraph.generateNewProps([], [], {});
101         return {
102           ...state,
103           forceDirectedGraphRawData: emptyNodesAndLinksWarningEvent,
104           graphNodeSelectedMenu: TSUI_GRAPH_MENU_NODE_DETAILS
105         };
106       case aaiActionTypes.AAI_WINDOW_RESIZE:
107       case tierSupportActionTypes.SPLIT_PANE_RESIZE:
108         let splitPaneLeftSideElement = document.getElementsByClassName('Pane1');
109         if (splitPaneLeftSideElement.length > 0) {
110           let width = splitPaneLeftSideElement[0].offsetWidth;
111
112           return {
113             ...state, windowWidth: width, windowHeight: splitPaneLeftSideElement[0].offsetHeight
114           };
115         } else {
116           return state;
117         }
118       case tierSupportActionTypes.TS_OVERLAY_NETWORK_CALLBACK_RESPONSE_RECEIVED:
119         let newNodeData = JSON.parse(JSON.stringify(action.data.curData));
120         newNodeData[action.data.paramName] = action.data.overlayData;
121         return {
122           ...state,
123           nodeData: newNodeData
124         };
125     }
126
127     return state;
128   }
129 });