X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/72c12f527787181e4abb09fc968f07e795179c3c..62cb779efb0b098c05053e957c765a807467b28b:/src/store/data-explorer/data-explorer-middleware-service.ts diff --git a/src/store/data-explorer/data-explorer-middleware-service.ts b/src/store/data-explorer/data-explorer-middleware-service.ts index 14be4ea7..0b8d6deb 100644 --- a/src/store/data-explorer/data-explorer-middleware-service.ts +++ b/src/store/data-explorer/data-explorer-middleware-service.ts @@ -2,19 +2,57 @@ // // SPDX-License-Identifier: AGPL-3.0 -import { Dispatch, MiddlewareAPI } from "redux"; -import { RootState } from "../store"; +import { Dispatch, MiddlewareAPI } from 'redux'; +import { RootState } from '../store'; +import { DataColumns } from 'components/data-table/data-table'; +import { DataExplorer } from './data-explorer-reducer'; +import { ListResults } from 'services/common-service/common-service'; +import { createTree } from 'models/tree'; +import { DataTableFilters } from 'components/data-table-filters/data-table-filters-tree'; export abstract class DataExplorerMiddlewareService { - protected readonly id: string; + protected readonly id: string; - protected constructor(id: string) { - this.id = id; - } + protected constructor(id: string) { + this.id = id; + } - public getId() { - return this.id; - } + public getId() { + return this.id; + } - abstract requestItems(api: MiddlewareAPI): void; + public getColumnFilters( + columns: DataColumns, + columnName: string + ): DataTableFilters { + return getDataExplorerColumnFilters(columns, columnName); + } + + abstract requestItems( + api: MiddlewareAPI, + criteriaChanged?: boolean + ): Promise; } + +export const getDataExplorerColumnFilters = ( + columns: DataColumns, + columnName: string +): DataTableFilters => { + const column = columns.find((c) => c.name === columnName); + return column ? column.filters : createTree(); +}; + +export const dataExplorerToListParams = (dataExplorer: DataExplorer) => ({ + limit: dataExplorer.rowsPerPage, + offset: dataExplorer.page * dataExplorer.rowsPerPage, +}); + +export const listResultsToDataExplorerItemsMeta = ({ + itemsAvailable, + offset, + limit, +}: ListResults) => ({ + itemsAvailable, + page: Math.floor(offset / limit), + rowsPerPage: limit, +});