X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/d1fa1c888be0d956178cc29cd78dbb924a7606c1..993c6c511af30163a2826d6992720b6be397943b:/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 2bff28cb..6779bc35 100644 --- a/src/components/multi-panel-view/multi-panel-view.tsx +++ b/src/components/multi-panel-view/multi-panel-view.tsx @@ -15,7 +15,7 @@ import { import { GridProps } from '@material-ui/core/Grid'; import { isArray } from 'lodash'; import { DefaultView } from 'components/default-view/default-view'; -import { InfoIcon, InvisibleIcon, VisibleIcon } from 'components/icon/icon'; +import { InfoIcon } from 'components/icon/icon'; import { ReactNodeArray } from 'prop-types'; import classNames from 'classnames'; @@ -33,7 +33,6 @@ const styles: StyleRulesCallback = theme => ({ }, content: { overflow: 'auto', - display: 'contents', }, }); @@ -49,14 +48,15 @@ interface MPVHideablePanelDataProps { interface MPVHideablePanelActionProps { doHidePanel: () => void; doMaximizePanel: () => void; + doUnMaximizePanel: () => void; } type MPVHideablePanelProps = MPVHideablePanelDataProps & MPVHideablePanelActionProps; -const MPVHideablePanel = ({doHidePanel, doMaximizePanel, name, visible, maximized, illuminated, ...props}: MPVHideablePanelProps) => +const MPVHideablePanel = ({doHidePanel, doMaximizePanel, doUnMaximizePanel, name, visible, maximized, illuminated, ...props}: MPVHideablePanelProps) => visible ? <> - {React.cloneElement((props.children as ReactElement), { doHidePanel, doMaximizePanel, panelName: name, panelMaximized: maximized, panelIlluminated: illuminated, panelRef: props.panelRef })} + {React.cloneElement((props.children as ReactElement), { doHidePanel, doMaximizePanel, doUnMaximizePanel, panelName: name, panelMaximized: maximized, panelIlluminated: illuminated, panelRef: props.panelRef })} : null; @@ -72,6 +72,7 @@ interface MPVPanelDataProps { interface MPVPanelActionProps { doHidePanel?: () => void; doMaximizePanel?: () => void; + doUnMaximizePanel?: () => void; } // Props received by panel implementors @@ -80,7 +81,7 @@ 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, +export const MPVPanelContent = ({doHidePanel, doMaximizePanel, doUnMaximizePanel, panelName, panelMaximized, panelIlluminated, panelRef, forwardProps, maxHeight, ...props}: MPVPanelContentProps) => { useEffect(() => { @@ -97,7 +98,7 @@ export const MPVPanelContent = ({doHidePanel, doMaximizePanel, panelName, {/* Element to scroll to when the panel is selected */} { forwardProps - ? React.cloneElement(props.children, { doHidePanel, doMaximizePanel, panelName, panelMaximized }) + ? React.cloneElement(props.children, { doHidePanel, doMaximizePanel, doUnMaximizePanel, panelName, panelMaximized }) : props.children } ; @@ -119,27 +120,32 @@ const MPVContainerComponent = ({children, panelStates, classes, ...props}: MPVCo } else if (!isArray(children)) { children = [children]; } - const visibility = (children as ReactNodeArray).map((_, idx) => + const initialVisibility = (children as ReactNodeArray).map((_, idx) => !panelStates || // if panelStates wasn't passed, default to all visible panels (panelStates[idx] && (panelStates[idx].visible || panelStates[idx].visible === undefined))); - const [panelVisibility, setPanelVisibility] = useState(visibility); - const [brightenedPanel, setBrightenedPanel] = useState(-1); + const [panelVisibility, setPanelVisibility] = useState(initialVisibility); + const [previousPanelVisibility, setPreviousPanelVisibility] = useState(initialVisibility); + const [highlightedPanel, setHighlightedPanel] = useState(-1); + const [selectedPanel, setSelectedPanel] = useState(-1); const panelRef = useRef(null); let panels: JSX.Element[] = []; - let toggles: JSX.Element[] = []; + let buttons: JSX.Element[] = []; if (isArray(children)) { for (let idx = 0; idx < children.length; idx++) { const showFn = (idx: number) => () => { + setPreviousPanelVisibility(initialVisibility); setPanelVisibility([ ...panelVisibility.slice(0, idx), true, ...panelVisibility.slice(idx+1) ]); + setSelectedPanel(idx); }; const hideFn = (idx: number) => () => { + setPreviousPanelVisibility(initialVisibility); setPanelVisibility([ ...panelVisibility.slice(0, idx), false, @@ -147,52 +153,52 @@ const MPVContainerComponent = ({children, panelStates, classes, ...props}: MPVCo ]) }; const maximizeFn = (idx: number) => () => { + setPreviousPanelVisibility(panelVisibility); // Maximize X == hide all but X setPanelVisibility([ ...panelVisibility.slice(0, idx).map(() => false), true, ...panelVisibility.slice(idx+1).map(() => false), - ]) + ]); }; - const toggleIcon = panelVisibility[idx] - ? - : + const unMaximizeFn = (idx: number) => () => { + setPanelVisibility(previousPanelVisibility); + setSelectedPanel(idx); + } const panelName = panelStates === undefined ? `Panel ${idx+1}` : (panelStates[idx] && panelStates[idx].name) || `Panel ${idx+1}`; - const toggleVariant = "outlined"; - const toggleTooltip = panelVisibility[idx] - ? '' - :`Show ${panelName} panel`; + const btnVariant = panelVisibility[idx] + ? "contained" + : "outlined"; + const btnTooltip = panelVisibility[idx] + ? `` + :`Open ${panelName} panel`; const panelIsMaximized = panelVisibility[idx] && panelVisibility.filter(e => e).length === 1; - let brightenerTimer: NodeJS.Timer; - toggles = [ - ...toggles, - - ]; const aPanel = + panelRef={(idx === selectedPanel) ? panelRef : undefined} + maximized={panelIsMaximized} illuminated={idx === highlightedPanel} + doHidePanel={hideFn(idx)} doMaximizePanel={maximizeFn(idx)} doUnMaximizePanel={panelIsMaximized ? unMaximizeFn(idx) : () => null}> {children[idx]} ; panels = [...panels, aPanel]; @@ -201,9 +207,10 @@ const MPVContainerComponent = ({children, panelStates, classes, ...props}: MPVCo return - { toggles.map((tgl, idx) => {tgl}) } + { buttons.map((tgl, idx) => {tgl}) } - + setSelectedPanel(-1)}> { panelVisibility.includes(true) ? panels :