Fix bottom panel and make it resizable

Summary: The bottom panel got broken during the virtualisation+ panel refactor, we need to tell the tree how much height is taken by the panel so it can size itself accordingly.

Reviewed By: lblasa

Differential Revision: D48313766

fbshipit-source-id: 849886101eb0869cc068fd0ad6dc1d053233043e
This commit is contained in:
Luke De Feo
2023-08-21 04:24:16 -07:00
committed by Facebook GitHub Bot
parent 2d217575bb
commit 4912b3f47e
2 changed files with 80 additions and 44 deletions

View File

@@ -53,6 +53,8 @@ export function Component() {
setBottomPanelComponent(undefined); setBottomPanelComponent(undefined);
}; };
const [bottomPanelHeight, setBottomPanelHeight] = useState(400);
if (showPerfStats) if (showPerfStats)
return ( return (
<PerfStats <PerfStats
@@ -106,49 +108,62 @@ export function Component() {
return ( return (
<QueryClientProvider client={queryClient}> <QueryClientProvider client={queryClient}>
<Layout.Horizontal <Layout.Container grow>
grow <Layout.Horizontal
style={{
borderRadius: theme.borderRadius,
backgroundColor: theme.backgroundWash,
}}>
<Layout.Container
grow grow
style={{ style={{
borderRadius: theme.borderRadius, borderRadius: theme.borderRadius,
backgroundColor: theme.backgroundDefault, backgroundColor: theme.backgroundWash,
}}> }}>
<TreeControls /> <Layout.Container
<Tree2 nodes={nodes} rootId={rootId} /> grow
</Layout.Container> style={{
borderRadius: theme.borderRadius,
backgroundColor: theme.backgroundDefault,
}}>
<TreeControls />
<Tree2
additionalHeightOffset={
bottomPanelComponent != null ? bottomPanelHeight : 0
}
nodes={nodes}
rootId={rootId}
/>
</Layout.Container>
<ResizablePanel <ResizablePanel
position="right" position="right"
minWidth={200} minWidth={200}
width={visualiserWidth + theme.space.large} width={visualiserWidth + theme.space.large}
maxWidth={800} maxWidth={800}
onResize={(width) => { onResize={(width) => {
instance.uiActions.setVisualiserWidth(width); instance.uiActions.setVisualiserWidth(width);
}} }}
gutter> gutter>
<Visualization2D <Visualization2D
width={visualiserWidth} width={visualiserWidth}
nodes={nodes} nodes={nodes}
onSelectNode={instance.uiActions.onSelectNode} onSelectNode={instance.uiActions.onSelectNode}
/> />
</ResizablePanel> </ResizablePanel>
<DetailSidebar width={350}> <DetailSidebar width={350}>
<Inspector <Inspector
os={instance.os} os={instance.os}
metadata={metadata} metadata={metadata}
nodes={nodes} nodes={nodes}
showExtra={openBottomPanelWithContent} showExtra={openBottomPanelWithContent}
/> />
</DetailSidebar> </DetailSidebar>
<BottomPanel dismiss={dismissBottomPanel}> </Layout.Horizontal>
{bottomPanelComponent} {bottomPanelComponent && (
</BottomPanel> <BottomPanel
</Layout.Horizontal> height={bottomPanelHeight}
setHeight={setBottomPanelHeight}
dismiss={dismissBottomPanel}>
{bottomPanelComponent}
</BottomPanel>
)}
</Layout.Container>
</QueryClientProvider> </QueryClientProvider>
); );
} }
@@ -166,8 +181,15 @@ export function Centered(props: {children: React.ReactNode}) {
type BottomPanelProps = { type BottomPanelProps = {
dismiss: () => void; dismiss: () => void;
children: React.ReactNode; children: React.ReactNode;
height: number;
setHeight: (height: number) => void;
}; };
export function BottomPanel({dismiss, children}: BottomPanelProps) { export function BottomPanel({
dismiss,
children,
height,
setHeight,
}: BottomPanelProps) {
const bottomPanelRef = useRef<any>(null); const bottomPanelRef = useRef<any>(null);
useEffect(() => { useEffect(() => {
@@ -191,9 +213,15 @@ export function BottomPanel({dismiss, children}: BottomPanelProps) {
if (!children) { if (!children) {
return <></>; return <></>;
} }
return ( return (
<div ref={bottomPanelRef}> <div ref={bottomPanelRef}>
<ResizablePanel position="bottom" minHeight={200} height={400} gutter> <ResizablePanel
position="bottom"
minHeight={200}
height={height}
onResize={(_, height) => setHeight(height)}
gutter>
<Layout.ScrollContainer>{children}</Layout.ScrollContainer> <Layout.ScrollContainer>{children}</Layout.ScrollContainer>
<div style={{margin: 10}}> <div style={{margin: 10}}>
<Button type="ghost" style={{float: 'right'}} onClick={dismiss}> <Button type="ghost" style={{float: 'right'}} onClick={dismiss}>

View File

@@ -55,7 +55,9 @@ export type TreeNode = ClientNode & {
export function Tree2({ export function Tree2({
nodes, nodes,
rootId, rootId,
additionalHeightOffset,
}: { }: {
additionalHeightOffset: number;
nodes: Map<Id, ClientNode>; nodes: Map<Id, ClientNode>;
rootId: Id; rootId: Id;
}) { }) {
@@ -139,16 +141,22 @@ export function Tree2({
isUsingKBToScrollUtill, isUsingKBToScrollUtill,
); );
const initialHeightOffset = useRef<number | null>(null);
useLayoutEffect(() => { useLayoutEffect(() => {
//the grand parent gets its size correclty via flex box, we use its initial //the grand parent gets its size correclty via flex box, we use its initial
//position to size the scroll parent ref for react virtual, It uses vh which accounts for window size changes //position to size the scroll parent ref for react virtual, It uses vh which accounts for window size changes
//However if we dynamically add content above or below we may need to revisit this approach //However if we dynamically add content above or below we may need to revisit this approach
const boundingClientRect = grandParentRef?.current?.getBoundingClientRect(); const boundingClientRect = grandParentRef?.current?.getBoundingClientRect();
parentRef.current!!.style.height = `calc(100vh - ${ if (initialHeightOffset.current == null) {
boundingClientRect!!.top //it is important to capture the initial height offset as we dont want to consider them again if elements are added dynamically later
}px - ${window.innerHeight - boundingClientRect!!.bottom}px )`; initialHeightOffset.current =
}, []); boundingClientRect!!.top +
(window.innerHeight - boundingClientRect!!.bottom) -
additionalHeightOffset;
}
parentRef.current!!.style.height = `calc(100vh - ${initialHeightOffset.current}px - ${additionalHeightOffset}px )`;
}, [additionalHeightOffset]);
useLayoutEffect(() => { useLayoutEffect(() => {
//scroll width is the width of the element including overflow, we grab the scroll width //scroll width is the width of the element including overflow, we grab the scroll width