Merge branch 'master' into 14565-admin-managing-user
[arvados-workbench2.git] / src / store / search-bar / search-bar-actions.ts
index f5d83579a046723fa72a92645d27d9e7f59037b4..199ec3f95788c9f131e373862e52c07ddb9703bd 100644 (file)
@@ -10,12 +10,12 @@ import { RootState } from '~/store/store';
 import { initUserProject, treePickerActions } from '~/store/tree-picker/tree-picker-actions';
 import { ServiceRepository } from '~/services/services';
 import { FilterBuilder } from "~/services/api/filter-builder";
-import { getResourceKind, ResourceKind } from '~/models/resource';
+import { ResourceKind } from '~/models/resource';
 import { GroupClass } from '~/models/group';
 import { SearchView } from '~/store/search-bar/search-bar-reducer';
 import { navigateTo, navigateToSearchResults } from '~/store/navigation/navigation-action';
 import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions';
-import { getClusterObjectType, PropertyValues, SearchBarAdvanceFormData } from '~/models/search-bar';
+import { ClusterObjectType, PropertyValue, SearchBarAdvanceFormData } from '~/models/search-bar';
 import { debounce } from 'debounce';
 import * as _ from "lodash";
 import { getModifiedKeysValues } from "~/common/objects";
@@ -307,7 +307,7 @@ export const parseSearchQuery: (query: string) => ParseSearchQuery = (searchValu
         'has:'
     ];
 
-    const hasKeywords = (search: string) => keywords.reduce((acc, keyword) => acc + search.indexOf(keyword) >= 0 ? 1 : 0, 0);
+    const hasKeywords = (search: string) => keywords.reduce((acc, keyword) => acc + (search.includes(keyword) ? 1 : 0), 0);
     let keywordsCnt = 0;
 
     const properties = {};
@@ -353,7 +353,7 @@ export const parseSearchQuery: (query: string) => ParseSearchQuery = (searchValu
 
 const getFirstProp = (sq: ParseSearchQuery, name: string) => sq.properties[name] && sq.properties[name][0];
 const getPropValue = (sq: ParseSearchQuery, name: string, value: string) => sq.properties[name] && sq.properties[name].find((v: string) => v === value);
-const getProperties = (sq: ParseSearchQuery) => {
+const getProperties = (sq: ParseSearchQuery): PropertyValue[] => {
     if (sq.properties.has) {
         return sq.properties.has.map((value: string) => {
             const v = value.split(':');
@@ -371,8 +371,8 @@ export const getAdvancedDataFromQuery = (query: string): SearchBarAdvanceFormDat
 
     return {
         searchValue: sq.values.join(' '),
-        type: getResourceKind(getFirstProp(sq, 'type')),
-        cluster: getClusterObjectType(getFirstProp(sq, 'cluster')),
+        type: getFirstProp(sq, 'type') as ResourceKind,
+        cluster: getFirstProp(sq, 'cluster') as ClusterObjectType,
         projectUuid: getFirstProp(sq, 'project'),
         inTrash: getPropValue(sq, 'is', 'trashed') !== undefined,
         dateFrom: getFirstProp(sq, 'from'),
@@ -387,7 +387,7 @@ export const getFilters = (filterName: string, searchValue: string): string => {
     const filter = new FilterBuilder();
     const sq = parseSearchQuery(searchValue);
 
-    const resourceKind = getResourceKind(getFirstProp(sq, 'type'));
+    const resourceKind = getFirstProp(sq, 'type') as ResourceKind;
 
     let prefix = '';
     switch (resourceKind) {
@@ -439,9 +439,13 @@ export const getFilters = (filterName: string, searchValue: string): string => {
         if (dateTo) {
             filter.addLte('modified_at', buildDateFilter(dateTo));
         }
-    }
 
-    // TODO: has props
+        const props = getProperties(sq);
+        props.forEach(p => {
+            // filter.addILike(`properties.${p.key}`, p.value);
+            filter.addExists(p.key);
+        });
+    }
 
     return filter
         .addEqual('groupClass', GroupClass.PROJECT, GroupContentsResourcePrefix.PROJECT)
@@ -462,12 +466,12 @@ export const initAdvanceFormProjectsTree = () =>
         dispatch<any>(initUserProject(SEARCH_BAR_ADVANCE_FORM_PICKER_ID));
     };
 
-export const changeAdvanceFormProperty = (property: string, value: PropertyValues[] | string = '') =>
+export const changeAdvanceFormProperty = (property: string, value: PropertyValue[] | string = '') =>
     (dispatch: Dispatch) => {
         dispatch(change(SEARCH_BAR_ADVANCE_FORM_NAME, property, value));
     };
 
-export const updateAdvanceFormProperties = (propertyValues: PropertyValues) =>
+export const updateAdvanceFormProperties = (propertyValues: PropertyValue) =>
     (dispatch: Dispatch) => {
         dispatch(arrayPush(SEARCH_BAR_ADVANCE_FORM_NAME, 'properties', propertyValues));
     };