2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 import {getTSUIElasticSearchQueryString} from 'app/networking/NetworkUtil.js';
22 import networkCall from 'app/networking/NetworkCalls.js';
27 } from 'app/networking/NetworkConstants.js';
30 globalAutoCompleteSearchBarActionTypes,
31 ERROR_INVALID_SEARCH_TERMS,
33 } from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarConstants.js';
35 getSetGlobalMessageEvent,
36 getClearGlobalMessageEvent
37 } from 'app/globalInlineMessageBar/GlobalInlineMessageBarActions.js';
40 function createSuggestionFoundEvent({suggestions}) {
42 type: globalAutoCompleteSearchBarActionTypes.SUGGESTION_FOUND,
47 function createSuggestionNotFoundEvent() {
49 type: globalAutoCompleteSearchBarActionTypes.SUGGESTION_NOT_FOUND
53 function createSuggestionChangedEvent(value) {
55 type: globalAutoCompleteSearchBarActionTypes.SUGGESTION_CHANGED,
60 function getInvalidQueryEvent(value) {
62 type: globalAutoCompleteSearchBarActionTypes.NETWORK_ERROR,
63 data: {value: value, errorMsg: ERROR_RETRIEVING_DATA}
67 function getSearchBarWarningMessageEvent(message) {
69 type: globalAutoCompleteSearchBarActionTypes.SEARCH_WARNING_EVENT,
70 data: {errorMsg: message}
73 export function getInvalidSearchInputEvent(value) {
74 return getSearchBarWarningMessageEvent(
75 ERROR_INVALID_SEARCH_TERMS + ': ' + value);
79 function fetchView(selectedSuggestion) {
81 type: globalAutoCompleteSearchBarActionTypes.SUGGESTION_CLICKED,
82 data: {selectedSuggestion: selectedSuggestion}
87 export function populateView(
88 searchRequestObject, keyWord, selectedNodeFetchRequest) {
89 if (selectedNodeFetchRequest === undefined) {
90 let postBody = JSON.stringify(searchRequestObject);
91 selectedNodeFetchRequest =
92 () => networkCall.fetchRequest('', POST,
93 POST_HEADER, postBody);
97 dispatch(fetchView(searchRequestObject));
102 export function fetchRequestedValues(fetchRequestCallback, keyWord) {
104 return fetchRequestCallback().then(
105 (responseJson) => responseJson.suggestions
107 (filteredResults)=> {
108 if (filteredResults.length > 0) {
109 dispatch(createSuggestionFoundEvent({suggestions: filteredResults}));
111 dispatch(createSuggestionNotFoundEvent());
116 dispatch(getInvalidQueryEvent(keyWord));
122 export function queryRequestedValues(keyWord, requestedFetchRequest) {
123 if (requestedFetchRequest === undefined) {
124 let postBody = JSON.stringify(getTSUIElasticSearchQueryString(keyWord));
125 requestedFetchRequest =
126 () => networkCall.fetchRequest(GLOBAL_SEARCH_URL, POST, POST_HEADER,
130 dispatch(fetchRequestedValues(requestedFetchRequest, keyWord), keyWord);
134 export function clearSuggestionsTextField() {
137 {type: globalAutoCompleteSearchBarActionTypes.CLEAR_SUGGESTIONS_TEXT_FIELD});
141 export function onSuggestionsChange(event, value) {
143 dispatch(createSuggestionChangedEvent(value));
144 //Only fetch values if the enter key is used.
145 if (event.keyCode === 13) {
146 let postBody = JSON.stringify(getTSUIElasticSearchQueryString(value));
147 dispatch(fetchRequestedValues(
148 () => networkCall.fetchRequest(GLOBAL_SEARCH_URL, POST, POST_HEADER,
154 export function onSuggestionsClearRequested() {
156 dispatch({type: globalAutoCompleteSearchBarActionTypes.CLEAR_SUGGESTIONS});
160 export function setNotificationText(msgText, msgSeverity) {
161 if (msgText.length > 0) {
164 getSetGlobalMessageEvent(msgText, msgSeverity));
168 dispatch(getClearGlobalMessageEvent());