From d76d0dbba0c7fdcb29303bbc2d4eca27d1a0984b Mon Sep 17 00:00:00 2001 From: Janicki Artur Date: Mon, 29 Oct 2018 13:03:04 +0100 Subject: [PATCH] add filter by create_at for advance search bar Feature #14276_structured_search_service Arvados-DCO-1.1-Signed-off-by: Janicki Artur --- src/services/api/filter-builder.ts | 16 +++++++++++ src/store/search-bar/search-bar-actions.ts | 27 ++++++++++++------- .../search-results-middleware-service.ts | 2 +- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/services/api/filter-builder.ts b/src/services/api/filter-builder.ts index 06a040e3..e36765ba 100644 --- a/src/services/api/filter-builder.ts +++ b/src/services/api/filter-builder.ts @@ -31,6 +31,22 @@ export class FilterBuilder { return this.addCondition(field, "in", value, "", "", resourcePrefix); } + public addGt(field: string, value?: string, resourcePrefix?: string) { + return this.addCondition(field, ">", value, "", "", resourcePrefix); + } + + public addGte(field: string, value?: string, resourcePrefix?: string) { + return this.addCondition(field, ">=", value, "", "", resourcePrefix); + } + + public addLt(field: string, value?: string, resourcePrefix?: string) { + return this.addCondition(field, "<", value, "", "", resourcePrefix); + } + + public addLte(field: string, value?: string, resourcePrefix?: string) { + return this.addCondition(field, "<=", value, "", "", resourcePrefix); + } + public getFilters() { return this.filters; } diff --git a/src/store/search-bar/search-bar-actions.ts b/src/store/search-bar/search-bar-actions.ts index 653a8f53..d6203d2f 100644 --- a/src/store/search-bar/search-bar-actions.ts +++ b/src/store/search-bar/search-bar-actions.ts @@ -55,7 +55,7 @@ export const searchData = (searchValue: string) => const currentView = getState().searchBar.currentView; dispatch(searchBarActions.SET_SEARCH_VALUE(searchValue)); dispatch(searchBarActions.SET_SEARCH_RESULTS([])); - dispatch(searchGroups(searchValue)); + dispatch(searchGroups(searchValue, 5, {})); if (currentView === SearchView.BASIC) { dispatch(searchBarActions.CLOSE_SEARCH_VIEW()); dispatch(navigateToSearchResults); @@ -67,7 +67,7 @@ export const searchAdvanceData = (data: SearchBarAdvanceFormData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { const searchValue = getState().searchBar.searchValue; dispatch(saveQuery(data)); - dispatch(searchGroups(searchValue, 100, data.type)); + dispatch(searchGroups(searchValue, 100, data)); dispatch(searchBarActions.SET_CURRENT_VIEW(SearchView.BASIC)); dispatch(searchBarActions.CLOSE_SEARCH_VIEW()); dispatch(navigateToSearchResults); @@ -122,7 +122,7 @@ export const closeSearchView = () => } }; -export const closeAdvanceView = () => +export const closeAdvanceView = () => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { dispatch(searchBarActions.SET_SEARCH_VALUE('')); dispatch(searchBarActions.SET_CURRENT_VIEW(SearchView.BASIC)); @@ -134,7 +134,7 @@ export const navigateToItem = (uuid: string) => dispatch(navigateTo(uuid)); }; -export const changeData = (searchValue: string) => +export const changeData = (searchValue: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { dispatch(searchBarActions.SET_SEARCH_VALUE(searchValue)); const currentView = getState().searchBar.currentView; @@ -166,24 +166,24 @@ const searchDataOnEnter = (searchValue: string) => dispatch(searchBarActions.CLOSE_SEARCH_VIEW()); dispatch(searchBarActions.SET_SEARCH_VALUE(searchValue)); dispatch(searchBarActions.SET_SEARCH_RESULTS([])); - dispatch(searchGroups(searchValue, 100)); + dispatch(searchGroups(searchValue, 100, {})); dispatch(navigateToSearchResults); }; const debounceStartSearch = debounce((dispatch: Dispatch) => dispatch(startSearch()), DEFAULT_SEARCH_DEBOUNCE); -const startSearch = () => +const startSearch = () => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { const searchValue = getState().searchBar.searchValue; 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, @@ -193,12 +193,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}): 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('created_at', buildDateFilter(dateTo)) + .addGte('created_at', buildDateFilter(dateFrom)) .addEqual('groupClass', GroupClass.PROJECT, GroupContentsResourcePrefix.PROJECT) .getFilters(); }; @@ -207,6 +210,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, getState: () => RootState, services: ServiceRepository) => { dispatch(initUserProject(SEARCH_BAR_ADVANCE_FORM_PICKER_ID)); diff --git a/src/store/search-results-panel/search-results-middleware-service.ts b/src/store/search-results-panel/search-results-middleware-service.ts index 5ccb61bf..0b384442 100644 --- a/src/store/search-results-panel/search-results-middleware-service.ts +++ b/src/store/search-results-panel/search-results-middleware-service.ts @@ -39,7 +39,7 @@ export class SearchResultsMiddlewareService extends DataExplorerMiddlewareServic export const getParams = (dataExplorer: DataExplorer, searchValue: string) => ({ ...dataExplorerToListParams(dataExplorer), - filters: getFilters('name', searchValue), + filters: getFilters('name', searchValue, {}), order: getOrder(dataExplorer) }); -- 2.30.2