1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { DataTableFilterItem } from "../data-table-filters/data-table-filters";
7 export interface DataColumn<T, F extends DataTableFilterItem = DataTableFilterItem> {
10 configurable?: boolean;
12 sortDirection?: SortDirection;
14 render: (item: T) => React.ReactElement<void>;
15 renderHeader?: () => React.ReactElement<void> | null;
19 export enum SortDirection {
25 export const isColumnConfigurable = <T>(column: DataColumn<T>) => {
26 return column.configurable === undefined || column.configurable;
29 export const toggleSortDirection = <T>(column: DataColumn<T>): DataColumn<T> => {
30 return column.sortDirection
31 ? column.sortDirection === SortDirection.ASC
32 ? { ...column, sortDirection: SortDirection.DESC }
33 : { ...column, sortDirection: SortDirection.ASC }
37 export const resetSortDirection = <T>(column: DataColumn<T>): DataColumn<T> => {
38 return column.sortDirection ? { ...column, sortDirection: SortDirection.NONE } : column;