2 // Copyright (C) The Arvados Authors. All rights reserved.
4 // SPDX-License-Identifier: AGPL-3.0
6 import { Middleware } from "../../../node_modules/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());
12 next(actions.SET_COLUMNS({ columns: service.getColumns() }));
15 const handleAction = <T extends { id: string }>(handler: (data: T) => void) =>
18 if (data.id === service.getId()) {
22 dataExplorerActions.match(action, {
23 SET_PAGE: handleAction(() => {
24 api.dispatch(actions.REQUEST_ITEMS());
26 SET_ROWS_PER_PAGE: handleAction(() => {
27 api.dispatch(actions.REQUEST_ITEMS());
29 SET_FILTERS: handleAction(() => {
30 api.dispatch(actions.RESET_PAGINATION());
31 api.dispatch(actions.REQUEST_ITEMS());
33 TOGGLE_SORT: handleAction(() => {
34 api.dispatch(actions.REQUEST_ITEMS());
36 SET_SEARCH_VALUE: handleAction(() => {
37 api.dispatch(actions.RESET_PAGINATION());
38 api.dispatch(actions.REQUEST_ITEMS());
40 REQUEST_ITEMS: handleAction(() => {
41 service.requestItems(api);
43 default: () => next(action)