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