15669: Store and retrieve search value in location 'search' part
[arvados-workbench2.git] / src / store / search-bar / search-bar-actions.ts
index 68efb4e6f2f6b0651a8aa409f65fd5f2b4d72a61..11dc1ef5645976ed1861afa109669649cf670f1c 100644 (file)
@@ -10,12 +10,11 @@ import { RootState } from '~/store/store';
 import { initUserProject, treePickerActions } from '~/store/tree-picker/tree-picker-actions';
 import { ServiceRepository } from '~/services/services';
 import { FilterBuilder } from "~/services/api/filter-builder";
-import { ResourceKind, isResourceUuid, extractUuidKind, RESOURCE_UUID_REGEX, COLLECTION_PDH_REGEX } from '~/models/resource';
+import { ResourceKind, RESOURCE_UUID_REGEX, COLLECTION_PDH_REGEX } from '~/models/resource';
 import { SearchView } from '~/store/search-bar/search-bar-reducer';
 import { navigateTo, navigateToSearchResults } from '~/store/navigation/navigation-action';
 import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions';
 import { PropertyValue, SearchBarAdvanceFormData } from '~/models/search-bar';
-import { debounce } from 'debounce';
 import * as _ from "lodash";
 import { getModifiedKeysValues } from "~/common/objects";
 import { activateSearchBarProject } from "~/store/search-bar/search-bar-tree-actions";
@@ -71,9 +70,9 @@ export const searchData = (searchValue: string) =>
             dispatch<any>(searchGroups(searchValue, 5));
             if (currentView === SearchView.BASIC) {
                 dispatch(searchBarActions.CLOSE_SEARCH_VIEW());
-                dispatch(navigateToSearchResults);
+                dispatch(navigateToSearchResults(searchValue));
             }
-        }
+       }
     };
 
 export const searchAdvanceData = (data: SearchBarAdvanceFormData) =>
@@ -82,7 +81,7 @@ export const searchAdvanceData = (data: SearchBarAdvanceFormData) =>
         dispatch(searchResultsPanelActions.CLEAR());
         dispatch(searchBarActions.SET_CURRENT_VIEW(SearchView.BASIC));
         dispatch(searchBarActions.CLOSE_SEARCH_VIEW());
-        dispatch(navigateToSearchResults);
+        dispatch(navigateToSearchResults(""));
     };
 
 export const setSearchValueFromAdvancedData = (data: SearchBarAdvanceFormData, prevData?: SearchBarAdvanceFormData) =>
@@ -198,17 +197,11 @@ export const submitData = (event: React.FormEvent<HTMLFormElement>) =>
             dispatch(searchBarActions.SET_SEARCH_VALUE(searchValue));
             dispatch(searchBarActions.SET_SEARCH_RESULTS([]));
             dispatch(searchResultsPanelActions.CLEAR());
-            dispatch(navigateToSearchResults);
+            dispatch(navigateToSearchResults(searchValue));
         }
     };
 
 
-const startSearch = () =>
-    (dispatch: Dispatch, getState: () => RootState) => {
-        const searchValue = getState().searchBar.searchValue;
-        dispatch<any>(searchData(searchValue));
-    };
-
 const searchGroups = (searchValue: string, limit: number) =>
     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
         const currentView = getState().searchBar.currentView;
@@ -238,15 +231,15 @@ const buildQueryFromKeyMap = (data: any, keyMap: string[][], mode: 'rebuild' | '
 
         if (data.hasOwnProperty(key)) {
             const pattern = v === false
-                ? `${field.replace(':', '\\:\\s*')}\\s*`
-                : `${field.replace(':', '\\:\\s*')}\\:\\s*"[\\w|\\#|\\-|\\/]*"\\s*`;
+                          ? `${field.replace(':', '\\:\\s*')}\\s*`
+                          : `${field.replace(':', '\\:\\s*')}\\:\\s*"[\\w|\\#|\\-|\\/]*"\\s*`;
             value = value.replace(new RegExp(pattern), '');
         }
 
         if (v) {
             const nv = v === true
-                ? `${field}`
-                : `${field}:${v}`;
+                     ? `${field}`
+                     : `${field}:${v}`;
 
             if (mode === 'rebuild') {
                 value = value + ' ' + nv;
@@ -287,11 +280,9 @@ export const getQueryFromAdvancedData = (data: SearchBarAdvanceFormData, prevDat
         ['to', 'dateTo']
     ];
     _.union(data.properties, prevData ? prevData.properties : [])
-        .forEach(p => keyMap.push([`has:"${p.key}"`, `prop-"${p.key}"`]));
+     .forEach(p => keyMap.push([`has:"${p.key}"`, `prop-"${p.key}"`]));
 
     if (prevData) {
-        const fd = flatData(data);
-        const pfd = flatData(prevData);
         const obj = getModifiedKeysValues(flatData(data), flatData(prevData));
         value = buildQueryFromKeyMap({
             searchValue: data.searchValue,