X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/d0f49b7683fe607b6165c0232ff220080142eb57..96f66c48c34febdf6478026ef1f575f441c7d614:/src/components/data-table/data-table.tsx

diff --git a/src/components/data-table/data-table.tsx b/src/components/data-table/data-table.tsx
index 5a6f9e5a..25d81c62 100644
--- a/src/components/data-table/data-table.tsx
+++ b/src/components/data-table/data-table.tsx
@@ -5,7 +5,8 @@
 import * as React from 'react';
 import { Table, TableBody, TableRow, TableCell, TableHead, TableSortLabel, StyleRulesCallback, Theme, WithStyles, withStyles } from '@material-ui/core';
 import { DataColumn, SortDirection } from './data-column';
-import { DataTableFilters,  DataTableFilterItem } from "../data-table-filters/data-table-filters";
+import { DataTableFilters, DataTableFilterItem } from "../data-table-filters/data-table-filters";
+import { DataTableDefaultView } from '../data-table-default-view/data-table-default-view';
 
 export type DataColumns<T, F extends DataTableFilterItem = DataTableFilterItem> = Array<DataColumn<T, F>>;
 
@@ -18,21 +19,30 @@ export interface DataTableDataProps<T> {
     onSortToggle: (column: DataColumn<T>) => void;
     onFiltersChange: (filters: DataTableFilterItem[], column: DataColumn<T>) => void;
     extractKey?: (item: T) => React.Key;
+    working?: boolean;
+    defaultView?: React.ReactNode;
 }
 
-type CssRules = "tableBody" | "tableContainer" | "noItemsInfo";
+type CssRules = "tableBody" | "root" | "content" | "noItemsInfo" | 'tableCell';
 
 const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
-    tableContainer: {
+    root: {
         overflowX: 'auto',
         overflowY: 'hidden'
     },
+    content: {
+        display: 'inline-block',
+        width: '100%'
+    },
     tableBody: {
         background: theme.palette.background.paper
     },
     noItemsInfo: {
         textAlign: "center",
         padding: theme.spacing.unit
+    },
+    tableCell: {
+        wordWrap: 'break-word'
     }
 });
 
@@ -42,25 +52,33 @@ export const DataTable = withStyles(styles)(
     class Component<T> extends React.Component<DataTableProps<T>> {
         render() {
             const { items, classes } = this.props;
-            return <div
-                className={classes.tableContainer}>
-                <Table>
-                    <TableHead>
-                        <TableRow>
-                            {this.mapVisibleColumns(this.renderHeadCell)}
-                        </TableRow>
-                    </TableHead>
-                    <TableBody className={classes.tableBody}>
-                        {items.map(this.renderBodyRow)}
-                    </TableBody>
-                </Table>
+            return <div className={classes.root}>
+                <div className={classes.content}>
+                    <Table>
+                        <TableHead>
+                            <TableRow>
+                                {this.mapVisibleColumns(this.renderHeadCell)}
+                            </TableRow>
+                        </TableHead>
+                        <TableBody className={classes.tableBody}>
+                            {items.map(this.renderBodyRow)}
+                        </TableBody>
+                    </Table>
+                    {items.length === 0 && this.props.working !== undefined && !this.props.working && this.renderNoItemsPlaceholder()}
+                </div>
             </div>;
         }
 
+        renderNoItemsPlaceholder = () => {
+            return this.props.defaultView
+                ? this.props.defaultView
+                : <DataTableDefaultView/>;
+        }
+
         renderHeadCell = (column: DataColumn<T>, index: number) => {
             const { name, key, renderHeader, filters, sortDirection } = column;
             const { onSortToggle, onFiltersChange } = this.props;
-            return <TableCell key={key || index} style={{ width: column.width, minWidth: column.width }}>
+            return <TableCell key={key || index}>
                 {renderHeader ?
                     renderHeader() :
                     filters.length > 0
@@ -88,15 +106,15 @@ export const DataTable = withStyles(styles)(
         }
 
         renderBodyRow = (item: T, index: number) => {
-            const { onRowClick, onRowDoubleClick, extractKey } = this.props;
+            const { onRowClick, onRowDoubleClick, extractKey, classes } = this.props;
             return <TableRow
                 hover
                 key={extractKey ? extractKey(item) : index}
                 onClick={event => onRowClick && onRowClick(event, item)}
                 onContextMenu={this.handleRowContextMenu(item)}
-                onDoubleClick={event => onRowDoubleClick && onRowDoubleClick(event, item) }>
+                onDoubleClick={event => onRowDoubleClick && onRowDoubleClick(event, item)}>
                 {this.mapVisibleColumns((column, index) => (
-                    <TableCell key={column.key || index}>
+                    <TableCell key={column.key || index} className={classes.tableCell}>
                         {column.render(item)}
                     </TableCell>
                 ))}
