X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/4bbaf2a0cede89ea50d63d210c6631adc1970620..1a9eb2261e6030ba78078e2a206bad27653f2475:/src/components/data-table/data-table.tsx?ds=sidebyside

diff --git a/src/components/data-table/data-table.tsx b/src/components/data-table/data-table.tsx
index e7ce03ad..43efdd0a 100644
--- a/src/components/data-table/data-table.tsx
+++ b/src/components/data-table/data-table.tsx
@@ -3,18 +3,21 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from 'react';
-import { Table, TableBody, TableRow, TableCell, TableHead, StyleRulesCallback, Theme, WithStyles, withStyles, Typography } from '@material-ui/core';
+import { Table, TableBody, TableRow, TableCell, TableHead, TableSortLabel, StyleRulesCallback, Theme, WithStyles, withStyles, Typography } from '@material-ui/core';
 import { DataColumn } from './data-column';
 
+export type DataColumns<T> = Array<DataColumn<T>>;
+
 export interface DataTableProps<T> {
     items: T[];
-    columns: Array<DataColumn<T>>;
-    onItemClick?: (item: T) => void;
+    columns: DataColumns<T>;
+    onRowClick?: (event: React.MouseEvent<HTMLTableRowElement>, item: T) => void;
+    onRowContextMenu?: (event: React.MouseEvent<HTMLTableRowElement>, item: T) => void;
 }
 
 class DataTable<T> extends React.Component<DataTableProps<T> & WithStyles<CssRules>> {
     render() {
-        const { items, columns, classes, onItemClick } = this.props;
+        const { items, columns, classes, onRowClick, onRowContextMenu } = this.props;
         return <div className={classes.tableContainer}>
             {items.length > 0 ?
                 <Table>
@@ -22,9 +25,16 @@ class DataTable<T> extends React.Component<DataTableProps<T> & WithStyles<CssRul
                         <TableRow>
                             {columns
                                 .filter(column => column.selected)
-                                .map(({ name, renderHeader, key }, index) =>
+                                .map(({ name, renderHeader, key, sortDirection, onSortToggle }, index) =>
                                     <TableCell key={key || index}>
-                                        {renderHeader ? renderHeader() : name}
+                                        {renderHeader ?
+                                            renderHeader() :
+                                            <TableSortLabel
+                                                active={!!sortDirection}
+                                                direction={sortDirection}
+                                                onClick={() => onSortToggle && onSortToggle()}>
+                                                {name}
+                                            </TableSortLabel>}
                                     </TableCell>
                                 )}
                         </TableRow>
@@ -35,7 +45,8 @@ class DataTable<T> extends React.Component<DataTableProps<T> & WithStyles<CssRul
                                 <TableRow
                                     hover
                                     key={index}
-                                    onClick={() => onItemClick && onItemClick(item)}>
+                                    onClick={event => onRowClick && onRowClick(event, item)}
+                                    onContextMenu={event => onRowContextMenu && onRowContextMenu(event, item)}>
                                     {columns
                                         .filter(column => column.selected)
                                         .map((column, index) => (
@@ -46,7 +57,7 @@ class DataTable<T> extends React.Component<DataTableProps<T> & WithStyles<CssRul
                                 </TableRow>
                             )}
                     </TableBody>
-                </Table> : <Typography 
+                </Table> : <Typography
                     className={classes.noItemsInfo}
                     variant="body2"
                     gutterBottom>
