2 // Copyright (C) The Arvados Authors. All rights reserved.
4 // SPDX-License-Identifier: AGPL-3.0
6 import { Middleware } from "redux";
7 import { dataExplorerActions, bindDataExplorerActions } from "./data-explorer-action";
8 import { DataExplorerMiddlewareService } from "./data-explorer-middleware-service";
10 export const dataExplorerMiddleware = (service: DataExplorerMiddlewareService): Middleware => api => next => {
11 const actions = bindDataExplorerActions(service.getId());
14 const handleAction = <T extends { id: string }>(handler: (data: T) => void) =>
17 if (data.id === service.getId()) {
21 dataExplorerActions.match(action, {
22 SET_PAGE: handleAction(() => {
23 api.dispatch(actions.REQUEST_ITEMS(false));
25 SET_ROWS_PER_PAGE: handleAction(() => {
26 api.dispatch(actions.REQUEST_ITEMS(true));
28 SET_FILTERS: handleAction(() => {
29 api.dispatch(actions.RESET_PAGINATION());
30 api.dispatch(actions.REQUEST_ITEMS(true));
32 TOGGLE_SORT: handleAction(() => {
33 api.dispatch(actions.REQUEST_ITEMS(true));
35 SET_EXPLORER_SEARCH_VALUE: handleAction(() => {
36 api.dispatch(actions.RESET_PAGINATION());
37 api.dispatch(actions.REQUEST_ITEMS(true));
39 REQUEST_ITEMS: handleAction(({ criteriaChanged }) => {
40 service.requestItems(api, criteriaChanged);
42 default: () => next(action)