15604275c3267a68efa5dfb6aec2a5bb928114a6
[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 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 });