Merge branch 'master'
[arvados.git] / src / components / data-table / data-column.ts
index d3b147362651256d2c1cf546643ef2788de2c7f0..f3d9576dd66d5cac933dffdc5e96c67464c9610e 100644 (file)
@@ -7,10 +7,23 @@ export interface DataColumn<T> {
     selected: boolean;
     configurable?: boolean;
     key?: React.Key;
+    sortDirection?: SortDirection;
+    onSortToggle?: () => void;
     render: (item: T) => React.ReactElement<void>;
     renderHeader?: () => React.ReactElement<void> | null;
 }
 
+export type SortDirection = "asc" | "desc";
+
 export const isColumnConfigurable = <T>(column: DataColumn<T>) => {
     return column.configurable === undefined || column.configurable;
-};
\ No newline at end of file
+};
+
+export const toggleSortDirection = <T>(column: DataColumn<T>): DataColumn<T> => {
+    const sortDirection = column.sortDirection === undefined || column.sortDirection === "desc" ? "asc" : "desc";
+    return { ...column, sortDirection };
+};
+
+export const resetSortDirection = <T>(column: DataColumn<T>): DataColumn<T> => {
+    return { ...column, sortDirection: undefined };
+};