Merge branch '18972-all-procs-flickering-fix'. Closes #18972
[arvados-workbench2.git] / src / components / data-explorer / data-explorer.tsx
index 5f396bb4d0322eba1a032ce34a87e2f04943acec..0363d33399c1dc90299fd2a73f78ca8d22cb6c0b 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'
     }
 });
 
@@ -55,6 +66,8 @@ interface DataExplorerDataProps<T> {
     contextMenuColumn: boolean;
     dataTableDefaultView?: React.ReactNode;
     working?: boolean;
+    currentRefresh?: string;
+    currentRoute?: string;
     hideColumnSelector?: boolean;
     paperProps?: PaperProps;
     actions?: React.ReactNode;
@@ -62,6 +75,7 @@ interface DataExplorerDataProps<T> {
     title?: React.ReactNode;
     paperKey?: string;
     currentItemUuid: string;
+    elementPath?: string;
 }
 
 interface DataExplorerActionProps<T> {
@@ -79,49 +93,101 @@ 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>, { currentItemUuid: string }> {
-        constructor(props) {
-            super(props);
-            this.state = {
-                currentItemUuid: props.currentItemUuid
-            };
+    class DataExplorerGeneric<T> extends React.Component<DataExplorerProps<T>> {
+        state = {
+            showLoading: false,
+            prevRefresh: '',
+            prevRoute: '',
+        };
+
+        componentDidUpdate(prevProps: DataExplorerProps<T>) {
+            const currentRefresh = this.props.currentRefresh || '';
+            const currentRoute = this.props.currentRoute || '';
+
+            if (currentRoute !== this.state.prevRoute) {
+                // Component already mounted, but the user comes from a route change,
+                // like browsing through a project hierarchy.
+                this.setState({
+                    showLoading: this.props.working,
+                    prevRoute: currentRoute,
+                });
+            }
+
+            if (currentRefresh !== this.state.prevRefresh) {
+                // Component already mounted, but the user just clicked the
+                // refresh button.
+                this.setState({
+                    showLoading: this.props.working,
+                    prevRefresh: currentRefresh,
+                });
+            }
+            if (this.state.showLoading && !this.props.working) {
+                this.setState({
+                    showLoading: false,
+                });
+            }
         }
+
         componentDidMount() {
             if (this.props.onSetColumns) {
                 this.props.onSetColumns(this.props.columns);
             }
+            // Component just mounted, so we need to show the loading indicator.
+            this.setState({
+                showLoading: this.props.working,
+                prevRefresh: this.props.currentRefresh || '',
+                prevRoute: this.props.currentRoute || '',
+            });
         }
 
         render() {
             const {
-                columns, onContextMenu, onFiltersChange, onSortToggle, working, extractKey,
+                columns, onContextMenu, onFiltersChange, onSortToggle, 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}
-                                selfClearProp={currentItemUuid}
-                                onSearch={onSearch} />}
-                        </div>
-                        {actions}
-                        {!hideColumnSelector && <ColumnSelector
-                            columns={columns}
-                            onColumnToggle={onColumnToggle} />}
-                    </Grid>
-                </Toolbar>}
-                <DataTable
+            return <Paper className={classes.root} {...paperProps} key={paperKey} data-cy={this.props["data-cy"]}>
+                <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)}
@@ -130,12 +196,20 @@ export const DataExplorer = withStyles(styles)(
                     onFiltersChange={onFiltersChange}
                     onSortToggle={onSortToggle}
                     extractKey={extractKey}
-                    working={working}
+                    working={this.state.showLoading}
                     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}
@@ -151,7 +225,8 @@ export const DataExplorer = withStyles(styles)(
                                 onClick={this.loadMore}
                             >Load more</Button>}
                     </Grid>
-                </Toolbar>
+                </Toolbar></Grid>
+                </Grid>
             </Paper>;
         }