X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/95bc64c72fa9e7ede2cc235ee668ee2e8aa6a1f0..e7c978d1f6fa309e8462fc952f2735c39a4040bb:/src/components/data-explorer/data-explorer.tsx

diff --git a/src/components/data-explorer/data-explorer.tsx b/src/components/data-explorer/data-explorer.tsx
index 557b0158ee..09a327268b 100644
--- a/src/components/data-explorer/data-explorer.tsx
+++ b/src/components/data-explorer/data-explorer.tsx
@@ -7,7 +7,7 @@ import { Grid, Paper, Toolbar, StyleRulesCallback, withStyles, Theme, WithStyles
 import MoreVertIcon from "@material-ui/icons/MoreVert";
 import ContextMenu, { ContextMenuActionGroup, ContextMenuAction } from "../../components/context-menu/context-menu";
 import ColumnSelector from "../../components/column-selector/column-selector";
-import DataTable from "../../components/data-table/data-table";
+import DataTable, { DataColumns, DataItem } from "../../components/data-table/data-table";
 import { mockAnchorFromMouseEvent } from "../../components/popover/helpers";
 import { DataColumn } from "../../components/data-table/data-column";
 import { DataTableFilterItem } from '../../components/data-table-filters/data-table-filters';
@@ -15,10 +15,12 @@ import SearchInput from '../search-input/search-input';
 
 interface DataExplorerProps<T> {
     items: T[];
-    columns: Array<DataColumn<T>>;
+    itemsAvailable: number;
+    columns: DataColumns<T>;
     contextActions: ContextMenuActionGroup[];
     searchValue: string;
     rowsPerPage: number;
+    rowsPerPageOptions?: number[];
     page: number;
     onSearch: (value: string) => void;
     onRowClick: (item: T) => void;
@@ -37,7 +39,7 @@ interface DataExplorerState<T> {
     };
 }
 
-class DataExplorer<T> extends React.Component<DataExplorerProps<T> & WithStyles<CssRules>, DataExplorerState<T>> {
+class DataExplorer<T extends DataItem> extends React.Component<DataExplorerProps<T> & WithStyles<CssRules>, DataExplorerState<T>> {
     state: DataExplorerState<T> = {
         contextMenu: {}
     };
@@ -52,9 +54,9 @@ class DataExplorer<T> extends React.Component<DataExplorerProps<T> & WithStyles<
             <Toolbar className={this.props.classes.toolbar}>
                 <Grid container justify="space-between" wrap="nowrap" alignItems="center">
                     <div className={this.props.classes.searchBox}>
-                        {this.props.items.length > 0 && <SearchInput
+                        <SearchInput
                             value={this.props.searchValue}
-                            onSearch={this.props.onSearch} />}
+                            onSearch={this.props.onSearch} />
                     </div>
                     <ColumnSelector
                         columns={this.props.columns}
@@ -62,9 +64,7 @@ class DataExplorer<T> extends React.Component<DataExplorerProps<T> & WithStyles<
                 </Grid>
             </Toolbar>
             <DataTable
-                columns={[
-                    ...this.props.columns,
-                    this.contextMenuColumn]}
+                columns={[...this.props.columns, this.contextMenuColumn]}
                 items={this.props.items}
                 onRowClick={(_, item: T) => this.props.onRowClick(item)}
                 onRowContextMenu={this.openContextMenu}
@@ -74,8 +74,9 @@ class DataExplorer<T> extends React.Component<DataExplorerProps<T> & WithStyles<
                 {this.props.items.length > 0 &&
                     <Grid container justify="flex-end">
                         <TablePagination
-                            count={this.props.items.length}
+                            count={this.props.itemsAvailable}
                             rowsPerPage={this.props.rowsPerPage}
+                            rowsPerPageOptions={this.props.rowsPerPageOptions}
                             page={this.props.page}
                             onChangePage={this.changePage}
                             onChangeRowsPerPage={this.changeRowsPerPage}
@@ -119,11 +120,21 @@ class DataExplorer<T> extends React.Component<DataExplorerProps<T> & WithStyles<
 
     renderContextMenuTrigger = (item: T) =>
         <Grid container justify="flex-end">
-            <IconButton onClick={event => this.openContextMenu(event, item)}>
+            <IconButton onClick={event => this.openContextMenuTrigger(event, item)}>
                 <MoreVertIcon />
             </IconButton>
         </Grid>
 
+    openContextMenuTrigger = (event: React.MouseEvent<HTMLElement>, item: T) => {
+        event.preventDefault();
+        this.setState({
+            contextMenu: {
+                anchorEl: event.currentTarget,
+                item
+            }
+        });
+    }
+
     contextMenuColumn = {
         name: "Actions",
         selected: true,
