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 { DataExplorer } from './data-explorer-reducer';
9 import { ListResults } from '~/services/common-service/common-service';
10 import { createTree } from "~/models/tree";
11 import { DataTableFilters } from "~/components/data-table-filters/data-table-filters-tree";
13 export abstract class DataExplorerMiddlewareService {
14 protected readonly id: string;
16 protected constructor(id: string) {
24 public getColumnFilters<T>(columns: DataColumns<T>, columnName: string): DataTableFilters {
25 return getDataExplorerColumnFilters(columns, columnName);
28 abstract requestItems(api: MiddlewareAPI<Dispatch, RootState>): void;
31 export const getDataExplorerColumnFilters = <T>(columns: DataColumns<T>, columnName: string): DataTableFilters => {
32 const column = columns.find(c => c.name === columnName);
33 return column ? column.filters : createTree();
36 export const dataExplorerToListParams = (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),