Initial coomit for AAI-UI(sparky-fe)
[aai/sparky-fe.git] / src / app / vnfSearch / VnfSearchReducer.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 import {vnfActionTypes} from 'app/vnfSearch/VnfSearchConstants.js';
26 import {
27   CHART_ORCH_STATUS,
28   CHART_PROV_STATUS,
29   TOTAL_VNF_COUNT
30 } from 'app/vnfSearch/VnfSearchConstants.js';
31 import {ERROR_RETRIEVING_DATA} from 'app/networking/NetworkConstants.js';
32 import {MESSAGE_LEVEL_DANGER} from 'utils/GlobalConstants.js';
33 import {
34   globalAutoCompleteSearchBarActionTypes
35 } from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarConstants.js';
36
37 export default (state = {}, action) => {
38   let data = action.data;
39   switch (action.type) {
40
41     case vnfActionTypes.COUNT_BY_PROV_STATUS_RECEIVED:
42       return {
43         ...state,
44         processedProvStatusCountChartData: data.provStatusCountChartData.chartData,
45         feedbackMsgText: '',
46         feedbackMsgSeverity: ''
47       };
48
49     case vnfActionTypes.COUNT_BY_ORCH_STATUS_RECEIVED:
50       return {
51         ...state,
52         processedOrchStatusCountChartData: data.orchStatusCountChartData.chartData,
53         feedbackMsgText: '',
54         feedbackMsgSeverity: ''
55       };
56     case vnfActionTypes.TOTAL_VNF_COUNT_RECEIVED:
57       return {
58         ...state,
59         count: data.count,
60         feedbackMsgText: '',
61         feedbackMsgSeverity: ''
62       };
63     case vnfActionTypes.ERROR_NO_DATA_FOR_PROV_STATUS_IN_SEARCH_RANGE_RECEIVED:
64       return {
65         ...state,
66         processedProvStatusCountChartData: CHART_PROV_STATUS.emptyData,
67       };
68     case vnfActionTypes.ERROR_NO_DATA_FOR_ORCH_STATUS_IN_SEARCH_RANGE_RECEIVED:
69       return {
70         ...state,
71         processedOrchStatusCountChartData: CHART_ORCH_STATUS.emptyData,
72       };
73     case vnfActionTypes.ERROR_NO_COUNT_RECEIVED:
74       return {
75         ...state,
76         count: TOTAL_VNF_COUNT.emptyValue,
77       };
78     case vnfActionTypes.VNF_NETWORK_ERROR:
79       return {
80         ...state,
81         processedProvStatusCountChartData: CHART_PROV_STATUS.emptyData,
82         processedOrchStatusCountChartData: CHART_ORCH_STATUS.emptyData,
83         count: TOTAL_VNF_COUNT.emptyValue,
84         feedbackMsgText: ERROR_RETRIEVING_DATA,
85         feedbackMsgSeverity: MESSAGE_LEVEL_DANGER
86       };
87     case globalAutoCompleteSearchBarActionTypes.SEARCH_WARNING_EVENT:
88       return {
89         ...state,
90         processedProvStatusCountChartData: CHART_PROV_STATUS.emptyData,
91         processedOrchStatusCountChartData: CHART_ORCH_STATUS.emptyData,
92         count: TOTAL_VNF_COUNT.emptyValue
93       };
94   }
95
96   return state;
97 };