Skip to content

Commit 9d8c0fd

Browse files
authored
fix(ui): open response pane at a minimum height on expand (usebruno#8236)
1 parent 2bc735e commit 9d8c0fd

3 files changed

Lines changed: 65 additions & 1 deletion

File tree

packages/bruno-app/src/components/RequestTabPanel/index.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import GlobalEnvironmentSettings from 'components/Environments/GlobalEnvironment
4343
import OpenAPISyncTab from 'components/OpenAPISyncTab';
4444
import OpenAPISpecTab from 'components/OpenAPISpecTab';
4545
import CollapsedPanelIndicator from './CollapsedPanelIndicator';
46+
import { clampRequestHeightForResponse } from './paneSize';
4647
import { IconLoader2 } from '@tabler/icons';
4748

4849
const MIN_LEFT_PANE_WIDTH = 300;
@@ -51,6 +52,8 @@ const MIN_TOP_PANE_HEIGHT = 150;
5152
const MIN_BOTTOM_PANE_HEIGHT = 150;
5253
const COLLAPSE_EDGE_THRESHOLD = 80;
5354
const EXPAND_EDGE_THRESHOLD = 100;
55+
// Minimum response pane height to show placeholder content on click-expand
56+
const RESPONSE_EXPAND_MIN_HEIGHT = 300;
5457

5558
const RequestTabPanel = () => {
5659
const dispatch = useDispatch();
@@ -262,6 +265,21 @@ const RequestTabPanel = () => {
262265
startDragging(e);
263266
}, [expandResponse, applyPointerResize, startDragging]);
264267

268+
const handleResponseIndicatorClickExpand = useCallback(() => {
269+
expandResponse();
270+
if (!isVerticalLayoutRef.current || !mainSectionRef.current) return;
271+
const { height: containerHeight } = mainSectionRef.current.getBoundingClientRect();
272+
const clampedHeight = clampRequestHeightForResponse(
273+
topPaneHeight,
274+
containerHeight,
275+
RESPONSE_EXPAND_MIN_HEIGHT,
276+
MIN_TOP_PANE_HEIGHT
277+
);
278+
if (clampedHeight != null) {
279+
setTopPaneHeight(clampedHeight);
280+
}
281+
}, [expandResponse, topPaneHeight, setTopPaneHeight]);
282+
265283
useEffect(() => {
266284
document.addEventListener('mouseup', handleMouseUp);
267285
document.addEventListener('mousemove', handleMouseMove);
@@ -563,7 +581,7 @@ const RequestTabPanel = () => {
563581
<CollapsedPanelIndicator
564582
panelType="response"
565583
isVertical={isVerticalLayout}
566-
onExpand={expandResponse}
584+
onExpand={handleResponseIndicatorClickExpand}
567585
onDragStart={handleResponseIndicatorDragStart}
568586
dragThresholdPx={isVerticalLayout ? MIN_BOTTOM_PANE_HEIGHT / 2 : MIN_RIGHT_PANE_WIDTH / 2}
569587
/>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Clamps the request pane height to leave room for the response pane.
3+
* Returns null if no clamping is needed.
4+
*/
5+
export const clampRequestHeightForResponse = (
6+
currentRequestHeight,
7+
containerHeight,
8+
minResponseHeight,
9+
minRequestHeight
10+
) => {
11+
const maxRequestHeight = containerHeight - minResponseHeight;
12+
if (currentRequestHeight <= maxRequestHeight) return null;
13+
return Math.max(minRequestHeight, maxRequestHeight);
14+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { clampRequestHeightForResponse } from './paneSize';
2+
3+
// Mirrors RequestTabPanel's constants
4+
const MIN_TOP_PANE_HEIGHT = 150;
5+
const RESPONSE_EXPAND_MIN_HEIGHT = 300;
6+
7+
const clamp = (currentRequestHeight, containerHeight) =>
8+
clampRequestHeightForResponse(currentRequestHeight, containerHeight, RESPONSE_EXPAND_MIN_HEIGHT, MIN_TOP_PANE_HEIGHT);
9+
10+
describe('clampRequestHeightForResponse', () => {
11+
it('shrinks the request pane so the response opens without squishing', () => {
12+
const containerHeight = 800;
13+
const result = clamp(760, containerHeight);
14+
expect(result).toBe(500);
15+
});
16+
17+
it('floors at the request minimum in a short window', () => {
18+
const containerHeight = 400;
19+
const result = clamp(380, containerHeight);
20+
expect(result).toBe(MIN_TOP_PANE_HEIGHT);
21+
});
22+
23+
it('floors at the request minimum even when the window cannot fit both panes', () => {
24+
// 200px container results in a negative maxRequestHeight, so the MIN_TOP_PANE_HEIGHT is returned.
25+
expect(clamp(380, 200)).toBe(MIN_TOP_PANE_HEIGHT);
26+
});
27+
28+
it('returns null when the response already has enough room, no clamping needed', () => {
29+
// Request with height 400 leaves the response with enough room, so no clamping is needed.
30+
expect(clamp(400, 1000)).toBeNull();
31+
});
32+
});

0 commit comments

Comments
 (0)