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