X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/616395646c46f90c46ad97bd9a335ab326e5a040..5219b97601d3aee849081f81536f8edd91d9ad53:/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 7ae66358..1073ddd8 100644
--- a/src/components/data-explorer/data-explorer.tsx
+++ b/src/components/data-explorer/data-explorer.tsx
@@ -3,81 +3,66 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from 'react';
-import { Grid, Paper, Toolbar, StyleRulesCallback, withStyles, Theme, WithStyles, TablePagination, Table, IconButton } from '@material-ui/core';
+import { Grid, Paper, Toolbar, StyleRulesCallback, withStyles, Theme, WithStyles, TablePagination, IconButton } from '@material-ui/core';
 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, { DataColumns } 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';
+import ColumnSelector from "../column-selector/column-selector";
+import DataTable, { DataColumns } from "../data-table/data-table";
+import { DataColumn } from "../data-table/data-column";
+import { DataTableFilterItem } from '../data-table-filters/data-table-filters';
 import SearchInput from '../search-input/search-input';
 
 interface DataExplorerProps<T> {
     items: T[];
+    itemsAvailable: number;
     columns: DataColumns<T>;
-    contextActions: ContextMenuActionGroup[];
     searchValue: string;
     rowsPerPage: number;
+    rowsPerPageOptions?: number[];
     page: number;
     onSearch: (value: string) => void;
     onRowClick: (item: T) => void;
+    onRowDoubleClick: (item: T) => void;
     onColumnToggle: (column: DataColumn<T>) => void;
-    onContextAction: (action: ContextMenuAction, item: T) => void;
+    onContextMenu: (event: React.MouseEvent<HTMLElement>, item: T) => void;
     onSortToggle: (column: DataColumn<T>) => void;
     onFiltersChange: (filters: DataTableFilterItem[], column: DataColumn<T>) => void;
     onChangePage: (page: number) => void;
     onChangeRowsPerPage: (rowsPerPage: number) => void;
+    extractKey?: (item: T) => React.Key;
 }
 
-interface DataExplorerState<T> {
-    contextMenu: {
-        anchorEl?: HTMLElement;
-        item?: T;
-    };
-}
-
-class DataExplorer<T> extends React.Component<DataExplorerProps<T> & WithStyles<CssRules>, DataExplorerState<T>> {
-    state: DataExplorerState<T> = {
-        contextMenu: {}
-    };
+class DataExplorer<T> extends React.Component<DataExplorerProps<T> & WithStyles<CssRules>> {
 
     render() {
         return <Paper>
-            <ContextMenu
-                anchorEl={this.state.contextMenu.anchorEl}
-                actions={this.props.contextActions}
-                onActionClick={this.callAction}
-                onClose={this.closeContextMenu} />
             <Toolbar className={this.props.classes.toolbar}>
-                {this.props.items.length > 0 &&
-                    <Grid container justify="space-between" wrap="nowrap" alignItems="center">
-                        <div className={this.props.classes.searchBox}>
-                            <SearchInput
-                                value={this.props.searchValue}
-                                onSearch={this.props.onSearch} />
-                        </div>
-                        <ColumnSelector
-                            columns={this.props.columns}
-                            onColumnToggle={this.props.onColumnToggle} />
-                    </Grid>}
-
+                <Grid container justify="space-between" wrap="nowrap" alignItems="center">
+                    <div className={this.props.classes.searchBox}>
+                        <SearchInput
+                            value={this.props.searchValue}
+                            onSearch={this.props.onSearch} />
+                    </div>
+                    <ColumnSelector
+                        columns={this.props.columns}
+                        onColumnToggle={this.props.onColumnToggle} />
+                </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}
+                onContextMenu={this.props.onContextMenu}
+                onRowDoubleClick={(_, item: T) => this.props.onRowDoubleClick(item)}
                 onFiltersChange={this.props.onFiltersChange}
-                onSortToggle={this.props.onSortToggle} />
+                onSortToggle={this.props.onSortToggle}
+                extractKey={this.props.extractKey} />
             <Toolbar>
                 {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}
@@ -88,28 +73,6 @@ class DataExplorer<T> extends React.Component<DataExplorerProps<T> & WithStyles<
         </Paper>;
     }
 
-    openContextMenu = (event: React.MouseEvent<HTMLElement>, item: T) => {
-        event.preventDefault();
-        this.setState({
-            contextMenu: {
-                anchorEl: mockAnchorFromMouseEvent(event),
-                item
-            }
-        });
-    }
-
-    closeContextMenu = () => {
-        this.setState({ contextMenu: {} });
-    }
-
-    callAction = (action: ContextMenuAction) => {
-        const { item } = this.state.contextMenu;
-        this.closeContextMenu();
-        if (item) {
-            this.props.onContextAction(action, item);
-        }
-    }
-
     changePage = (event: React.MouseEvent<HTMLButtonElement> | null, page: number) => {
         this.props.onChangePage(page);
     }
@@ -120,7 +83,7 @@ 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.props.onContextMenu(event, item)}>
                 <MoreVertIcon />
             </IconButton>
         </Grid>
@@ -130,7 +93,8 @@ class DataExplorer<T> extends React.Component<DataExplorerProps<T> & WithStyles<
         selected: true,
         key: "context-actions",
         renderHeader: () => null,
-        render: this.renderContextMenuTrigger
+        render: this.renderContextMenuTrigger,
+        width: "auto"
     };
 
 }
