Add exist filter
authorDaniel Kos <daniel.kos@contractors.roche.com>
Fri, 30 Nov 2018 00:02:01 +0000 (01:02 +0100)
committerDaniel Kos <daniel.kos@contractors.roche.com>
Fri, 30 Nov 2018 00:02:01 +0000 (01:02 +0100)
Feature #14280

Arvados-DCO-1.1-Signed-off-by: Daniel Kos <daniel.kos@contractors.roche.com>

src/services/api/filter-builder.ts
src/store/search-bar/search-bar-actions.ts

index 1ebf488636115c7dfb2cd9bcbf420d79ee82fa1b..08746c81b9ee1d91736b4e9e09eb79b820bd916f 100644 (file)
@@ -51,6 +51,10 @@ export class FilterBuilder {
         return this.addCondition(field, "<=", value, "", "", resourcePrefix);
     }
 
+    public addExists(value?: string, resourcePrefix?: string) {
+        return this.addCondition("properties", "exists", value, "", "", resourcePrefix);
+    }
+
     public getFilters() {
         return this.filters;
     }
@@ -69,7 +73,9 @@ export class FilterBuilder {
                 ? resourcePrefix + "."
                 : "";
 
-            this.filters += `${this.filters ? "," : ""}["${resPrefix}${_.snakeCase(field)}","${cond}",${value}]`;
+            const fld = field.indexOf('properties.') < 0 ? _.snakeCase(field) : field;
+
+            this.filters += `${this.filters ? "," : ""}["${resPrefix}${fld}","${cond}",${value}]`;
         }
         return this;
     }
index f5d83579a046723fa72a92645d27d9e7f59037b4..3d1b4ee910b6643cadd5734d1a7a38ca78f0ed2d 100644 (file)
@@ -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): PropertyValues[] => {
     if (sq.properties.has) {
         return sq.properties.has.map((value: string) => {
             const v = value.split(':');
@@ -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)