merge master
[arvados-workbench2.git] / src / store / search-bar / search-bar-actions.ts
index 394920a5d7c776aaec41841c0d13161fb5701446..771cbc891da17de2ba7b995721ac388c2c63a483 100644 (file)
@@ -13,6 +13,7 @@ import { GroupClass } from '~/models/group';
 import { SearchView } from '~/store/search-bar/search-bar-reducer';
 import { navigateToSearchResults, navigateTo } from '~/store/navigation/navigation-action';
 import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions';
+import { SearchBarAdvanceFormData } from '~/models/search-bar';
 
 export const searchBarActions = unionize({
     SET_CURRENT_VIEW: ofType<string>(),
@@ -25,17 +26,6 @@ export const searchBarActions = unionize({
 
 export type SearchBarActions = UnionOf<typeof searchBarActions>;
 
-export interface SearchBarAdvanceFormData {
-    type?: GroupContentsResource;
-    cluster?: string;
-    project?: string;
-    inTrash: boolean;
-    dataFrom: string;
-    dataTo: string;
-    saveQuery: boolean;
-    searchQuery: string;
-}
-
 export const SEARCH_BAR_ADVANCE_FORM_NAME = 'searchBarAdvanceFormName';
 
 export const goToView = (currentView: string) => searchBarActions.SET_CURRENT_VIEW(currentView);
@@ -75,12 +65,16 @@ export const openSearchView = () =>
         dispatch(searchBarActions.SET_SAVED_QUERIES(savedSearchQueries));
     };
 
-export const closeSearchView = () =>
+export const closeSearchView = () => 
     (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
-        dispatch(searchBarActions.CLOSE_SEARCH_VIEW());
-        dispatch(searchBarActions.SET_CURRENT_VIEW(SearchView.BASIC));
+        const isOpen = getState().searchBar.open;
+        if(isOpen) {
+            dispatch(searchBarActions.CLOSE_SEARCH_VIEW());
+            dispatch(searchBarActions.SET_CURRENT_VIEW(SearchView.BASIC));
+        }
     };
 
+
 export const navigateToItem = (uuid: string) =>
     (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
         dispatch(searchBarActions.CLOSE_SEARCH_VIEW());