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';
9 export interface DataColumn<T> {
13 configurable: boolean;
16 * If set to true, filters on this column will be displayed in a
17 * radio group and only one filter can be selected at a time.
19 mutuallyExclusiveFilters?: boolean;
20 sortDirection?: SortDirection;
21 filters: DataTableFilters;
22 render: (item: T) => React.ReactElement<any>;
23 renderHeader?: () => React.ReactElement<any>;
26 export enum SortDirection {
32 export const toggleSortDirection = <T>(column: DataColumn<T>): DataColumn<T> => {
33 return column.sortDirection
34 ? column.sortDirection === SortDirection.ASC
35 ? { ...column, sortDirection: SortDirection.DESC }
36 : { ...column, sortDirection: SortDirection.ASC }
40 export const resetSortDirection = <T>(column: DataColumn<T>): DataColumn<T> => {
41 return column.sortDirection ? { ...column, sortDirection: SortDirection.NONE } : column;
44 export const createDataColumn = <T>(dataColumn: Partial<DataColumn<T>>): DataColumn<T> => ({
49 sortDirection: SortDirection.NONE,
50 filters: createTree(),
51 render: () => React.createElement('span'),