X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/3d5a1c29aad86476f2e789e1e54cabf8b4605aa2..10e1abd9cfb8f5cc11659c7961b9d83cf5b9a8b8:/services/workbench2/src/components/multi-panel-view/multi-panel-view.tsx diff --git a/services/workbench2/src/components/multi-panel-view/multi-panel-view.tsx b/services/workbench2/src/components/multi-panel-view/multi-panel-view.tsx index 203748d5e0..69e2b7015e 100644 --- a/services/workbench2/src/components/multi-panel-view/multi-panel-view.tsx +++ b/services/workbench2/src/components/multi-panel-view/multi-panel-view.tsx @@ -8,6 +8,8 @@ import { Grid, Paper, StyleRulesCallback, + Tab, + Tabs, Tooltip, withStyles, WithStyles @@ -19,7 +21,7 @@ import { InfoIcon } from 'components/icon/icon'; import { ReactNodeArray } from 'prop-types'; import classNames from 'classnames'; -type CssRules = 'root' | 'button' | 'buttonIcon' | 'content'; +type CssRules = 'root' | 'button' | 'buttonIcon' | 'content' | 'tabsWrapper' | 'tabsRoot' | 'tabs'; const styles: StyleRulesCallback = theme => ({ root: { @@ -36,6 +38,18 @@ const styles: StyleRulesCallback = theme => ({ }, content: { overflow: 'auto', + maxWidth: 'initial', + }, + tabsWrapper: { + width: '100%', + }, + tabsRoot: { + flexGrow: 1, + }, + tabs: { + flexGrow: 1, + flexShrink: 1, + maxWidth: 'initial', }, }); @@ -56,12 +70,12 @@ interface MPVHideablePanelActionProps { type MPVHideablePanelProps = MPVHideablePanelDataProps & MPVHideablePanelActionProps; -const MPVHideablePanel = ({doHidePanel, doMaximizePanel, doUnMaximizePanel, 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, doUnMaximizePanel, panelName: name, panelMaximized: maximized, panelIlluminated: illuminated, panelRef: props.panelRef })} - - : null; + ? <> + {React.cloneElement((props.children as ReactElement), { doHidePanel, doMaximizePanel, doUnMaximizePanel, panelName: name, panelMaximized: maximized, panelIlluminated: illuminated, panelRef: props.panelRef })} + + : null; interface MPVPanelDataProps { panelName?: string; @@ -82,15 +96,15 @@ interface MPVPanelActionProps { // Props received by panel implementors export type MPVPanelProps = MPVPanelDataProps & MPVPanelActionProps; -type MPVPanelContentProps = {children: ReactElement} & MPVPanelProps & GridProps; +type MPVPanelContentProps = { children: ReactElement } & MPVPanelProps & GridProps; // Grid item compatible component for layout and MPV props passing -export const MPVPanelContent = ({doHidePanel, doMaximizePanel, doUnMaximizePanel, panelName, +export const MPVPanelContent = ({ doHidePanel, doMaximizePanel, doUnMaximizePanel, panelName, panelMaximized, panelIlluminated, panelRef, forwardProps, maxHeight, minHeight, - ...props}: MPVPanelContentProps) => { + ...props }: MPVPanelContentProps) => { useEffect(() => { if (panelRef && panelRef.current) { - panelRef.current.scrollIntoView({alignToTop: true}); + panelRef.current.scrollIntoView({ alignToTop: true }); } }, [panelRef]); @@ -98,12 +112,12 @@ export const MPVPanelContent = ({doHidePanel, doMaximizePanel, doUnMaximizePanel ? '100%' : maxHeight; - return + return {/* Element to scroll to when the panel is selected */} - - { forwardProps + + {forwardProps ? React.cloneElement(props.children, { doHidePanel, doMaximizePanel, doUnMaximizePanel, panelName, panelMaximized }) - : props.children } + : props.children} ; } @@ -114,11 +128,12 @@ export interface MPVPanelState { } interface MPVContainerDataProps { panelStates?: MPVPanelState[]; + mutuallyExclusive?: boolean; } type MPVContainerProps = MPVContainerDataProps & GridProps; // Grid container compatible component that also handles panel toggling. -const MPVContainerComponent = ({children, panelStates, classes, ...props}: MPVContainerProps & WithStyles) => { +const MPVContainerComponent = ({ children, panelStates, classes, ...props }: MPVContainerProps & WithStyles) => { if (children === undefined || children === null || children === {}) { children = []; } else if (!isArray(children)) { @@ -126,58 +141,70 @@ const MPVContainerComponent = ({children, panelStates, classes, ...props}: MPVCo } 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))); + (panelStates[idx] && + (panelStates[idx].visible || panelStates[idx].visible === undefined))); const [panelVisibility, setPanelVisibility] = useState(initialVisibility); const [previousPanelVisibility, setPreviousPanelVisibility] = useState(initialVisibility); const [highlightedPanel, setHighlightedPanel] = useState(-1); + const currentSelectedPanel = panelVisibility.findIndex(Boolean); const [selectedPanel, setSelectedPanel] = useState(-1); const panelRef = useRef(null); let panels: JSX.Element[] = []; let buttons: JSX.Element[] = []; + let tabs: JSX.Element[] = []; + let buttonBar: JSX.Element = <>; if (isArray(children)) { - for (let idx = 0; idx < children.length; idx++) { - const showFn = (idx: number) => () => { - setPreviousPanelVisibility(initialVisibility); + const showFn = (idx: number) => () => { + setPreviousPanelVisibility(initialVisibility); + if (props.mutuallyExclusive) { + // Hide all other panels setPanelVisibility([ - ...panelVisibility.slice(0, idx), + ...(new Array(idx).fill(false)), true, - ...panelVisibility.slice(idx+1) + ...(new Array(panelVisibility.length-(idx+1)).fill(false)), ]); - setSelectedPanel(idx); - }; - const hideFn = (idx: number) => () => { - setPreviousPanelVisibility(initialVisibility); + } else { setPanelVisibility([ ...panelVisibility.slice(0, idx), - false, - ...panelVisibility.slice(idx+1) - ]) - }; - 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), + ...panelVisibility.slice(idx + 1) ]); - }; - const unMaximizeFn = (idx: number) => () => { - setPanelVisibility(previousPanelVisibility); - setSelectedPanel(idx); } + setSelectedPanel(idx); + }; + const hideFn = (idx: number) => () => { + setPreviousPanelVisibility(initialVisibility); + setPanelVisibility([ + ...panelVisibility.slice(0, idx), + false, + ...panelVisibility.slice(idx+1) + ]) + }; + 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 unMaximizeFn = (idx: number) => () => { + setPanelVisibility(previousPanelVisibility); + setSelectedPanel(idx); + } + for (let idx = 0; idx < children.length; idx++) { const panelName = panelStates === undefined - ? `Panel ${idx+1}` - : (panelStates[idx] && panelStates[idx].name) || `Panel ${idx+1}`; + ? `Panel ${idx + 1}` + : (panelStates[idx] && panelStates[idx].name) || `Panel ${idx + 1}`; const btnVariant = panelVisibility[idx] ? "contained" : "outlined"; const btnTooltip = panelVisibility[idx] ? `` - :`Open ${panelName} panel`; + : `Open ${panelName} panel`; const panelIsMaximized = panelVisibility[idx] && panelVisibility.filter(e => e).length === 1; @@ -193,11 +220,16 @@ const MPVContainerComponent = ({children, panelStates, classes, ...props}: MPVCo setHighlightedPanel(-1); }} onClick={showFn(idx)}> - {panelName} + {panelName} ]; + tabs = [ + ...tabs, + <>{panelName} + ]; + const aPanel = ; panels = [...panels, aPanel]; }; + + buttonBar = props.mutuallyExclusive ? + + showFn(val)()}> + {tabs.map((tgl, idx) => )} + + : + <> + {buttons.map((tgl, idx) => {tgl})} + ; }; - return + return - { buttons.map((tgl, idx) => {tgl}) } + {buttonBar} setSelectedPanel(-1)}> - { panelVisibility.includes(true) + {panelVisibility.includes(true) ? panels : - } + } ; };