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 handleAction = <T extends { id: string }>(handler: (data: T) => void) =>
13 if (data.id === service.getId()) {
17 const actions = bindDataExplorerActions(service.getId());
20 dataExplorerActions.match(action, {
21 SET_PAGE: handleAction(() => {
22 api.dispatch(actions.REQUEST_ITEMS());
24 SET_ROWS_PER_PAGE: handleAction(() => {
25 api.dispatch(actions.REQUEST_ITEMS());
27 SET_FILTERS: handleAction(() => {
28 api.dispatch(actions.RESET_PAGINATION());
29 api.dispatch(actions.REQUEST_ITEMS());
31 TOGGLE_SORT: handleAction(() => {
32 api.dispatch(actions.REQUEST_ITEMS());
34 SET_SEARCH_VALUE: handleAction(() => {
35 api.dispatch(actions.RESET_PAGINATION());
36 api.dispatch(actions.REQUEST_ITEMS());
38 REQUEST_ITEMS: handleAction(() => {
39 service.requestItems(api);
41 default: () => next(action)