X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/9f1850a385ee8e0a011474de19ee6507b0b168f3..cb690390d4f253c3bbb9c543e243cf988f39fbb3:/services/workbench2/src/views/workbench/workbench.tsx diff --git a/services/workbench2/src/views/workbench/workbench.tsx b/services/workbench2/src/views/workbench/workbench.tsx index b094b769cb..3020e0d298 100644 --- a/services/workbench2/src/views/workbench/workbench.tsx +++ b/services/workbench2/src/views/workbench/workbench.tsx @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: AGPL-3.0 -import React from "react"; +import React, { useEffect, useState } 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"; @@ -150,6 +150,8 @@ interface WorkbenchDataProps { isNotLinking: boolean; sessionIdleTimeout: number; sidePanelIsCollapsed: boolean; + isTransitioning: boolean; + currentSideWidth: number; } type WorkbenchPanelProps = WithStyles & WorkbenchDataProps; @@ -292,38 +294,55 @@ routes = React.createElement( pluginConfig.centerPanelList.reduce(reduceRoutesFn, React.Children.toArray(routes.props.children)) ); -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 ? `calc(${rightPanelExpandedWidth}% - 1rem)` : `${getSplitterInitialSize()}%`}`); - } - const splitter = document.getElementsByClassName("layout-splitter")[0]; - isCollapsed ? splitter?.classList.add("layout-splitter-disabled") : splitter?.classList.remove("layout-splitter-disabled"); -}; - export const WorkbenchPanel = withStyles(styles)((props: WorkbenchPanelProps) => { - //panel size will not scale automatically on window resize, so we do it manually - if (props && props.sidePanelIsCollapsed) window.addEventListener("resize", () => applyCollapsedState(props.sidePanelIsCollapsed)); - applyCollapsedState(props.sidePanelIsCollapsed); +const { classes, sidePanelIsCollapsed, isNotLinking, isTransitioning, isUserActive, sessionIdleTimeout, currentSideWidth } = props + + const applyCollapsedState = (savedWidthInPx) => { + const rightPanel: Element = document.getElementsByClassName("layout-pane")[1]; + const totalWidth: number = document.getElementsByClassName("splitter-layout")[0]?.clientWidth; + const savedWidthInPercent = (savedWidthInPx / totalWidth) * 100 + const rightPanelExpandedWidth = (totalWidth - COLLAPSE_ICON_SIZE) / (totalWidth / 100); + + if(isTransitioning && !!rightPanel) { + rightPanel.setAttribute('style', `width: ${sidePanelIsCollapsed ? `calc(${savedWidthInPercent}% - 1rem)` : `${getSplitterInitialSize()}%`};`) + } + + if (rightPanel) { + rightPanel.setAttribute("style", `width: ${sidePanelIsCollapsed ? `calc(${rightPanelExpandedWidth}% - 1rem)` : `${getSplitterInitialSize()}%`};`); + } + const splitter = document.getElementsByClassName("layout-splitter")[0]; + sidePanelIsCollapsed ? splitter?.classList.add("layout-splitter-disabled") : splitter?.classList.remove("layout-splitter-disabled"); + }; + + const [savedWidth, setSavedWidth] = useState(0) + + useEffect(()=>{ + if (isTransitioning) setSavedWidth(currentSideWidth) + }, [isTransitioning, currentSideWidth]) + + useEffect(()=>{ + if (isTransitioning) applyCollapsedState(savedWidth); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [isTransitioning, savedWidth]) + + applyCollapsedState(savedWidth); return ( - {props.sessionIdleTimeout > 0 && } + {sessionIdleTimeout > 0 && } secondaryMinSize={40} onSecondaryPaneSizeChange={saveSplitterSize} > - {props.isUserActive && props.isNotLinking && ( + {isUserActive && isNotLinking && ( @@ -349,18 +368,18 @@ export const WorkbenchPanel = withStyles(styles)((props: WorkbenchPanelProps) => xs component="main" direction="column" - className={props.classes.contentWrapper} + className={classes.contentWrapper} > - {props.isNotLinking && } + {isNotLinking && } {routes.props.children}