1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as 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;
14 sortDirection?: SortDirection;
15 filters: DataTableFilters;
16 render: (item: T) => React.ReactElement<any>;
17 renderHeader?: () => React.ReactElement<any>;
20 export enum SortDirection {
26 export const toggleSortDirection = <T>(column: DataColumn<T>): DataColumn<T> => {
27 return column.sortDirection
28 ? column.sortDirection === SortDirection.ASC
29 ? { ...column, sortDirection: SortDirection.DESC }
30 : { ...column, sortDirection: SortDirection.ASC }
34 export const resetSortDirection = <T>(column: DataColumn<T>): DataColumn<T> => {
35 return column.sortDirection ? { ...column, sortDirection: SortDirection.NONE } : column;
38 export const createDataColumn = <T>(dataColumn: Partial<DataColumn<T>>): DataColumn<T> => ({
43 sortDirection: SortDirection.NONE,
44 filters: createTree(),
45 render: () => React.createElement('span'),