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>;
19 export enum SortDirection {
25 export const toggleSortDirection = <T>(column: DataColumn<T>): DataColumn<T> => {
26 return column.sortDirection
27 ? column.sortDirection === SortDirection.ASC
28 ? { ...column, sortDirection: SortDirection.DESC }
29 : { ...column, sortDirection: SortDirection.ASC }
33 export const resetSortDirection = <T>(column: DataColumn<T>): DataColumn<T> => {
34 return column.sortDirection ? { ...column, sortDirection: SortDirection.NONE } : column;
37 export const createDataColumn = <T, F extends DataTableFilterItem>(dataColumn: Partial<DataColumn<T, F>>): DataColumn<T, F> => ({
42 sortDirection: SortDirection.NONE,
44 render: () => React.createElement('span'),