Updating versions of Sparky FE files
[aai/sparky-fe.git] / src / app / globalAutoCompleteSearchBar / GlobalAutoCompleteSearchBarReducer.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 i18n from 'utils/i18n/i18n';
24
25 import {
26   globalAutoCompleteSearchBarActionTypes,
27   NO_MATCHES_FOUND
28 } from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarConstants.js';
29 import {
30   MESSAGE_LEVEL_WARNING,
31   MESSAGE_LEVEL_DANGER
32 } from 'utils/GlobalConstants.js';
33
34 export default (state = {}, action) => {
35   switch (action.type) {
36     case globalAutoCompleteSearchBarActionTypes.SUGGESTION_FOUND:
37       return {
38         ...state,
39         suggestions: action.data.suggestions,
40         cachedSuggestions: action.data.suggestions,
41         feedbackMsgText: action.data.errorMsg,
42         feedbackMsgSeverity: MESSAGE_LEVEL_DANGER
43       };
44     case globalAutoCompleteSearchBarActionTypes.SUGGESTION_NOT_FOUND:
45       return {
46         ...state,
47         suggestions: [{ text: i18n(NO_MATCHES_FOUND)}],
48         cachedSuggestions: [{
49           entityType: i18n(NO_MATCHES_FOUND)
50         }],
51         feedbackMsgText: '',
52         feedbackMsgSeverity: ''
53       };
54     case globalAutoCompleteSearchBarActionTypes.CLEAR_SUGGESTIONS_TEXT_FIELD:
55       return {
56         ...state,
57         suggestions: [],
58         cachedSuggestions: [],
59         value: '',
60         feedbackMsgText: '',
61         feedbackMsgSeverity: '',
62         clearSearchText: false
63       };
64     case globalAutoCompleteSearchBarActionTypes.CLEAR_SUGGESTIONS:
65       return {
66         ...state,
67         suggestions: []
68       };
69     case globalAutoCompleteSearchBarActionTypes.SUGGESTION_CHANGED:
70       return {
71         ...state,
72         value: action.data,
73         feedbackMsgText: '',
74         feedbackMsgSeverity: ''
75       };
76     case globalAutoCompleteSearchBarActionTypes.SUGGESTION_CLICKED:
77       return {
78         ...state,
79         selectedSuggestion: action.data.selectedSuggestion,
80         performPrepareVisualization: true,
81         feedbackMsgText: '',
82         feedbackMsgSeverity: ''
83       };
84     case globalAutoCompleteSearchBarActionTypes.NETWORK_ERROR:
85       return {
86         ...state,
87         suggestions: [],
88         cachedSuggestions: [],
89         feedbackMsgText: action.data.errorMsg,
90         feedbackMsgSeverity: MESSAGE_LEVEL_DANGER
91       };
92     case globalAutoCompleteSearchBarActionTypes.SEARCH_WARNING_EVENT:
93       return {
94         ...state,
95         suggestions: [],
96         cachedSuggestions: [],
97         feedbackMsgText: action.data.errorMsg,
98         feedbackMsgSeverity: MESSAGE_LEVEL_WARNING
99       };
100   }
101   return state;
102 };