1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { Middleware } from "redux";
6 import actions from "../../store/data-explorer/data-explorer-action";
7 import { PROJECT_PANEL_ID, columns } from "./project-panel";
8 import { groupsService } from "../../services/services";
9 import { RootState } from "../../store/store";
10 import { getDataExplorer } from "../../store/data-explorer/data-explorer-reducer";
11 import { resourceToDataItem } from "./project-panel-item";
13 export const projectPanelMiddleware: Middleware = store => next => {
14 next(actions.SET_COLUMNS({ id: PROJECT_PANEL_ID, columns }));
18 const handleProjectPanelAction = <T extends { id: string }>(handler: (data: T) => void) =>
21 if (data.id === PROJECT_PANEL_ID) {
26 actions.match(action, {
27 SET_PAGE: handleProjectPanelAction(() => {
28 store.dispatch(actions.REQUEST_ITEMS({ id: PROJECT_PANEL_ID }));
30 SET_ROWS_PER_PAGE: handleProjectPanelAction(() => {
31 store.dispatch(actions.REQUEST_ITEMS({ id: PROJECT_PANEL_ID }));
33 REQUEST_ITEMS: handleProjectPanelAction(() => {
34 const state = store.getState() as RootState;
35 const dataExplorer = getDataExplorer(state.dataExplorer, PROJECT_PANEL_ID);
37 .contents(state.projects.currentItemId, {
38 limit: dataExplorer.rowsPerPage,
39 offset: dataExplorer.page * dataExplorer.rowsPerPage,
42 store.dispatch(actions.SET_ITEMS({
44 items: response.items.map(resourceToDataItem),
45 itemsAvailable: response.itemsAvailable,
46 page: Math.floor(response.offset / response.limit),
47 rowsPerPage: response.limit
52 default: () => next(action)