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 } from "./data-explorer-action";
8 import { DataExplorerMiddlewareService } from "./data-explorer-middleware-service";
10 export const dataExplorerMiddleware = (service: DataExplorerMiddlewareService): Middleware => api => next => {
12 next(dataExplorerActions.SET_COLUMNS({ id: service.Id, columns: service.Columns }));
14 const handleAction = <T extends { id: string }>(handler: (data: T) => void) =>
17 if (data.id === service.Id) {
21 dataExplorerActions.match(action, {
22 SET_PAGE: handleAction(() => {
23 api.dispatch(dataExplorerActions.REQUEST_ITEMS({ id: service.Id }));
25 SET_ROWS_PER_PAGE: handleAction(() => {
26 api.dispatch(dataExplorerActions.REQUEST_ITEMS({ id: service.Id }));
28 SET_FILTERS: handleAction(() => {
29 api.dispatch(dataExplorerActions.RESET_PAGINATION({ id: service.Id }));
30 api.dispatch(dataExplorerActions.REQUEST_ITEMS({ id: service.Id }));
32 TOGGLE_SORT: handleAction(() => {
33 api.dispatch(dataExplorerActions.REQUEST_ITEMS({ id: service.Id }));
35 SET_SEARCH_VALUE: handleAction(() => {
36 api.dispatch(dataExplorerActions.RESET_PAGINATION({ id: service.Id }));
37 api.dispatch(dataExplorerActions.REQUEST_ITEMS({ id: service.Id }));
39 REQUEST_ITEMS: handleAction(() => {
40 service.requestItems(api);
42 default: () => next(action)