X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/4ad549e2cebe285c9a854e466f3e0ddac10b808d..68c2068a9371fd5b158adbeef0ba0021832c8a76:/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 f953a57784..165392c6c2 100644 --- a/src/store/search-bar/search-bar-actions.ts +++ b/src/store/search-bar/search-bar-actions.ts @@ -26,10 +26,12 @@ export const searchBarActions = unionize({ SET_SEARCH_RESULTS: ofType(), SET_SEARCH_VALUE: ofType(), SET_SAVED_QUERIES: ofType(), + SET_RECENT_QUERIES: ofType(), UPDATE_SAVED_QUERY: ofType(), SET_SELECTED_ITEM: ofType(), MOVE_UP: ofType<{}>(), - MOVE_DOWN: ofType<{}>() + MOVE_DOWN: ofType<{}>(), + SELECT_FIRST_ITEM: ofType<{}>() }); export type SearchBarActions = UnionOf; @@ -49,17 +51,17 @@ export const saveRecentQuery = (query: string) => export const loadRecentQueries = () => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - const recentSearchQueries = services.searchService.getRecentQueries(); - return recentSearchQueries || []; + const recentQueries = services.searchService.getRecentQueries(); + dispatch(searchBarActions.SET_RECENT_QUERIES(recentQueries)); + return recentQueries; }; export const searchData = (searchValue: string) => async (dispatch: Dispatch, getState: () => RootState) => { const currentView = getState().searchBar.currentView; dispatch(searchBarActions.SET_SEARCH_VALUE(searchValue)); - // dispatch(searchBarActions.SET_SEARCH_RESULTS([])); if (searchValue.length > 0) { - dispatch(searchGroups(searchValue)); + dispatch(searchGroups(searchValue, 5, {})); if (currentView === SearchView.BASIC) { dispatch(searchBarActions.CLOSE_SEARCH_VIEW()); dispatch(navigateToSearchResults); @@ -75,19 +77,18 @@ export const searchAdvanceData = (data: SearchBarAdvanceFormData) => dispatch(navigateToSearchResults); }; -// Todo: create ids for particular searchQuery const saveQuery = (data: SearchBarAdvanceFormData) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - const savedSearchQueries = services.searchService.getSavedQueries(); - const filteredQuery = savedSearchQueries.find(query => query.searchQuery === data.searchQuery); + const savedQueries = services.searchService.getSavedQueries(); if (data.saveQuery && data.searchQuery) { + const filteredQuery = savedQueries.find(query => query.searchQuery === data.searchQuery); if (filteredQuery) { services.searchService.editSavedQueries(data); - dispatch(searchBarActions.UPDATE_SAVED_QUERY(savedSearchQueries)); + dispatch(searchBarActions.UPDATE_SAVED_QUERY(savedQueries)); dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Query has been successfully updated', hideDuration: 2000, kind: SnackbarKind.SUCCESS })); } else { services.searchService.saveQuery(data); - dispatch(searchBarActions.SET_SAVED_QUERIES(savedSearchQueries)); + dispatch(searchBarActions.SET_SAVED_QUERIES(savedQueries)); dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Query has been successfully saved', hideDuration: 2000, kind: SnackbarKind.SUCCESS })); } } @@ -110,18 +111,17 @@ export const editSavedQuery = (data: SearchBarAdvanceFormData) => export const openSearchView = () => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - dispatch(searchBarActions.OPEN_SEARCH_VIEW()); const savedSearchQueries = services.searchService.getSavedQueries(); dispatch(searchBarActions.SET_SAVED_QUERIES(savedSearchQueries)); + dispatch(loadRecentQueries()); + dispatch(searchBarActions.OPEN_SEARCH_VIEW()); + dispatch(searchBarActions.SELECT_FIRST_ITEM()); }; export const closeSearchView = () => - (dispatch: Dispatch, getState: () => RootState) => { - const isOpen = getState().searchBar.open; - if (isOpen) { - dispatch(searchBarActions.CLOSE_SEARCH_VIEW()); - dispatch(searchBarActions.SET_CURRENT_VIEW(SearchView.BASIC)); - } + (dispatch: Dispatch) => { + dispatch(searchBarActions.SET_SELECTED_ITEM('')); + dispatch(searchBarActions.CLOSE_SEARCH_VIEW()); }; export const closeAdvanceView = () => @@ -132,6 +132,7 @@ export const closeAdvanceView = () => export const navigateToItem = (uuid: string) => (dispatch: Dispatch) => { + dispatch(searchBarActions.SET_SELECTED_ITEM('')); dispatch(searchBarActions.CLOSE_SEARCH_VIEW()); dispatch(navigateTo(uuid)); }; @@ -145,12 +146,13 @@ export const changeData = (searchValue: string) => if (currentView === SearchView.ADVANCED) { } else if (searchValuePresent) { - dispatch(goToView(SearchView.AUTOCOMPLETE)); + dispatch(searchBarActions.SET_CURRENT_VIEW(SearchView.AUTOCOMPLETE)); + dispatch(searchBarActions.SET_SELECTED_ITEM(searchValue)); debounceStartSearch(dispatch); } else { - dispatch(goToView(SearchView.BASIC)); - dispatch(searchBarActions.SET_SEARCH_VALUE(searchValue)); + dispatch(searchBarActions.SET_CURRENT_VIEW(SearchView.BASIC)); dispatch(searchBarActions.SET_SEARCH_RESULTS([])); + dispatch(searchBarActions.SELECT_FIRST_ITEM()); } }; @@ -174,12 +176,12 @@ const startSearch = () => dispatch(searchData(searchValue)); }; -const searchGroups = (searchValue: string, limit = 5, resourceKind?: ResourceKind) => +const searchGroups = (searchValue: string, limit: number, {...props}) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { const currentView = getState().searchBar.currentView; if (searchValue || currentView === SearchView.ADVANCED) { - const filters = getFilters('name', searchValue, resourceKind); + const filters = getFilters('name', searchValue, props); const { items } = await services.groupsService.contents('', { filters, limit, @@ -189,12 +191,15 @@ const searchGroups = (searchValue: string, limit = 5, resourceKind?: ResourceKin } }; -export const getFilters = (filterName: string, searchValue: string, resourceKind?: ResourceKind): string => { +export const getFilters = (filterName: string, searchValue: string, props: any): string => { + const { resourceKind, dateTo, dateFrom } = props; return new FilterBuilder() .addIsA("uuid", buildUuidFilter(resourceKind)) .addILike(filterName, searchValue, GroupContentsResourcePrefix.COLLECTION) .addILike(filterName, searchValue, GroupContentsResourcePrefix.PROCESS) .addILike(filterName, searchValue, GroupContentsResourcePrefix.PROJECT) + .addLte('modified_at', buildDateFilter(dateTo)) + .addGte('modified_at', buildDateFilter(dateFrom)) .addEqual('groupClass', GroupClass.PROJECT, GroupContentsResourcePrefix.PROJECT) .getFilters(); }; @@ -203,6 +208,10 @@ const buildUuidFilter = (type?: ResourceKind): ResourceKind[] => { return type ? [type] : [ResourceKind.PROJECT, ResourceKind.COLLECTION, ResourceKind.PROCESS]; }; +const buildDateFilter = (date?: string): string => { + return date ? date : ''; +}; + export const initAdvanceFormProjectsTree = () => (dispatch: Dispatch) => { dispatch(initUserProject(SEARCH_BAR_ADVANCE_FORM_PICKER_ID));