From dd01c37f3cc8b741e4202c480271eb2ffa6a3021 Mon Sep 17 00:00:00 2001 From: Michal Klobukowski Date: Tue, 24 Jul 2018 10:39:14 +0200 Subject: [PATCH] Add possibility to filter favorites by type Feature #13753 Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski --- .../favorite-panel-middleware.ts | 38 ++----------------- 1 file changed, 3 insertions(+), 35 deletions(-) diff --git a/src/store/favorite-panel/favorite-panel-middleware.ts b/src/store/favorite-panel/favorite-panel-middleware.ts index 5848ec7c5a..27e36b0caa 100644 --- a/src/store/favorite-panel/favorite-panel-middleware.ts +++ b/src/store/favorite-panel/favorite-panel-middleware.ts @@ -21,6 +21,7 @@ import { } from "../../views/favorite-panel/favorite-panel"; import { FavoritePanelItem, resourceToDataItem } from "../../views/favorite-panel/favorite-panel-item"; import { LinkResource } from "../../models/link"; +import { ResourceKind } from "../../models/resource"; export const favoritePanelMiddleware: Middleware = store => next => { next(dataExplorerActions.SET_COLUMNS({ id: FAVORITE_PANEL_ID, columns })); @@ -58,28 +59,14 @@ export const favoritePanelMiddleware: Middleware = store => next => { const dataExplorer = getDataExplorer(state.dataExplorer, FAVORITE_PANEL_ID); const columns = dataExplorer.columns as DataColumns; const typeFilters = getColumnFilters(columns, FavoritePanelColumnNames.TYPE); - const statusFilters = getColumnFilters(columns, FavoritePanelColumnNames.STATUS); - const sortColumn = dataExplorer.columns.find(({ sortDirection }) => Boolean(sortDirection && sortDirection !== "none")); - const sortDirection = sortColumn && sortColumn.sortDirection === SortDirection.Asc ? SortDirection.Asc : SortDirection.Desc; if (typeFilters.length > 0) { favoriteService .list(state.projects.currentItemId, { limit: dataExplorer.rowsPerPage, offset: dataExplorer.page * dataExplorer.rowsPerPage, - order: sortColumn - ? sortColumn.name === FavoritePanelColumnNames.NAME - ? getOrder("name", sortDirection) - : getOrder("createdAt", sortDirection) - : OrderBuilder.create(), filters: FilterBuilder - .create() - .concat(FilterBuilder - .create() - .addIsA("uuid", typeFilters.map(f => f.type))) - .concat(FilterBuilder - .create(GroupContentsResourcePrefix.Process) - .addIn("state", statusFilters.map(f => f.type))) - .concat(getSearchFilter(dataExplorer.searchValue)) + .create() + .addIsA("headUuid", typeFilters.map(filter => filter.type)) }) .then(response => { store.dispatch(dataExplorerActions.SET_ITEMS({ @@ -110,24 +97,5 @@ const getColumnFilters = (columns: DataColumns f.selected) : []; }; -const getOrder = (attribute: "name" | "createdAt", direction: SortDirection) => - [ - OrderBuilder.create(GroupContentsResourcePrefix.Collection), - OrderBuilder.create(GroupContentsResourcePrefix.Process), - OrderBuilder.create(GroupContentsResourcePrefix.Project) - ].reduce((acc, b) => - acc.concat(direction === SortDirection.Asc - ? b.addAsc(attribute) - : b.addDesc(attribute)), OrderBuilder.create()); - -const getSearchFilter = (searchValue: string) => - searchValue - ? [ - FilterBuilder.create(GroupContentsResourcePrefix.Collection), - FilterBuilder.create(GroupContentsResourcePrefix.Process), - FilterBuilder.create(GroupContentsResourcePrefix.Project)] - .reduce((acc, b) => - acc.concat(b.addILike("name", searchValue)), FilterBuilder.create()) - : FilterBuilder.create(); -- 2.30.2