autocomplete fixed
authorPawel Kowalczyk <pawel.kowalczyk@contractors.roche.com>
Tue, 16 Oct 2018 13:08:54 +0000 (15:08 +0200)
committerPawel Kowalczyk <pawel.kowalczyk@contractors.roche.com>
Tue, 16 Oct 2018 13:08:54 +0000 (15:08 +0200)
Feature #14277

Arvados-DCO-1.1-Signed-off-by: Pawel Kowalczyk <pawel.kowalczyk@contractors.roche.com>

src/store/search-bar/search-bar-actions.ts
src/views-components/search-bar/search-bar-view.tsx
src/views-components/search-bar/search-bar.tsx

index e73db641fad86968dfc564bdfbc864adf535a5f4..2541e7a3a5e4d46a686ebd71da1661041d7d9b61 100644 (file)
@@ -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<any>, 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);
     };
 
index 3d15801ae944a6441f7917a9386cf3199bb65387..cfaee6d4f32032c2b6968d3e51c4efc1e8ee65c0 100644 (file)
@@ -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();
         }
 
index 2d487e0dda1170288f50d9b5e9e0ec8d230a1e58..7c3d2604a7a54072d1c089d256ae39a7c0895d16 100644 (file)
@@ -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<any>(deleteSavedQuery(id)),
     openSearchView: () => dispatch<any>(openSearchView()),
     navigateTo: (uuid: string) => dispatch<any>(navigateToItem(uuid)),
-    editSavedQuery: (data: SearchBarAdvanceFormData) => dispatch<any>(editSavedQuery(data))
+    editSavedQuery: (data: SearchBarAdvanceFormData) => dispatch<any>(editSavedQuery(data)),
+    searchDataOnEnter: (searchValue: string) => dispatch<any>(searchDataOnEnter(searchValue))
 });
 
 export const SearchBar = connect(mapStateToProps, mapDispatchToProps)(SearchBarView);
\ No newline at end of file