1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from "react";
6 import { DataTableFilterItem } from "../data-table-filters/data-table-filters";
8 export interface DataColumn<T, F extends DataTableFilterItem = DataTableFilterItem> {
12 configurable: boolean;
13 sortDirection: SortDirection;
15 render: (item: T) => React.ReactElement<any>;
16 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, F extends DataTableFilterItem>(dataColumn: Partial<DataColumn<T, F>>): DataColumn<T, F> => ({
43 sortDirection: SortDirection.NONE,
45 render: () => React.createElement('span'),