X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/394ebdfd13fe40a7096f484c46a353d2537f4c9a..b469528b5aeb65fc8ce891db28ae20183a141aa2:/src/components/multi-panel-view/multi-panel-view.tsx

diff --git a/src/components/multi-panel-view/multi-panel-view.tsx b/src/components/multi-panel-view/multi-panel-view.tsx
index dbb37921..507b30ab 100644
--- a/src/components/multi-panel-view/multi-panel-view.tsx
+++ b/src/components/multi-panel-view/multi-panel-view.tsx
@@ -64,6 +64,8 @@ interface MPVPanelDataProps {
     panelMaximized?: boolean;
     panelIlluminated?: boolean;
     panelRef?: MutableRefObject<any>;
+    forwardProps?: boolean;
+    maxHeight?: string;
 }
 
 interface MPVPanelActionProps {
@@ -77,17 +79,25 @@ export type MPVPanelProps = MPVPanelDataProps & MPVPanelActionProps;
 type MPVPanelContentProps = {children: ReactElement} & MPVPanelProps & GridProps;
 
 // Grid item compatible component for layout and MPV props passing
-export const MPVPanelContent = ({doHidePanel, doMaximizePanel, panelName, panelMaximized, panelIlluminated, panelRef, ...props}: MPVPanelContentProps) => {
+export const MPVPanelContent = ({doHidePanel, doMaximizePanel, panelName,
+    panelMaximized, panelIlluminated, panelRef, forwardProps, maxHeight,
+    ...props}: MPVPanelContentProps) => {
     useEffect(() => {
         if (panelRef && panelRef.current) {
             panelRef.current.scrollIntoView({behavior: 'smooth'});
         }
     }, [panelRef]);
 
-    return <Grid item {...props}>
+    const mh = panelMaximized
+        ? '100%'
+        : maxHeight;
+
+    return <Grid item style={{maxHeight: mh}} {...props}>
         <span ref={panelRef} /> {/* Element to scroll to when the panel is selected */}
         <Paper style={{height: '100%'}} elevation={panelIlluminated ? 8 : 0}>
-            {React.cloneElement(props.children, { doHidePanel, doMaximizePanel, panelName, panelMaximized })}
+            { forwardProps
+                ? React.cloneElement(props.children, { doHidePanel, doMaximizePanel, panelName, panelMaximized })
+                : props.children }
         </Paper>
     </Grid>;
 }
@@ -109,11 +119,12 @@ const MPVContainerComponent = ({children, panelStates, classes, ...props}: MPVCo
         children = [children];
     }
     const visibility = (children as ReactNodeArray).map((_, idx) =>
-        !!!panelStates || // if panelStates wasn't passed, default to all visible panels
+        !panelStates || // if panelStates wasn't passed, default to all visible panels
             (panelStates[idx] &&
                 (panelStates[idx].visible || panelStates[idx].visible === undefined)));
     const [panelVisibility, setPanelVisibility] = useState<boolean[]>(visibility);
     const [brightenedPanel, setBrightenedPanel] = useState<number>(-1);
+    const [selectedPanel, setSelectedPanel] = useState<number>(-1);
     const panelRef = useRef<any>(null);
 
     let panels: JSX.Element[] = [];
@@ -127,6 +138,7 @@ const MPVContainerComponent = ({children, panelStates, classes, ...props}: MPVCo
                     true,
                     ...panelVisibility.slice(idx+1)
                 ]);
+                setSelectedPanel(idx);
             };
             const hideFn = (idx: number) => () => {
                 setPanelVisibility([
@@ -149,8 +161,8 @@ const MPVContainerComponent = ({children, panelStates, classes, ...props}: MPVCo
             const panelName = panelStates === undefined
                 ? `Panel ${idx+1}`
                 : (panelStates[idx] && panelStates[idx].name) || `Panel ${idx+1}`;
-            const toggleVariant = "outlined";
-            const toggleTooltip = panelVisibility[idx]
+            const btnVariant = "outlined";
+            const btnTooltip = panelVisibility[idx]
                 ? ''
                 :`Show ${panelName} panel`;
             const panelIsMaximized = panelVisibility[idx] &&
@@ -158,11 +170,15 @@ const MPVContainerComponent = ({children, panelStates, classes, ...props}: MPVCo
 
             toggles = [
                 ...toggles,
-                <Tooltip title={toggleTooltip} disableFocusListener>
-                    <Button variant={toggleVariant} size="small" color="primary"
+                <Tooltip title={btnTooltip} disableFocusListener>
+                    <Button variant={btnVariant} size="small" color="primary"
                         className={classNames(classes.button)}
-                        onMouseEnter={() => setBrightenedPanel(idx)}
-                        onMouseLeave={() => setBrightenedPanel(-1)}
+                        onMouseEnter={() => {
+                            setBrightenedPanel(idx);
+                        }}
+                        onMouseLeave={() => {
+                            setBrightenedPanel(-1);
+                        }}
                         onClick={showFn(idx)}>
                             {panelName}
                             {toggleIcon}
@@ -172,7 +188,7 @@ const MPVContainerComponent = ({children, panelStates, classes, ...props}: MPVCo
 
             const aPanel =
                 <MPVHideablePanel key={idx} visible={panelVisibility[idx]} name={panelName}
-                    panelRef={(idx === brightenedPanel) ? panelRef : undefined}
+                    panelRef={(idx === selectedPanel) ? panelRef : undefined}
                     maximized={panelIsMaximized} illuminated={idx === brightenedPanel}
                     doHidePanel={hideFn(idx)} doMaximizePanel={maximizeFn(idx)}>
                     {children[idx]}
