add filter by create_at for advance search bar
authorJanicki Artur <artur.janicki@contractors.roche.com>
Mon, 29 Oct 2018 12:03:04 +0000 (13:03 +0100)
committerJanicki Artur <artur.janicki@contractors.roche.com>
Mon, 29 Oct 2018 12:03:04 +0000 (13:03 +0100)
Feature #14276_structured_search_service

Arvados-DCO-1.1-Signed-off-by: Janicki Artur <artur.janicki@contractors.roche.com>

src/services/api/filter-builder.ts
src/store/search-bar/search-bar-actions.ts
src/store/search-results-panel/search-results-middleware-service.ts

index 06a040e3cc373f8206c83783c90e8cdf010d095a..e36765ba5b5a6a145f7bae29529238438fb13420 100644 (file)
@@ -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;
     }
index 653a8f536d4a548ca18dabf33a2b1c6a15af44d8..d6203d2f46d0c269f6cf56bb06b5e0c01c8a562b 100644 (file)
@@ -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<any>(searchGroups(searchValue));
+        dispatch<any>(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<any>(saveQuery(data));
-        dispatch<any>(searchGroups(searchValue, 100, data.type));
+        dispatch<any>(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<any>, 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<any>(searchGroups(searchValue, 100));
+        dispatch<any>(searchGroups(searchValue, 100, {}));
         dispatch(navigateToSearchResults);
     };
 
 const debounceStartSearch = debounce((dispatch: Dispatch) => dispatch<any>(startSearch()), DEFAULT_SEARCH_DEBOUNCE);
 
-const startSearch = () => 
+const startSearch = () =>
     (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
         const searchValue = getState().searchBar.searchValue;
         dispatch<any>(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<any>(initUserProject(SEARCH_BAR_ADVANCE_FORM_PICKER_ID));
index 5ccb61bf6961c11ec95c3a8f11a706a9c6258490..0b38444205e496ed0d6d440e00fe16b214232fcc 100644 (file)
@@ -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)
 });