X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/d38fcf4f5b9d8a1889b9bdf79ee77a2022ed4b52..2209cb79b4d5e48187590433246b9026216cfb6a:/src/store/search-bar/search-bar-actions.ts diff --git a/src/store/search-bar/search-bar-actions.ts b/src/store/search-bar/search-bar-actions.ts index 3aceb65887..2b8ca83e69 100644 --- a/src/store/search-bar/search-bar-actions.ts +++ b/src/store/search-bar/search-bar-actions.ts @@ -15,21 +15,33 @@ export const searchBarActions = unionize({ SET_CURRENT_VIEW: ofType(), OPEN_SEARCH_VIEW: ofType<{}>(), CLOSE_SEARCH_VIEW: ofType<{}>(), - SET_SEARCH_RESULTS: ofType() + SET_SEARCH_RESULTS: ofType(), + SET_SEARCH_VALUE: ofType() }); export type SearchBarActions = UnionOf; export const goToView = (currentView: string) => searchBarActions.SET_CURRENT_VIEW(currentView); -export const searchData = (searchValue: string) => +export const saveRecentQuery = (query: string) => + (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + services.searchQueriesService.saveRecentQuery(query); + }; + +export const loadRecentQueries = () => + (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + const recentSearchQueries = services.searchQueriesService.getRecentQueries(); + return recentSearchQueries || []; + }; + +export const searchData = (searchValue: string) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + dispatch(searchBarActions.SET_SEARCH_VALUE(searchValue)); dispatch(searchBarActions.SET_SEARCH_RESULTS([])); if (searchValue) { const filters = getFilters('name', searchValue); - // set user.uuid search only in Projects, the empty value search by whole app const { items } = await services.groupsService.contents('', { - filters, + filters, limit: 5, recursive: true }); @@ -37,7 +49,6 @@ export const searchData = (searchValue: string) => } }; - const getFilters = (filterName: string, searchValue: string): string => { return new FilterBuilder() .addIsA("uuid", [ResourceKind.PROJECT, ResourceKind.COLLECTION, ResourceKind.PROCESS]) @@ -46,4 +57,4 @@ const getFilters = (filterName: string, searchValue: string): string => { .addILike(filterName, searchValue, GroupContentsResourcePrefix.PROJECT) .addEqual('groupClass', GroupClass.PROJECT, GroupContentsResourcePrefix.PROJECT) .getFilters(); -}; \ No newline at end of file +};