20424: Memoize process io card preview to reduce unnecessary re-renders
[arvados.git] / src / views / workbench / workbench.tsx
index ae8a8f842d16f505d2c2fae3b84af665e59a39b5..d549c52935136d42c6fb295b71269a5750a04c4a 100644 (file)
@@ -2,7 +2,7 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import React, { useState, useCallback } from 'react';
+import React from 'react';
 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
 import { Route, Switch } from "react-router";
 import { ProjectPanel } from "views/project-panel/project-panel";
@@ -41,6 +41,7 @@ import { SharedWithMePanel } from 'views/shared-with-me-panel/shared-with-me-pan
 import { RunProcessPanel } from 'views/run-process-panel/run-process-panel';
 import SplitterLayout from 'react-splitter-layout';
 import { WorkflowPanel } from 'views/workflow-panel/workflow-panel';
+import { RegisteredWorkflowPanel } from 'views/workflow-panel/registered-workflow-panel';
 import { SearchResultsPanel } from 'views/search-results-panel/search-results-panel';
 import { SshKeyPanel } from 'views/ssh-key-panel/ssh-key-panel';
 import { SshKeyAdminPanel } from 'views/ssh-key-panel/ssh-key-admin-panel';
@@ -99,6 +100,8 @@ import { RestoreCollectionVersionDialog } from 'views-components/collections-dia
 import { WebDavS3InfoDialog } from 'views-components/webdav-s3-dialog/webdav-s3-dialog';
 import { pluginConfig } from 'plugins';
 import { ElementListReducer } from 'common/plugintypes';
+import { COLLAPSE_ICON_SIZE } from 'views-components/side-panel-toggle/side-panel-toggle'
+import { Banner } from 'views-components/baner/banner';
 
 type CssRules = 'root' | 'container' | 'splitter' | 'asidePanel' | 'contentWrapper' | 'content';
 
@@ -112,7 +115,11 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     },
     splitter: {
         '& > .layout-splitter': {
-            width: '2px'
+            width: '2px',
+        },
+        '& > .layout-splitter-disabled': {
+            pointerEvents: 'none',
+            cursor: 'pointer'
         }
     },
     asidePanel: {
@@ -137,6 +144,7 @@ interface WorkbenchDataProps {
     isUserActive: boolean;
     isNotLinking: boolean;
     sessionIdleTimeout: number;
+    sidePanelIsCollapsed: boolean;
 }
 
 type WorkbenchPanelProps = WithStyles<CssRules> & WorkbenchDataProps;
@@ -159,6 +167,7 @@ let routes = <>
     <Route path={Routes.TRASH} component={TrashPanel} />
     <Route path={Routes.SHARED_WITH_ME} component={SharedWithMePanel} />
     <Route path={Routes.RUN_PROCESS} component={RunProcessPanel} />
+    <Route path={Routes.REGISTEREDWORKFLOW} component={RegisteredWorkflowPanel} />
     <Route path={Routes.WORKFLOWS} component={WorkflowPanel} />
     <Route path={Routes.SEARCH_RESULTS} component={SearchResultsPanel} />
     <Route path={Routes.VIRTUAL_MACHINES_USER} component={VirtualMachineUserPanel} />
@@ -185,21 +194,26 @@ const reduceRoutesFn: (a: React.ReactElement[],
 
 routes = React.createElement(React.Fragment, null, pluginConfig.centerPanelList.reduce(reduceRoutesFn, React.Children.toArray(routes.props.children)));
 
-const Banner = () => {
-    const [visible, setVisible] = useState(true);
-    const hideBanner = useCallback(() => setVisible(false), []);
+const applyCollapsedState = (isCollapsed) => {
+    const rightPanel: Element = document.getElementsByClassName('layout-pane')[1]
+    const totalWidth: number = document.getElementsByClassName('splitter-layout')[0]?.clientWidth
+    const rightPanelExpandedWidth = ((totalWidth - COLLAPSE_ICON_SIZE)) / (totalWidth / 100)
+    if (rightPanel) {
+        rightPanel.setAttribute('style', `width: ${isCollapsed ? rightPanelExpandedWidth : getSplitterInitialSize()}%`)
+    }
+    const splitter = document.getElementsByClassName('layout-splitter')[0]
+    isCollapsed ? splitter?.classList.add('layout-splitter-disabled') : splitter?.classList.remove('layout-splitter-disabled')
 
-    return visible ? 
-        <div id="banner" onClick={hideBanner} className="app-banner">
-            <span>
-            This is important message
-            </span>
-        </div> : null;
 }
 
 export const WorkbenchPanel =
-    withStyles(styles)((props: WorkbenchPanelProps) =>
-        <Grid container item xs className={props.classes.root}>
+    withStyles(styles)((props: WorkbenchPanelProps) => {
+
+        //panel size will not scale automatically on window resize, so we do it manually
+        window.addEventListener('resize', () => applyCollapsedState(props.sidePanelIsCollapsed))
+        applyCollapsedState(props.sidePanelIsCollapsed)
+
+        return <Grid container item xs className={props.classes.root}>
             {props.sessionIdleTimeout > 0 && <AutoLogout />}
             <Grid container item xs className={props.classes.container}>
                 <SplitterLayout customClassName={props.classes.splitter} percentage={true}
@@ -285,4 +299,5 @@ export const WorkbenchPanel =
             <Banner />
             {React.createElement(React.Fragment, null, pluginConfig.dialogs)}
         </Grid>
+    }
     );