X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/355aa79f1a2abb5e8142062d83f897d780cc8a8e..7ae86efd9905582df4191910528c3803a68ba81b:/src/store/project-panel/project-panel-middleware.ts diff --git a/src/store/project-panel/project-panel-middleware.ts b/src/store/project-panel/project-panel-middleware.ts index 1ba2ba2e34..b7ab03ceca 100644 --- a/src/store/project-panel/project-panel-middleware.ts +++ b/src/store/project-panel/project-panel-middleware.ts @@ -3,21 +3,22 @@ // SPDX-License-Identifier: AGPL-3.0 import { Middleware } from "redux"; -import actions from "../data-explorer/data-explorer-action"; -import { PROJECT_PANEL_ID, ProjectPanelFilter, columns, ProjectPanelColumnNames } from "../../views/project-panel/project-panel"; +import { dataExplorerActions } from "../data-explorer/data-explorer-action"; +import { PROJECT_PANEL_ID, columns, ProjectPanelFilter, ProjectPanelColumnNames } from "../../views/project-panel/project-panel"; import { groupsService } from "../../services/services"; import { RootState } from "../store"; import { getDataExplorer } from "../data-explorer/data-explorer-reducer"; import { resourceToDataItem, ProjectPanelItem } from "../../views/project-panel/project-panel-item"; -import FilterBuilder from "../../common/api/filter-builder"; +import { FilterBuilder } from "../../common/api/filter-builder"; import { DataColumns } from "../../components/data-table/data-table"; import { ProcessResource } from "../../models/process"; -import OrderBuilder from "../../common/api/order-builder"; +import { OrderBuilder } from "../../common/api/order-builder"; import { GroupContentsResource, GroupContentsResourcePrefix } from "../../services/groups-service/groups-service"; import { SortDirection } from "../../components/data-table/data-column"; +import { checkPresenceInFavorites } from "../favorites/favorites-actions"; export const projectPanelMiddleware: Middleware = store => next => { - next(actions.SET_COLUMNS({ id: PROJECT_PANEL_ID, columns })); + next(dataExplorerActions.SET_COLUMNS({ id: PROJECT_PANEL_ID, columns })); return action => { @@ -29,23 +30,23 @@ export const projectPanelMiddleware: Middleware = store => next => { } }; - actions.match(action, { + dataExplorerActions.match(action, { SET_PAGE: handleProjectPanelAction(() => { - store.dispatch(actions.REQUEST_ITEMS({ id: PROJECT_PANEL_ID })); + store.dispatch(dataExplorerActions.REQUEST_ITEMS({ id: PROJECT_PANEL_ID })); }), SET_ROWS_PER_PAGE: handleProjectPanelAction(() => { - store.dispatch(actions.REQUEST_ITEMS({ id: PROJECT_PANEL_ID })); + store.dispatch(dataExplorerActions.REQUEST_ITEMS({ id: PROJECT_PANEL_ID })); }), SET_FILTERS: handleProjectPanelAction(() => { - store.dispatch(actions.RESET_PAGINATION({ id: PROJECT_PANEL_ID })); - store.dispatch(actions.REQUEST_ITEMS({ id: PROJECT_PANEL_ID })); + store.dispatch(dataExplorerActions.RESET_PAGINATION({ id: PROJECT_PANEL_ID })); + store.dispatch(dataExplorerActions.REQUEST_ITEMS({ id: PROJECT_PANEL_ID })); }), TOGGLE_SORT: handleProjectPanelAction(() => { - store.dispatch(actions.REQUEST_ITEMS({ id: PROJECT_PANEL_ID })); + store.dispatch(dataExplorerActions.REQUEST_ITEMS({ id: PROJECT_PANEL_ID })); }), SET_SEARCH_VALUE: handleProjectPanelAction(() => { - store.dispatch(actions.RESET_PAGINATION({ id: PROJECT_PANEL_ID })); - store.dispatch(actions.REQUEST_ITEMS({ id: PROJECT_PANEL_ID })); + store.dispatch(dataExplorerActions.RESET_PAGINATION({ id: PROJECT_PANEL_ID })); + store.dispatch(dataExplorerActions.REQUEST_ITEMS({ id: PROJECT_PANEL_ID })); }), REQUEST_ITEMS: handleProjectPanelAction(() => { const state = store.getState() as RootState; @@ -54,7 +55,7 @@ export const projectPanelMiddleware: Middleware = store => next => { const typeFilters = getColumnFilters(columns, ProjectPanelColumnNames.TYPE); const statusFilters = getColumnFilters(columns, ProjectPanelColumnNames.STATUS); const sortColumn = dataExplorer.columns.find(({ sortDirection }) => Boolean(sortDirection && sortDirection !== "none")); - const sortDirection = sortColumn && sortColumn.sortDirection === SortDirection.Asc ? SortDirection.Asc : SortDirection.Desc; + const sortDirection = sortColumn && sortColumn.sortDirection === SortDirection.ASC ? SortDirection.ASC : SortDirection.DESC; if (typeFilters.length > 0) { groupsService .contents(state.projects.currentItemId, { @@ -71,21 +72,22 @@ export const projectPanelMiddleware: Middleware = store => next => { .create() .addIsA("uuid", typeFilters.map(f => f.type))) .concat(FilterBuilder - .create(GroupContentsResourcePrefix.Process) + .create(GroupContentsResourcePrefix.PROCESS) .addIn("state", statusFilters.map(f => f.type))) .concat(getSearchFilter(dataExplorer.searchValue)) }) .then(response => { - store.dispatch(actions.SET_ITEMS({ + store.dispatch(dataExplorerActions.SET_ITEMS({ id: PROJECT_PANEL_ID, items: response.items.map(resourceToDataItem), itemsAvailable: response.itemsAvailable, page: Math.floor(response.offset / response.limit), rowsPerPage: response.limit })); + store.dispatch(checkPresenceInFavorites(response.items.map(item => item.uuid))); }); } else { - store.dispatch(actions.SET_ITEMS({ + store.dispatch(dataExplorerActions.SET_ITEMS({ id: PROJECT_PANEL_ID, items: [], itemsAvailable: 0, @@ -106,20 +108,20 @@ const getColumnFilters = (columns: DataColumns [ - OrderBuilder.create(GroupContentsResourcePrefix.Collection), - OrderBuilder.create(GroupContentsResourcePrefix.Process), - OrderBuilder.create(GroupContentsResourcePrefix.Project) + OrderBuilder.create(GroupContentsResourcePrefix.COLLECTION), + OrderBuilder.create(GroupContentsResourcePrefix.PROCESS), + OrderBuilder.create(GroupContentsResourcePrefix.PROJECT) ].reduce((acc, b) => - acc.concat(direction === SortDirection.Asc + 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)] + 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();