Fix filtering by is_trashed field
authorDaniel Kos <daniel.kos@contractors.roche.com>
Tue, 11 Sep 2018 19:27:57 +0000 (21:27 +0200)
committerDaniel Kos <daniel.kos@contractors.roche.com>
Tue, 11 Sep 2018 19:27:57 +0000 (21:27 +0200)
Feature #14141

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

src/services/api/filter-builder.test.ts
src/services/api/filter-builder.ts
src/store/trash-panel/trash-panel-middleware-service.ts
src/views/trash-panel/trash-panel.tsx

index de2ba4cba65bbd008f581d20c4db5c16b1cbdc05..5149891d03cd9026cca212155d5c4c7dc89d008e 100644 (file)
@@ -12,12 +12,18 @@ describe("FilterBuilder", () => {
         filters = new FilterBuilder();
     });
 
-    it("should add 'equal' rule", () => {
+    it("should add 'equal' rule (string)", () => {
         expect(
             filters.addEqual("etag", "etagValue").getFilters()
         ).toEqual(`["etag","=","etagValue"]`);
     });
 
+    it("should add 'equal' rule (boolean)", () => {
+        expect(
+            filters.addEqual("is_trashed", true).getFilters()
+        ).toEqual(`["etag","=",true]`);
+    });
+
     it("should add 'like' rule", () => {
         expect(
             filters.addLike("etag", "etagValue").getFilters()
index b5558dbb16a291f8ecb81fdbd642f742bb99b9d3..06a040e3cc373f8206c83783c90e8cdf010d095a 100644 (file)
@@ -11,7 +11,7 @@ export function joinFilters(filters0?: string, filters1?: string) {
 export class FilterBuilder {
     constructor(private filters = "") { }
 
-    public addEqual(field: string, value?: string, resourcePrefix?: string) {
+    public addEqual(field: string, value?: string | boolean, resourcePrefix?: string) {
         return this.addCondition(field, "=", value, "", "", resourcePrefix );
     }
 
@@ -35,11 +35,15 @@ export class FilterBuilder {
         return this.filters;
     }
 
-    private addCondition(field: string, cond: string, value?: string | string[], prefix: string = "", postfix: string = "", resourcePrefix?: string) {
+    private addCondition(field: string, cond: string, value?: string | string[] | boolean, prefix: string = "", postfix: string = "", resourcePrefix?: string) {
         if (value) {
-            value = typeof value === "string"
-                ? `"${prefix}${value}${postfix}"`
-                : `["${value.join(`","`)}"]`;
+            if (typeof value === "string") {
+                value = `"${prefix}${value}${postfix}"`;
+            } else if (Array.isArray(value)) {
+                value = `["${value.join(`","`)}"]`;
+            } else {
+                value = value ? "true" : "false";
+            }
 
             const resPrefix = resourcePrefix
                 ? _.snakeCase(resourcePrefix) + "."
index 19ed3be13194982a97527417adb3b4eff8438389..6e8fa542478766368968e0912fc636da5f4c9b6b 100644 (file)
@@ -19,7 +19,6 @@ import { TrashPanelColumnNames, TrashPanelFilter } from "~/views/trash-panel/tra
 import { ProjectResource } from "~/models/project";
 import { ProjectPanelColumnNames } from "~/views/project-panel/project-panel";
 import { updateFavorites } from "~/store/favorites/favorites-actions";
-import { TrashableResource } from "~/models/resource";
 import { snackbarActions } from "~/store/snackbar/snackbar-actions";
 import { updateResources } from "~/store/resources/resources-actions";
 
@@ -57,14 +56,13 @@ export class TrashPanelMiddlewareService extends DataExplorerMiddlewareService {
                         .addIsA("uuid", typeFilters.map(f => f.type))
                         .addILike("name", dataExplorer.searchValue, GroupContentsResourcePrefix.COLLECTION)
                         .addILike("name", dataExplorer.searchValue, GroupContentsResourcePrefix.PROJECT)
+                        .addEqual("is_trashed", true)
                         .getFilters(),
                     recursive: true,
                     includeTrash: true
                 });
 
-            const items = listResults.items
-                .filter(it => (it as TrashableResource).isTrashed)
-                .map(it => it.uuid);
+            const items = listResults.items.map(it => it.uuid);
 
             api.dispatch(trashPanelActions.SET_ITEMS({
                 ...listResultsToDataExplorerItemsMeta(listResults),
index 4a1e197d540dc059a8cfe15c6d642c218a308a0d..db7d8f688096e34cb80ca4a1e7bc796b1e0d11bb 100644 (file)
@@ -99,11 +99,6 @@ export const trashPanelColumns: DataColumns<string, TrashPanelFilter> = [
                 selected: true,
                 type: ResourceKind.COLLECTION
             },
-            {
-                name: resourceLabel(ResourceKind.PROCESS),
-                selected: true,
-                type: ResourceKind.PROCESS
-            },
             {
                 name: resourceLabel(ResourceKind.PROJECT),
                 selected: true,