From: Michal Klobukowski Date: Thu, 22 Nov 2018 14:29:38 +0000 (+0100) Subject: Add buildCollectiomTypeFilters function X-Git-Tag: 1.3.0~12^2^2~1^2~3^2~16 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/890c0889fffd420a8ccf59c652d83e4fd1a06e6b Add buildCollectiomTypeFilters function Feature #14258 Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski --- diff --git a/src/store/resource-type-filters/resource-type-filters.ts b/src/store/resource-type-filters/resource-type-filters.ts index d95ae5a4..295818a2 100644 --- a/src/store/resource-type-filters/resource-type-filters.ts +++ b/src/store/resource-type-filters/resource-type-filters.ts @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: AGPL-3.0 -import { pipe, values, includes, __ } from 'lodash/fp'; +import { difference, 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'; @@ -98,13 +98,28 @@ const serializeCollectionTypeFilters = ({ fb, selectedFilters }: ReturnType getMatchingFilters(values(CollectionTypeFilter), selectedFilters), filters => filters.map(collectionTypeToPropertyValue), mappedFilters => ({ - fb: mappedFilters.length > 0 - ? fb.addIn('type', mappedFilters, `${GroupContentsResourcePrefix.COLLECTION}.properties`) - : fb, + fb: buildCollectiomTypeFilters({ fb, filters: mappedFilters }), selectedFilters }) )(); +const COLLECTION_TYPES = values(CollectionType); + +const NON_GENERAL_COLLECTION_TYPES = difference(COLLECTION_TYPES, [CollectionType.GENERAL]); + +const COLLECTION_PROPERTIES_PREFIX = `${GroupContentsResourcePrefix.COLLECTION}.properties`; + +const buildCollectiomTypeFilters = ({ fb, filters}: { fb: FilterBuilder, filters: CollectionType[] }) => { + switch(true){ + case filters.length === 0 || filters.length === COLLECTION_TYPES.length: + return fb; + case includes(CollectionType.GENERAL, filters): + return fb.addNotIn('type', difference(NON_GENERAL_COLLECTION_TYPES, filters), COLLECTION_PROPERTIES_PREFIX); + default: + return fb.addIn('type', filters, COLLECTION_PROPERTIES_PREFIX); + } +}; + export const serializeResourceTypeFilters = pipe( createFiltersBuilder, serializeObjectTypeFilters,