7dd6ab0e179e0e24305fb1efcf0f408f8210d724
[aai/sparky-fe.git] / src / app / tierSupport / TierSupportReducer.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 {combineReducers} from 'redux';
27 import ForceDirectedGraph from 'generic-components/graph/ForceDirectedGraph.jsx';
28 import {aaiActionTypes} from 'app/MainScreenWrapperConstants.js';
29 import {
30   tierSupportActionTypes, TSUI_GRAPH_MENU_NODE_DETAILS
31 } from 'app/tierSupport/TierSupportConstants.js';
32 import SelectedNodeDetailsReducer from 'app/tierSupport/selectedNodeDetails/SelectedNodeDetailsReducer.js';
33 import GlobalAutoCompleteSearchBarReducer from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarReducer.js';
34 import {
35   MESSAGE_LEVEL_DANGER, MESSAGE_LEVEL_WARNING
36 } from 'utils/GlobalConstants.js';
37 import {
38   globalAutoCompleteSearchBarActionTypes
39 } from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarConstants.js';
40
41 export default combineReducers({
42   selectedNodeDetails: SelectedNodeDetailsReducer,
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 globalAutoCompleteSearchBarActionTypes.SEARCH_WARNING_EVENT:
93         let emptyNodesAndLinksWarningEvent = ForceDirectedGraph.generateNewProps([], [], {});
94         return {
95           ...state,
96           forceDirectedGraphRawData: emptyNodesAndLinksWarningEvent,
97           graphNodeSelectedMenu: TSUI_GRAPH_MENU_NODE_DETAILS
98         };
99       case aaiActionTypes.AAI_WINDOW_RESIZE:
100       case tierSupportActionTypes.SPLIT_PANE_RESIZE:
101         let splitPaneLeftSideElement = document.getElementsByClassName('Pane1');
102         if (splitPaneLeftSideElement.length > 0) {
103           let width = splitPaneLeftSideElement[0].offsetWidth;
104
105           return {
106             ...state, windowWidth: width, windowHeight: splitPaneLeftSideElement[0].offsetHeight
107           };
108         } else {
109           return state;
110         }
111     }
112
113     return state;
114   }
115 });