2 * ============LICENSE_START=======================================================
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
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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 import {getTSUIElasticSearchQueryString} from 'app/networking/NetworkUtil.js';
24 import networkCall from 'app/networking/NetworkCalls.js';
29 } from 'app/networking/NetworkConstants.js';
32 globalAutoCompleteSearchBarActionTypes,
33 ERROR_INVALID_SEARCH_TERMS,
35 } from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarConstants.js';
37 getSetGlobalMessageEvent,
38 getClearGlobalMessageEvent
39 } from 'app/globalInlineMessageBar/GlobalInlineMessageBarActions.js';
42 function createSuggestionFoundEvent({suggestions}) {
44 type: globalAutoCompleteSearchBarActionTypes.SUGGESTION_FOUND,
49 function createSuggestionNotFoundEvent() {
51 type: globalAutoCompleteSearchBarActionTypes.SUGGESTION_NOT_FOUND
55 function createSuggestionChangedEvent(value) {
57 type: globalAutoCompleteSearchBarActionTypes.SUGGESTION_CHANGED,
62 function getInvalidQueryEvent(value) {
64 type: globalAutoCompleteSearchBarActionTypes.NETWORK_ERROR,
65 data: {value: value, errorMsg: ERROR_RETRIEVING_DATA}
69 function getSearchBarWarningMessageEvent(message) {
71 type: globalAutoCompleteSearchBarActionTypes.SEARCH_WARNING_EVENT,
72 data: {errorMsg: message}
75 export function getInvalidSearchInputEvent(value) {
76 return getSearchBarWarningMessageEvent(
77 ERROR_INVALID_SEARCH_TERMS + ': ' + value);
81 function fetchView(selectedSuggestion) {
83 type: globalAutoCompleteSearchBarActionTypes.SUGGESTION_CLICKED,
84 data: {selectedSuggestion: selectedSuggestion}
89 export function populateView(
90 searchRequestObject, keyWord, selectedNodeFetchRequest) {
91 if (selectedNodeFetchRequest === undefined) {
92 let postBody = JSON.stringify(searchRequestObject);
93 selectedNodeFetchRequest =
94 () => networkCall.fetchRequest('', POST,
95 POST_HEADER, postBody);
99 dispatch(fetchView(searchRequestObject));
104 export function fetchRequestedValues(fetchRequestCallback, keyWord) {
106 return fetchRequestCallback().then(
107 (responseJson) => responseJson.suggestions
109 (filteredResults)=> {
110 if (filteredResults.length > 0) {
111 dispatch(createSuggestionFoundEvent({suggestions: filteredResults}));
113 dispatch(createSuggestionNotFoundEvent());
118 dispatch(getInvalidQueryEvent(keyWord));
124 export function queryRequestedValues(keyWord, requestedFetchRequest) {
125 if (requestedFetchRequest === undefined) {
126 let postBody = JSON.stringify(getTSUIElasticSearchQueryString(keyWord));
127 requestedFetchRequest =
128 () => networkCall.fetchRequest(GLOBAL_SEARCH_URL, POST, POST_HEADER,
132 dispatch(fetchRequestedValues(requestedFetchRequest, keyWord), keyWord);
136 export function clearSuggestionsTextField() {
139 {type: globalAutoCompleteSearchBarActionTypes.CLEAR_SUGGESTIONS_TEXT_FIELD});
143 export function onSuggestionsChange(event, value) {
145 dispatch(createSuggestionChangedEvent(value));
146 //Only fetch values if the enter key is used.
147 if (event.keyCode === 13) {
148 let postBody = JSON.stringify(getTSUIElasticSearchQueryString(value));
149 dispatch(fetchRequestedValues(
150 () => networkCall.fetchRequest(GLOBAL_SEARCH_URL, POST, POST_HEADER,
156 export function onSuggestionsClearRequested() {
158 dispatch({type: globalAutoCompleteSearchBarActionTypes.CLEAR_SUGGESTIONS});
162 export function setNotificationText(msgText, msgSeverity) {
163 if (msgText.length > 0) {
166 getSetGlobalMessageEvent(msgText, msgSeverity));
170 dispatch(getClearGlobalMessageEvent());