From 2faacbe1f132f9349420e52e829d884044550fa4 Mon Sep 17 00:00:00 2001 From: Pawel Kowalczyk Date: Tue, 16 Oct 2018 15:08:54 +0200 Subject: [PATCH] autocomplete fixed Feature #14277 Arvados-DCO-1.1-Signed-off-by: Pawel Kowalczyk --- src/store/search-bar/search-bar-actions.ts | 26 ++++++++++++++++--- .../search-bar/search-bar-view.tsx | 3 ++- .../search-bar/search-bar.tsx | 4 ++- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/store/search-bar/search-bar-actions.ts b/src/store/search-bar/search-bar-actions.ts index e73db641..2541e7a3 100644 --- a/src/store/search-bar/search-bar-actions.ts +++ b/src/store/search-bar/search-bar-actions.ts @@ -47,21 +47,21 @@ export const loadRecentQueries = () => return recentSearchQueries || []; }; - // Todo: create ids for particular searchQuery +// Todo: create ids for particular searchQuery export const saveQuery = (data: SearchBarAdvanceFormData) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { const savedSearchQueries = services.searchService.getSavedQueries(); const filteredQuery = savedSearchQueries.find(query => query.searchQuery === data.searchQuery); if (data.saveQuery && data.searchQuery) { if (filteredQuery) { - services.searchService.editSavedQueries(data); + services.searchService.editSavedQueries(data); dispatch(searchBarActions.UPDATE_SAVED_QUERY(savedSearchQueries)); dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Query has been sucessfully updated', hideDuration: 2000, kind: SnackbarKind.SUCCESS })); } else { services.searchService.saveQuery(data); dispatch(searchBarActions.SET_SAVED_QUERIES(savedSearchQueries)); dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Query has been sucessfully saved', hideDuration: 2000, kind: SnackbarKind.SUCCESS })); - } + } } dispatch(searchBarActions.SET_CURRENT_VIEW(SearchView.BASIC)); dispatch(searchBarActions.CLOSE_SEARCH_VIEW()); @@ -121,6 +121,26 @@ export const searchData = (searchValue: string) => }); dispatch(searchBarActions.SET_SEARCH_RESULTS(items)); } + if (currentView !== SearchView.AUTOCOMPLETE) { + dispatch(navigateToSearchResults); + } + + }; + +export const searchDataOnEnter = (searchValue: string) => + async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + dispatch(searchBarActions.CLOSE_SEARCH_VIEW()); + dispatch(searchBarActions.SET_SEARCH_VALUE(searchValue)); + dispatch(searchBarActions.SET_SEARCH_RESULTS([])); + if (searchValue) { + const filters = getFilters('name', searchValue); + const { items } = await services.groupsService.contents('', { + filters, + limit: 5, + recursive: true + }); + dispatch(searchBarActions.SET_SEARCH_RESULTS(items)); + } dispatch(navigateToSearchResults); }; diff --git a/src/views-components/search-bar/search-bar-view.tsx b/src/views-components/search-bar/search-bar-view.tsx index 3d15801a..cfaee6d4 100644 --- a/src/views-components/search-bar/search-bar-view.tsx +++ b/src/views-components/search-bar/search-bar-view.tsx @@ -58,6 +58,7 @@ type SearchBarDataProps = { interface SearchBarActionProps { onSearch: (value: string) => any; + searchDataOnEnter: (value: string) => void; debounce?: number; onSetView: (currentView: string) => void; closeView: () => void; @@ -201,7 +202,7 @@ export const SearchBarView = withStyles(styles)( event.preventDefault(); clearTimeout(this.timeout); this.props.saveRecentQuery(this.state.value); - this.props.onSearch(this.state.value); + this.props.searchDataOnEnter(this.state.value); this.props.loadRecentQueries(); } diff --git a/src/views-components/search-bar/search-bar.tsx b/src/views-components/search-bar/search-bar.tsx index 2d487e0d..7c3d2604 100644 --- a/src/views-components/search-bar/search-bar.tsx +++ b/src/views-components/search-bar/search-bar.tsx @@ -19,6 +19,7 @@ import { } from '~/store/search-bar/search-bar-actions'; import { SearchBarView } from '~/views-components/search-bar/search-bar-view'; import { SearchBarAdvanceFormData } from '~/models/search-bar'; +import { searchDataOnEnter } from '../../store/search-bar/search-bar-actions'; const mapStateToProps = ({ searchBar }: RootState) => { return { @@ -40,7 +41,8 @@ const mapDispatchToProps = (dispatch: Dispatch) => ({ deleteSavedQuery: (id: number) => dispatch(deleteSavedQuery(id)), openSearchView: () => dispatch(openSearchView()), navigateTo: (uuid: string) => dispatch(navigateToItem(uuid)), - editSavedQuery: (data: SearchBarAdvanceFormData) => dispatch(editSavedQuery(data)) + editSavedQuery: (data: SearchBarAdvanceFormData) => dispatch(editSavedQuery(data)), + searchDataOnEnter: (searchValue: string) => dispatch(searchDataOnEnter(searchValue)) }); export const SearchBar = connect(mapStateToProps, mapDispatchToProps)(SearchBarView); \ No newline at end of file -- 2.30.2