merge checkbox
[arvados-workbench2.git] / src / store / search-bar / search-bar-actions.ts
index 7a13197a0e1f3f3a26c3e81ba606eed55fc5a32a..c8f9768a8478b4eeae112a5147452fd4cf5f5f15 100644 (file)
@@ -16,7 +16,8 @@ export const searchBarActions = unionize({
     OPEN_SEARCH_VIEW: ofType<{}>(),
     CLOSE_SEARCH_VIEW: ofType<{}>(),
     SET_SEARCH_RESULTS: ofType<GroupContentsResource[]>(),
-    SET_SEARCH_VALUE: ofType<string>()
+    SET_SEARCH_VALUE: ofType<string>(),
+    SET_SAVED_QUERIES: ofType<string[]>()
 });
 
 export type SearchBarActions = UnionOf<typeof searchBarActions>;
@@ -37,16 +38,38 @@ export const SEARCH_BAR_ADVANCE_FORM_NAME = 'searchBarAdvanceFormName';
 export const goToView = (currentView: string) => searchBarActions.SET_CURRENT_VIEW(currentView);
 
 export const saveRecentQuery = (query: string) =>
-    (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
-        services.searchQueriesService.saveRecentQuery(query);
-    };
+    (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) =>
+        services.searchService.saveRecentQuery(query);
+
 
 export const loadRecentQueries = () =>
     (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
-        const recentSearchQueries = services.searchQueriesService.getRecentQueries();
+        const recentSearchQueries = services.searchService.getRecentQueries();
         return recentSearchQueries || [];
     };
 
+export const saveQuery = (query: string) =>
+    (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
+        services.searchService.saveQuery(query);
+        dispatch(searchBarActions.SET_SAVED_QUERIES(services.searchService.getSavedQueries()));
+    };
+
+export const deleteSavedQuery = (id: number) =>
+    (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
+        services.searchService.deleteSavedQuery(id);
+        const savedSearchQueries = services.searchService.getSavedQueries();
+        dispatch(searchBarActions.SET_SAVED_QUERIES(savedSearchQueries));
+        return savedSearchQueries || [];
+    };
+
+export const openSearchView = () =>
+    (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
+        dispatch(searchBarActions.OPEN_SEARCH_VIEW());
+        const savedSearchQueries = services.searchService.getSavedQueries();
+        dispatch(searchBarActions.SET_SAVED_QUERIES(savedSearchQueries));
+    };
+
+
 export const searchData = (searchValue: string) =>
     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
         dispatch(searchBarActions.SET_SEARCH_VALUE(searchValue));