[ARVADOS-WORKBENCH2] created: 1.2.0-927-gb5dde55

Git user git at public.curoverse.com
Wed Nov 21 11:05:24 EST 2018


        at  b5dde550c7dd67f0b90841d6b92930e56c625dcd (commit)


commit b5dde550c7dd67f0b90841d6b92930e56c625dcd
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date:   Wed Nov 21 16:19:03 2018 +0100

    Create resource-type-filters
    
    Feature #14258
    
    Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>

diff --git a/src/store/resource-type-filters/resource-type-filters.test.ts b/src/store/resource-type-filters/resource-type-filters.test.ts
new file mode 100644
index 0000000..3e34586
--- /dev/null
+++ b/src/store/resource-type-filters/resource-type-filters.test.ts
@@ -0,0 +1,37 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { getInitialResourceTypeFilters, serializeResourceTypeFilters, ObjectTypeFilter, CollectionTypeFilter } from './resource-type-filters';
+import { ResourceKind } from '~/models/resource';
+import { deselectNode } from '~/models/tree';
+import { pipe } from 'lodash/fp';
+
+describe("serializeResourceTypeFilters", () => {
+    it("should serialize all filters", () => {
+        const filters = getInitialResourceTypeFilters();
+        const serializedFilters = serializeResourceTypeFilters(filters);
+        expect(serializedFilters)
+            .toEqual(`["uuid","is_a",["${ResourceKind.PROJECT}","${ResourceKind.PROCESS}","${ResourceKind.COLLECTION}"]],["collections.properties.type","in",["nil","output","log"]]`);
+    });
+
+    it("should serialize all but collection filters", () => {
+        const filters = deselectNode(ObjectTypeFilter.COLLECTION)(getInitialResourceTypeFilters());
+        const serializedFilters = serializeResourceTypeFilters(filters);
+        expect(serializedFilters)
+            .toEqual(`["uuid","is_a",["${ResourceKind.PROJECT}","${ResourceKind.PROCESS}"]]`);
+    });
+
+    it("should serialize output collections and projects", () => {
+        const filters = pipe(
+            () => getInitialResourceTypeFilters(),
+            deselectNode(ObjectTypeFilter.PROCESS),
+            deselectNode(CollectionTypeFilter.GENERAL_COLLECTION),
+            deselectNode(CollectionTypeFilter.LOG_COLLECTION),
+        )();
+
+        const serializedFilters = serializeResourceTypeFilters(filters);
+        expect(serializedFilters)
+            .toEqual(`["uuid","is_a",["${ResourceKind.PROJECT}","${ResourceKind.COLLECTION}"]],["collections.properties.type","in",["output"]]`);
+    });
+});
diff --git a/src/store/resource-type-filters/resource-type-filters.ts b/src/store/resource-type-filters/resource-type-filters.ts
new file mode 100644
index 0000000..d95ae5a
--- /dev/null
+++ b/src/store/resource-type-filters/resource-type-filters.ts
@@ -0,0 +1,113 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { pipe, values, includes, __ } from 'lodash/fp';
+import { createTree, setNode, TreeNodeStatus, TreeNode } from '~/models/tree';
+import { DataTableFilterItem, DataTableFilters } from '~/components/data-table-filters/data-table-filters-tree';
+import { ResourceKind } from '~/models/resource';
+import { FilterBuilder } from '~/services/api/filter-builder';
+import { getSelectedNodes } from '~/models/tree';
+import { CollectionType } from '~/models/collection';
+import { GroupContentsResourcePrefix } from '~/services/groups-service/groups-service';
+
+export enum ObjectTypeFilter {
+    PROJECT = 'Project',
+    PROCESS = 'Process',
+    COLLECTION = 'Data Collection',
+}
+
+export enum CollectionTypeFilter {
+    GENERAL_COLLECTION = 'General',
+    OUTPUT_COLLECTION = 'Output',
+    LOG_COLLECTION = 'Log',
+}
+
+const initFilter = (name: string, parent = '') =>
+    setNode<DataTableFilterItem>({
+        id: name,
+        value: { name },
+        parent,
+        children: [],
+        active: false,
+        selected: true,
+        expanded: false,
+        status: TreeNodeStatus.LOADED,
+    });
+
+export const getInitialResourceTypeFilters = pipe(
+    (): DataTableFilters => createTree<DataTableFilterItem>(),
+    initFilter(ObjectTypeFilter.PROJECT),
+    initFilter(ObjectTypeFilter.PROCESS),
+    initFilter(ObjectTypeFilter.COLLECTION),
+    initFilter(CollectionTypeFilter.GENERAL_COLLECTION, ObjectTypeFilter.COLLECTION),
+    initFilter(CollectionTypeFilter.OUTPUT_COLLECTION, ObjectTypeFilter.COLLECTION),
+    initFilter(CollectionTypeFilter.LOG_COLLECTION, ObjectTypeFilter.COLLECTION),
+);
+
+
+const createFiltersBuilder = (filters: DataTableFilters) =>
+    ({ fb: new FilterBuilder(), selectedFilters: getSelectedNodes(filters) });
+
+const getMatchingFilters = (values: string[], filters: TreeNode<DataTableFilterItem>[]) =>
+    filters
+        .map(f => f.id)
+        .filter(includes(__, values));
+
+const objectTypeToResourceKind = (type: ObjectTypeFilter) => {
+    switch (type) {
+        case ObjectTypeFilter.PROJECT:
+            return ResourceKind.PROJECT;
+        case ObjectTypeFilter.PROCESS:
+            return ResourceKind.PROCESS;
+        case ObjectTypeFilter.COLLECTION:
+            return ResourceKind.COLLECTION;
+    }
+};
+
+const serializeObjectTypeFilters = ({ fb, selectedFilters }: ReturnType<typeof createFiltersBuilder>) => {
+    const collectionFilters = getMatchingFilters(values(CollectionTypeFilter), selectedFilters);
+    const typeFilters = pipe(
+        () => new Set(getMatchingFilters(values(ObjectTypeFilter), selectedFilters)),
+        set => collectionFilters.length > 0
+            ? set.add(ObjectTypeFilter.COLLECTION)
+            : set,
+        set => Array.from(set)
+    )();
+
+    return {
+        fb: typeFilters.length > 0
+            ? fb.addIsA('uuid', typeFilters.map(objectTypeToResourceKind))
+            : fb,
+        selectedFilters,
+    };
+};
+
+const collectionTypeToPropertyValue = (type: CollectionTypeFilter) => {
+    switch (type) {
+        case CollectionTypeFilter.GENERAL_COLLECTION:
+            return CollectionType.GENERAL;
+        case CollectionTypeFilter.OUTPUT_COLLECTION:
+            return CollectionType.OUTPUT;
+        case CollectionTypeFilter.LOG_COLLECTION:
+            return CollectionType.LOG;
+    }
+};
+
+const serializeCollectionTypeFilters = ({ fb, selectedFilters }: ReturnType<typeof createFiltersBuilder>) => pipe(
+    () => getMatchingFilters(values(CollectionTypeFilter), selectedFilters),
+    filters => filters.map(collectionTypeToPropertyValue),
+    mappedFilters => ({
+        fb: mappedFilters.length > 0
+            ? fb.addIn('type', mappedFilters, `${GroupContentsResourcePrefix.COLLECTION}.properties`)
+            : fb,
+        selectedFilters
+    })
+)();
+
+export const serializeResourceTypeFilters = pipe(
+    createFiltersBuilder,
+    serializeObjectTypeFilters,
+    serializeCollectionTypeFilters,
+    ({ fb }) => fb.getFilters(),
+);

commit f7fe08bec2ee46d97356159e2bb54e076ccd0b3c
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date:   Wed Nov 21 15:48:53 2018 +0100

    Add collection type enum
    
    Feature #14258
    
    Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>

diff --git a/src/models/collection.ts b/src/models/collection.ts
index 53c6230..2b16ea2 100644
--- a/src/models/collection.ts
+++ b/src/models/collection.ts
@@ -22,3 +22,9 @@ export interface CollectionResource extends TrashableResource {
 export const getCollectionUrl = (uuid: string) => {
     return `/collections/${uuid}`;
 };
+
+export enum CollectionType {
+    GENERAL = 'nil',
+    OUTPUT = 'output',
+    LOG = 'log',
+}

commit a8595bc84a3272c75e6d3163db1d6031cd166bd7
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date:   Wed Nov 21 15:48:23 2018 +0100

    Add function for listing tree's selected nodes
    
    Feature #14258
    
    Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>

diff --git a/src/models/tree.ts b/src/models/tree.ts
index 1bc15bc..8b71692 100644
--- a/src/models/tree.ts
+++ b/src/models/tree.ts
@@ -178,6 +178,10 @@ export const deselectNodes = (id: string | string[]) => <T>(tree: Tree<T>) => {
     return ids.reduce((tree, id) => deselectNode(id)(tree), tree);
 };
 
+export const getSelectedNodes = <T>(tree: Tree<T>) =>
+    getNodeDescendants('')(tree)
+        .filter(node => node.selected);
+
 export const initTreeNode = <T>(data: Pick<TreeNode<T>, 'id' | 'value'> & { parent?: string }): TreeNode<T> => ({
     children: [],
     active: false,

commit fe7cca11d3d09d6aff1acf5284112a4069c49c1a
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date:   Wed Nov 21 15:47:51 2018 +0100

    Disable resourcePrefix snakecase in FilterBuilder - it was making it impossible to apply complex prefixes like `collections.properties`
    
    Feature #14258
    
    Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>

diff --git a/src/services/api/filter-builder.test.ts b/src/services/api/filter-builder.test.ts
index 5f646de..e365b33 100644
--- a/src/services/api/filter-builder.test.ts
+++ b/src/services/api/filter-builder.test.ts
@@ -73,6 +73,6 @@ describe("FilterBuilder", () => {
         expect(new FilterBuilder()
             .addIn("etag", ["etagValue1", "etagValue2"], "myPrefix")
             .getFilters())
-            .toEqual(`["my_prefix.etag","in",["etagValue1","etagValue2"]]`);
+            .toEqual(`["myPrefix.etag","in",["etagValue1","etagValue2"]]`);
     });
 });
diff --git a/src/services/api/filter-builder.ts b/src/services/api/filter-builder.ts
index e36765b..f83f574 100644
--- a/src/services/api/filter-builder.ts
+++ b/src/services/api/filter-builder.ts
@@ -62,7 +62,7 @@ export class FilterBuilder {
             }
 
             const resPrefix = resourcePrefix
-                ? _.snakeCase(resourcePrefix) + "."
+                ? resourcePrefix + "."
                 : "";
 
             this.filters += `${this.filters ? "," : ""}["${resPrefix}${_.snakeCase(field)}","${cond}",${value}]`;

commit b693bdde231b0ca4171015e578d9760c6001749b
Merge: 486b76b 296ddbd
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date:   Wed Nov 21 11:10:33 2018 +0100

    Merge branch '14258-update-data-explorer-to-use-table-filters-tree' into 14258-update-views-to-use-new-filters-tree
    
    refs #14258
    14258
    
    Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>


-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list