1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { Dispatch, MiddlewareAPI } from "redux";
6 import { RootState } from "../store";
7 import { DataColumns } from "~/components/data-table/data-table";
8 import { DataTableFilterItem } from "~/components/data-table-filters/data-table-filters";
9 import { DataExplorer } from './data-explorer-reducer';
10 import { ListResults } from '~/services/common-service/common-resource-service';
12 export abstract class DataExplorerMiddlewareService {
13 protected readonly id: string;
15 protected constructor(id: string) {
23 public getColumnFilters<T, F extends DataTableFilterItem>(columns: DataColumns<T, F>, columnName: string): F[] {
24 const column = columns.find(c => c.name === columnName);
25 return column ? column.filters.filter(f => f.selected) : [];
28 abstract requestItems(api: MiddlewareAPI<Dispatch, RootState>): void;
31 export const getDataExplorerColumnFilters = <T, F extends DataTableFilterItem>(columns: DataColumns<T, F>, columnName: string): F[] => {
32 const column = columns.find(c => c.name === columnName);
33 return column ? column.filters.filter(f => f.selected) : [];
36 export const dataExplorerToListParams = <R>(dataExplorer: DataExplorer) => ({
37 limit: dataExplorer.rowsPerPage,
38 offset: dataExplorer.page * dataExplorer.rowsPerPage,
41 export const listResultsToDataExplorerItemsMeta = <R>({ itemsAvailable, offset, limit }: ListResults<R>) => ({
43 page: Math.floor(offset / limit),