X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/837e79c83399108aa0492f163205edb952f0ab71..a5cc3b71b39f304f15c03b175e541b5adf4541f7:/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 58507fb0..7c1f9045 100644
--- a/src/components/data-explorer/data-explorer.tsx
+++ b/src/components/data-explorer/data-explorer.tsx
@@ -3,16 +3,18 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from 'react';
-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, SortDirection } from "../data-table/data-column";
-import { DataTableFilterItem } from '../data-table-filters/data-table-filters';
-import { SearchInput } from '../search-input/search-input';
+import { Grid, Paper, Toolbar, StyleRulesCallback, withStyles, WithStyles, TablePagination, IconButton, Tooltip, Button } from '@material-ui/core';
+import { ColumnSelector } from "~/components/column-selector/column-selector";
+import { DataTable, DataColumns, DataTableFetchMode } from "~/components/data-table/data-table";
+import { DataColumn } from "~/components/data-table/data-column";
+import { SearchInput } from '~/components/search-input/search-input';
 import { ArvadosTheme } from "~/common/custom-theme";
+import { createTree } from '~/models/tree';
+import { DataTableFilters } from '~/components/data-table-filters/data-table-filters-tree';
+import { MoreOptionsIcon } from '~/components/icon/icon';
+import { PaperProps } from '@material-ui/core/Paper';
 
-type CssRules = 'searchBox' | "toolbar";
+type CssRules = 'searchBox' | "toolbar" | "footer" | "root" | 'moreOptionsButton';
 
 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     searchBox: {
@@ -21,9 +23,19 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     toolbar: {
         paddingTop: theme.spacing.unit * 2
     },
+    footer: {
+        overflow: 'auto'
+    },
+    root: {
+        height: '100%'
+    },
+    moreOptionsButton: {
+        padding: 0
+    }
 });
 
 interface DataExplorerDataProps<T> {
+    fetchMode: DataTableFetchMode;
     items: T[];
     itemsAvailable: number;
     columns: DataColumns<T>;
@@ -33,6 +45,13 @@ interface DataExplorerDataProps<T> {
     page: number;
     contextMenuColumn: boolean;
     dataTableDefaultView?: React.ReactNode;
+    working?: boolean;
+    hideColumnSelector?: boolean;
+    paperProps?: PaperProps;
+    actions?: React.ReactNode;
+    hideSearchInput?: boolean;
+    paperKey?: string;
+    currentItemUuid: string;
 }
 
 interface DataExplorerActionProps<T> {
@@ -43,9 +62,10 @@ interface DataExplorerActionProps<T> {
     onColumnToggle: (column: DataColumn<T>) => void;
     onContextMenu: (event: React.MouseEvent<HTMLElement>, item: T) => void;
     onSortToggle: (column: DataColumn<T>) => void;
-    onFiltersChange: (filters: DataTableFilterItem[], column: DataColumn<T>) => void;
+    onFiltersChange: (filters: DataTableFilters, column: DataColumn<T>) => void;
     onChangePage: (page: number) => void;
     onChangeRowsPerPage: (rowsPerPage: number) => void;
+    onLoadMore: (page: number) => void;
     extractKey?: (item: T) => React.Key;
 }
 
@@ -60,24 +80,26 @@ export const DataExplorer = withStyles(styles)(
         }
         render() {
             const {
-                columns, onContextMenu, onFiltersChange, onSortToggle, extractKey,
+                columns, onContextMenu, onFiltersChange, onSortToggle, working, extractKey,
                 rowsPerPage, rowsPerPageOptions, onColumnToggle, searchValue, onSearch,
                 items, itemsAvailable, onRowClick, onRowDoubleClick, classes,
-                dataTableDefaultView
+                dataTableDefaultView, hideColumnSelector, actions, paperProps, hideSearchInput,
+                paperKey, fetchMode, currentItemUuid
             } = this.props;
-            return <Paper>
-                <Toolbar className={classes.toolbar}>
+            return <Paper className={classes.root} {...paperProps} key={paperKey}>
+                {(!hideColumnSelector || !hideSearchInput) && <Toolbar className={classes.toolbar}>
                     <Grid container justify="space-between" wrap="nowrap" alignItems="center">
                         <div className={classes.searchBox}>
-                            <SearchInput
+                            {!hideSearchInput && <SearchInput
                                 value={searchValue}
-                                onSearch={onSearch} />
+                                onSearch={onSearch} />}
                         </div>
-                        <ColumnSelector
+                        {actions}
+                        {!hideColumnSelector && <ColumnSelector
                             columns={columns}
-                            onColumnToggle={onColumnToggle} />
+                            onColumnToggle={onColumnToggle} />}
                     </Grid>
-                </Toolbar>
+                </Toolbar>}
                 <DataTable
                     columns={this.props.contextMenuColumn ? [...columns, this.contextMenuColumn] : columns}
                     items={items}
@@ -87,18 +109,24 @@ export const DataExplorer = withStyles(styles)(
                     onFiltersChange={onFiltersChange}
                     onSortToggle={onSortToggle}
                     extractKey={extractKey}
+                    working={working}
                     defaultView={dataTableDefaultView}
-                />
-                <Toolbar>
+                    currentItemUuid={currentItemUuid}
+                    currentRoute={paperKey} />
+                <Toolbar className={classes.footer}>
                     <Grid container justify="flex-end">
-                        <TablePagination
+                        {fetchMode === DataTableFetchMode.PAGINATED ? <TablePagination
                             count={itemsAvailable}
                             rowsPerPage={rowsPerPage}
                             rowsPerPageOptions={rowsPerPageOptions}
                             page={this.props.page}
                             onChangePage={this.changePage}
                             onChangeRowsPerPage={this.changeRowsPerPage}
-                            component="div" />
+                            component="div" /> : <Button
+                                variant="text"
+                                size="medium"
+                                onClick={this.loadMore}
+                            >Load more</Button>}
                     </Grid>
                 </Toolbar>
             </Paper>;
@@ -112,21 +140,24 @@ export const DataExplorer = withStyles(styles)(
             this.props.onChangeRowsPerPage(parseInt(event.target.value, 10));
         }
 
+        loadMore = () => {
+            this.props.onLoadMore(this.props.page + 1);
+        }
+
         renderContextMenuTrigger = (item: T) =>
-            <Grid container justify="flex-end">
-                <IconButton onClick={event => this.props.onContextMenu(event, item)}>
-                    <Tooltip title="More options">
-                        <MoreVertIcon />
-                    </Tooltip>
-                </IconButton>
+            <Grid container justify="center">
+                <Tooltip title="More options" disableFocusListener>
+                    <IconButton className={this.props.classes.moreOptionsButton} onClick={event => this.props.onContextMenu(event, item)}>
+                        <MoreOptionsIcon />
+                    </IconButton>
+                </Tooltip>
             </Grid>
 
         contextMenuColumn: DataColumn<any> = {
             name: "Actions",
             selected: true,
             configurable: false,
-            sortDirection: SortDirection.NONE,
-            filters: [],
+            filters: createTree(),
             key: "context-actions",
             render: this.renderContextMenuTrigger
         };
