18549: Layout fixed, tests updated
[arvados-workbench2.git] / src / components / data-explorer / data-explorer.tsx
index a38d0ed65ae3c03eb9affdd76a67cf423b2fbd60..051f5d34a6ef45ebc33d1cbcbbab5e1815b05184 100644 (file)
@@ -11,34 +11,45 @@ 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 { CloseIcon, MaximizeIcon, MoreOptionsIcon } from 'components/icon/icon';
 import { PaperProps } from '@material-ui/core/Paper';
+import { MPVPanelProps } from 'components/multi-panel-view/multi-panel-view';
 
-type CssRules = 'searchBox' | "toolbar" | "toolbarUnderTitle" | "footer" | "root" | 'moreOptionsButton' | 'title';
+type CssRules = 'searchBox' | 'headerMenu' | "toolbar" | "footer" | "root" | 'moreOptionsButton' | 'title' | 'dataTable' | 'container';
 
 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     searchBox: {
         paddingBottom: theme.spacing.unit * 2
     },
     toolbar: {
-        paddingTop: theme.spacing.unit * 2
-    },
-    toolbarUnderTitle: {
-        paddingTop: 0
+        paddingTop: theme.spacing.unit,
+        paddingRight: theme.spacing.unit * 2,
     },
     footer: {
         overflow: 'auto'
     },
     root: {
-        height: '100%'
+        height: '100%',
     },
     moreOptionsButton: {
         padding: 0
     },
     title: {
+        display: 'inline-block',
         paddingLeft: theme.spacing.unit * 3,
         paddingTop: theme.spacing.unit * 3,
         fontSize: '18px'
+    },
+    dataTable: {
+        height: '100%',
+        overflow: 'auto',
+    },
+    container: {
+        height: '100%',
+    },
+    headerMenu: {
+        float: 'right',
+        display: 'inline-block'
     }
 });
 
@@ -62,6 +73,7 @@ interface DataExplorerDataProps<T> {
     title?: React.ReactNode;
     paperKey?: string;
     currentItemUuid: string;
+    elementPath?: string;
 }
 
 interface DataExplorerActionProps<T> {
@@ -79,40 +91,63 @@ interface DataExplorerActionProps<T> {
     extractKey?: (item: T) => React.Key;
 }
 
-type DataExplorerProps<T> = DataExplorerDataProps<T> & DataExplorerActionProps<T> & WithStyles<CssRules>;
+type DataExplorerProps<T> = DataExplorerDataProps<T> &
+    DataExplorerActionProps<T> & WithStyles<CssRules> & MPVPanelProps;
 
 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, working, extractKey,
                 rowsPerPage, rowsPerPageOptions, onColumnToggle, searchLabel, searchValue, onSearch,
                 items, itemsAvailable, onRowClick, onRowDoubleClick, classes,
                 dataTableDefaultView, hideColumnSelector, actions, paperProps, hideSearchInput,
-                paperKey, fetchMode, currentItemUuid, title
+                paperKey, fetchMode, currentItemUuid, title,
+                doHidePanel, doMaximizePanel, panelName, panelMaximized, elementPath
             } = this.props;
-            return <Paper className={classes.root} {...paperProps} key={paperKey}>
-                {title && <div className={classes.title}>{title}</div>}
-                {(!hideColumnSelector || !hideSearchInput) && <Toolbar className={title ? classes.toolbarUnderTitle : classes.toolbar}>
-                    <Grid container justify="space-between" wrap="nowrap" alignItems="center">
-                        <div className={classes.searchBox}>
-                            {!hideSearchInput && <SearchInput
-                                label={searchLabel}
-                                value={searchValue}
-                                onSearch={onSearch} />}
-                        </div>
-                        {actions}
-                        {!hideColumnSelector && <ColumnSelector
-                            columns={columns}
-                            onColumnToggle={onColumnToggle} />}
-                    </Grid>
-                </Toolbar>}
-                <DataTable
+
+            const dataCy = this.props["data-cy"];
+            return <Paper className={classes.root} {...paperProps} key={paperKey} data-cy={dataCy}>
+                <Grid container direction="column" wrap="nowrap" className={classes.container}>
+                    <div>
+                        {title && <Grid item xs className={classes.title}>{title}</Grid>}
+                        {
+                            (!hideColumnSelector || !hideSearchInput || !!actions) &&
+                            <Grid className={classes.headerMenu} item xs>
+                                <Toolbar className={classes.toolbar}>
+                                    <Grid container justify="space-between" wrap="nowrap" alignItems="center">
+                                        {!hideSearchInput && <div className={classes.searchBox}>
+                                            {!hideSearchInput && <SearchInput
+                                                label={searchLabel}
+                                                value={searchValue}
+                                                selfClearProp={currentItemUuid}
+                                                onSearch={onSearch} />}
+                                        </div>}
+                                        {actions}
+                                        {!hideColumnSelector && <ColumnSelector
+                                            columns={columns}
+                                            onColumnToggle={onColumnToggle} />}
+                                    </Grid>
+                                    { doMaximizePanel && !panelMaximized &&
+                                        <Tooltip title={`Maximize ${panelName || 'panel'}`} disableFocusListener>
+                                            <IconButton onClick={doMaximizePanel}><MaximizeIcon /></IconButton>
+                                        </Tooltip> }
+                                    { doHidePanel &&
+                                        <Tooltip title={`Close ${panelName || 'panel'}`} disableFocusListener>
+                                            <IconButton onClick={doHidePanel}><CloseIcon /></IconButton>
+                                        </Tooltip> }
+                                </Toolbar>
+                            </Grid>
+                        }
+                    </div>
+                <Grid item xs="auto" className={classes.dataTable}><DataTable
                     columns={this.props.contextMenuColumn ? [...columns, this.contextMenuColumn] : columns}
                     items={items}
                     onRowClick={(_, item: T) => onRowClick(item)}
@@ -124,9 +159,17 @@ export const DataExplorer = withStyles(styles)(
                     working={working}
                     defaultView={dataTableDefaultView}
                     currentItemUuid={currentItemUuid}
-                    currentRoute={paperKey} />
-                <Toolbar className={classes.footer}>
-                    <Grid container justify="flex-end">
+                    currentRoute={paperKey} /></Grid>
+                <Grid item xs><Toolbar className={classes.footer}>
+                    {
+                        elementPath &&
+                        <Grid container>
+                            <span data-cy="element-path">
+                                {elementPath}
+                            </span>
+                        </Grid>
+                    }
+                    <Grid container={!elementPath} justify="flex-end">
                         {fetchMode === DataTableFetchMode.PAGINATED ? <TablePagination
                             count={itemsAvailable}
                             rowsPerPage={rowsPerPage}
@@ -134,13 +177,16 @@ export const DataExplorer = withStyles(styles)(
                             page={this.props.page}
                             onChangePage={this.changePage}
                             onChangeRowsPerPage={this.changeRowsPerPage}
+                            // Disable next button on empty lists since that's not default behavior
+                            nextIconButtonProps={(itemsAvailable > 0) ? {} : {disabled: true}}
                             component="div" /> : <Button
                                 variant="text"
                                 size="medium"
                                 onClick={this.loadMore}
                             >Load more</Button>}
                     </Grid>
-                </Toolbar>
+                </Toolbar></Grid>
+                </Grid>
             </Paper>;
         }