1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from "react";
6 import { DataTableFilters } from "../data-table-filters/data-table-filters-tree";
7 import { createTree } from 'models/tree';
11 * @template I Type of dataexplorer item reference
12 * @template R Type of resource to use to restrict values of column sort.field
14 export interface DataColumn<I, R> {
18 configurable: boolean;
21 * If set to true, filters on this column will be displayed in a
22 * radio group and only one filter can be selected at a time.
24 mutuallyExclusiveFilters?: boolean;
25 sort?: {direction: SortDirection, field: keyof R};
26 filters: DataTableFilters;
27 render: (item: I) => React.ReactElement<any>;
28 renderHeader?: () => React.ReactElement<any>;
31 export enum SortDirection {
37 export const toggleSortDirection = <I, R>(column: DataColumn<I, R>): DataColumn<I, R> => {
39 ? column.sort.direction === SortDirection.ASC
40 ? { ...column, sort: {...column.sort, direction: SortDirection.DESC} }
41 : { ...column, sort: {...column.sort, direction: SortDirection.ASC} }
45 export const resetSortDirection = <I, R>(column: DataColumn<I, R>): DataColumn<I, R> => {
46 return column.sort ? { ...column, sort: {...column.sort, direction: SortDirection.NONE} } : column;
49 export const createDataColumn = <I, R>(dataColumn: Partial<DataColumn<I, R>>): DataColumn<I, R> => ({
54 filters: createTree(),
55 render: () => React.createElement('span'),