Adding option for configurable header
[aai/sparky-fe.git] / src / app / globalAutoCompleteSearchBar / GlobalAutoCompleteSearchBarReducer.js
1 /*
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 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 import i18n from 'utils/i18n/i18n';
22
23 import {
24   globalAutoCompleteSearchBarActionTypes,
25   NO_MATCHES_FOUND
26 } from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarConstants.js';
27 import {
28   MESSAGE_LEVEL_WARNING,
29   MESSAGE_LEVEL_DANGER
30 } from 'utils/GlobalConstants.js';
31
32 export default (state = {}, action) => {
33   switch (action.type) {
34     case globalAutoCompleteSearchBarActionTypes.SUGGESTION_FOUND:
35       return {
36         ...state,
37         suggestions: action.data.suggestions,
38         cachedSuggestions: action.data.suggestions,
39         feedbackMsgText: action.data.errorMsg,
40         feedbackMsgSeverity: MESSAGE_LEVEL_DANGER
41       };
42     case globalAutoCompleteSearchBarActionTypes.SUGGESTION_NOT_FOUND:
43       return {
44         ...state,
45         suggestions: [{ text: i18n(NO_MATCHES_FOUND)}],
46         cachedSuggestions: [{
47           entityType: i18n(NO_MATCHES_FOUND)
48         }],
49         feedbackMsgText: '',
50         feedbackMsgSeverity: ''
51       };
52     case globalAutoCompleteSearchBarActionTypes.CLEAR_SUGGESTIONS_TEXT_FIELD:
53       return {
54         ...state,
55         suggestions: [],
56         cachedSuggestions: [],
57         value: '',
58         feedbackMsgText: '',
59         feedbackMsgSeverity: '',
60         clearSearchText: false
61       };
62     case globalAutoCompleteSearchBarActionTypes.CLEAR_SUGGESTIONS:
63       return {
64         ...state,
65         suggestions: []
66       };
67     case globalAutoCompleteSearchBarActionTypes.SUGGESTION_CHANGED:
68       return {
69         ...state,
70         value: action.data,
71         feedbackMsgText: '',
72         feedbackMsgSeverity: ''
73       };
74     case globalAutoCompleteSearchBarActionTypes.SUGGESTION_CLICKED:
75       return {
76         ...state,
77         selectedSuggestion: action.data.selectedSuggestion,
78         performPrepareVisualization: true,
79         feedbackMsgText: '',
80         feedbackMsgSeverity: ''
81       };
82     case globalAutoCompleteSearchBarActionTypes.NETWORK_ERROR:
83       return {
84         ...state,
85         suggestions: [],
86         cachedSuggestions: [],
87         feedbackMsgText: action.data.errorMsg,
88         feedbackMsgSeverity: MESSAGE_LEVEL_DANGER
89       };
90     case globalAutoCompleteSearchBarActionTypes.SEARCH_WARNING_EVENT:
91       return {
92         ...state,
93         suggestions: [],
94         cachedSuggestions: [],
95         feedbackMsgText: action.data.errorMsg,
96         feedbackMsgSeverity: MESSAGE_LEVEL_WARNING
97       };
98   }
99   return state;
100 };