15669: Store and retrieve search value in location 'search' part
[arvados-workbench2.git] / src / store / search-results-panel / search-results-panel-actions.ts
index d41191c002571753ed082b466e931578acae452b..20a14b2e7abef94b8f3bacece36422f2bf4e6078 100644 (file)
@@ -7,6 +7,7 @@ import { RootState } from '~/store/store';
 import { ServiceRepository } from '~/services/services';
 import { bindDataExplorerActions } from '~/store/data-explorer/data-explorer-action';
 import { setBreadcrumbs } from '~/store/breadcrumbs/breadcrumbs-actions';
+import { searchBarActions } from '~/store/search-bar/search-bar-actions';
 
 export const SEARCH_RESULTS_PANEL_ID = "searchResultsPanel";
 export const searchResultsPanelActions = bindDataExplorerActions(SEARCH_RESULTS_PANEL_ID);
@@ -14,5 +15,15 @@ export const searchResultsPanelActions = bindDataExplorerActions(SEARCH_RESULTS_
 export const loadSearchResultsPanel = () =>
     (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
         dispatch(setBreadcrumbs([{ label: 'Search results' }]));
+        const loc = getState().router.location;
+        if (loc !== null) {
+            const search = new URLSearchParams(loc.search);
+            const q = search.get('q');
+            if (q !== null) {
+                dispatch(searchBarActions.SET_SEARCH_VALUE(q));
+            }
+        }
+        dispatch(searchBarActions.SET_SEARCH_RESULTS([]));
+        dispatch(searchResultsPanelActions.CLEAR());
         dispatch(searchResultsPanelActions.REQUEST_ITEMS(true));
-    };
\ No newline at end of file
+    };