X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/732294bc8aeafde5e85a4437cbd36b0d2648b04e..00a61a4484185dc98daa92af5f189779cc10ad3c:/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 7acc1a83..d7abde7b 100644
--- a/src/components/data-explorer/data-explorer.tsx
+++ b/src/components/data-explorer/data-explorer.tsx
@@ -3,18 +3,16 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from 'react';
-import { Grid, Paper, Toolbar, StyleRulesCallback, withStyles, WithStyles, TablePagination, IconButton } from '@material-ui/core';
+import { Grid, Paper, Toolbar, StyleRulesCallback, withStyles, WithStyles, TablePagination, IconButton, Tooltip } from '@material-ui/core';
 import MoreVertIcon from "@material-ui/icons/MoreVert";
 import { ColumnSelector } from "../column-selector/column-selector";
 import { DataTable, DataColumns } from "../data-table/data-table";
-import { DataColumn } from "../data-table/data-column";
+import { DataColumn, SortDirection } from "../data-table/data-column";
 import { DataTableFilterItem } from '../data-table-filters/data-table-filters';
 import { SearchInput } from '../search-input/search-input';
-import { ArvadosTheme } from "../../common/custom-theme";
-import { DefaultView } from '../default-view/default-view';
-import { IconType } from '../icon/icon';
+import { ArvadosTheme } from "~/common/custom-theme";
 
-type CssRules = 'searchBox' | "toolbar" | 'defaultRoot' | 'defaultMessage' | 'defaultIcon';
+type CssRules = 'searchBox' | "toolbar" | "root";
 
 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     searchBox: {
@@ -23,18 +21,8 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     toolbar: {
         paddingTop: theme.spacing.unit * 2
     },
-    defaultRoot: {
-        position: 'absolute',
-        width: '80%',
-        left: '50%',
-        top: '50%',
-        transform: 'translate(-50%, -50%)'
-    },
-    defaultMessage: {
-        fontSize: '1.75rem',
-    },
-    defaultIcon: {
-        fontSize: '6rem'
+    root: {
+        height: '100%'
     }
 });
 
@@ -46,11 +34,13 @@ interface DataExplorerDataProps<T> {
     rowsPerPage: number;
     rowsPerPageOptions: number[];
     page: number;
-    defaultIcon: IconType;
-    defaultMessages: string[];
+    contextMenuColumn: boolean;
+    dataTableDefaultView?: React.ReactNode;
+    working?: boolean;
 }
 
 interface DataExplorerActionProps<T> {
+    onSetColumns: (columns: DataColumns<T>) => void;
     onSearch: (value: string) => void;
     onRowClick: (item: T) => void;
     onRowDoubleClick: (item: T) => void;
@@ -67,58 +57,56 @@ type DataExplorerProps<T> = DataExplorerDataProps<T> & DataExplorerActionProps<T
 
 export const DataExplorer = withStyles(styles)(
     class DataExplorerGeneric<T> extends React.Component<DataExplorerProps<T>> {
+        componentDidMount() {
+            if (this.props.onSetColumns) {
+                this.props.onSetColumns(this.props.columns);
+            }
+        }
         render() {
-            const { 
-                columns, onContextMenu, onFiltersChange, onSortToggle, extractKey, 
-                rowsPerPage, rowsPerPageOptions, onColumnToggle, searchValue, onSearch, 
-                items, itemsAvailable, onRowClick, onRowDoubleClick, defaultIcon, defaultMessages, classes 
+            const {
+                columns, onContextMenu, onFiltersChange, onSortToggle, working, extractKey,
+                rowsPerPage, rowsPerPageOptions, onColumnToggle, searchValue, onSearch,
+                items, itemsAvailable, onRowClick, onRowDoubleClick, classes,
+                dataTableDefaultView
             } = this.props;
-            return <div>
-                { items.length > 0 ? (
-                    <Paper>
-                        <Toolbar className={classes.toolbar}>
-                            <Grid container justify="space-between" wrap="nowrap" alignItems="center">
-                                <div className={classes.searchBox}>
-                                    <SearchInput
-                                        value={searchValue}
-                                        onSearch={onSearch}/>
-                                </div>
-                                <ColumnSelector
-                                    columns={columns}
-                                    onColumnToggle={onColumnToggle}/>
-                            </Grid>
-                        </Toolbar>
-                        <DataTable
-                            columns={[...columns, this.contextMenuColumn]}
-                            items={items}
-                            onRowClick={(_, item: T) => onRowClick(item)}
-                            onContextMenu={onContextMenu}
-                            onRowDoubleClick={(_, item: T) => onRowDoubleClick(item)}
-                            onFiltersChange={onFiltersChange}
-                            onSortToggle={onSortToggle}
-                            extractKey={extractKey}/>
-                        <Toolbar>
-                            <Grid container justify="flex-end">
-                                <TablePagination
-                                    count={itemsAvailable}
-                                    rowsPerPage={rowsPerPage}
-                                    rowsPerPageOptions={rowsPerPageOptions}
-                                    page={this.props.page}
-                                    onChangePage={this.changePage}
-                                    onChangeRowsPerPage={this.changeRowsPerPage}
-                                    component="div" />
-                            </Grid>
-                        </Toolbar>
-                    </Paper>
-                ) : (
-                    <DefaultView 
-                        classRoot={classes.defaultRoot}
-                        icon={defaultIcon}
-                        classIcon={classes.defaultIcon}
-                        messages={defaultMessages}
-                        classMessage={classes.defaultMessage} />
-                )}
-            </div>;
+            return <Paper className={classes.root}>
+                <Toolbar className={classes.toolbar}>
+                    <Grid container justify="space-between" wrap="nowrap" alignItems="center">
+                        <div className={classes.searchBox}>
+                            <SearchInput
+                                value={searchValue}
+                                onSearch={onSearch} />
+                        </div>
+                        <ColumnSelector
+                            columns={columns}
+                            onColumnToggle={onColumnToggle} />
+                    </Grid>
+                </Toolbar>
+                <DataTable
+                    columns={this.props.contextMenuColumn ? [...columns, this.contextMenuColumn] : columns}
+                    items={items}
+                    onRowClick={(_, item: T) => onRowClick(item)}
+                    onContextMenu={onContextMenu}
+                    onRowDoubleClick={(_, item: T) => onRowDoubleClick(item)}
+                    onFiltersChange={onFiltersChange}
+                    onSortToggle={onSortToggle}
+                    extractKey={extractKey}
+                    working={working}
+                    defaultView={dataTableDefaultView}
+                />
+                <Toolbar>
+                    <Grid container justify="flex-end">
+                        <TablePagination
+                            count={itemsAvailable}
+                            rowsPerPage={rowsPerPage}
+                            rowsPerPageOptions={rowsPerPageOptions}
+                            page={this.props.page}
+                            onChangePage={this.changePage}
+                            onChangeRowsPerPage={this.changeRowsPerPage}
+                            component="div" />
+                    </Grid>
+                </Toolbar>
+            </Paper>;
         }
 
         changePage = (event: React.MouseEvent<HTMLButtonElement>, page: number) => {
@@ -131,18 +119,21 @@ export const DataExplorer = withStyles(styles)(
 
         renderContextMenuTrigger = (item: T) =>
             <Grid container justify="flex-end">
-                <IconButton onClick={event => this.props.onContextMenu(event, item)}>
-                    <MoreVertIcon/>
-                </IconButton>
+                <Tooltip title="More options">
+                    <IconButton onClick={event => this.props.onContextMenu(event, item)}>
+                        <MoreVertIcon />
+                    </IconButton>
+                </Tooltip>
             </Grid>
 
-        contextMenuColumn = {
+        contextMenuColumn: DataColumn<any> = {
             name: "Actions",
             selected: true,
             configurable: false,
+            sortDirection: SortDirection.NONE,
+            filters: [],
             key: "context-actions",
-            render: this.renderContextMenuTrigger,
-            width: "auto"
+            render: this.renderContextMenuTrigger
         };
     }
 );
