Skip to content

Commit ad561dd

Browse files
authored
feat: add request/response area resizing (#3810)
1 parent 48b35b0 commit ad561dd

File tree

5 files changed

+84
-31
lines changed

5 files changed

+84
-31
lines changed

src/app/views/common/banners/Notification.styles.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,14 @@ export const useNotificationStyles = makeStyles({
99
backgroundRepeat: 'no-repeat',
1010
backgroundSize: 'contain',
1111
backgroundPosition: 'right',
12+
whiteSpace: 'wrap',
1213
'&light': {
1314
backgroundColor: '#E8EFFF',
1415
color: '#000000'
1516
},
1617
'&.dark': {
1718
backgroundColor: '#1D202A',
1819
color: '#ffffff'
19-
},
20-
'&.highContrast': {
21-
backgroundColor: '#0C3B5E',
22-
color: '#ffffff'
2320
}
2421
},
2522
body: {

src/app/views/layout/Layout.tsx

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { mergeClasses } from '@fluentui/react-components';
2-
import { useEffect, useState } from 'react';
2+
import { useEffect, useRef, useState } from 'react';
33
import { useAppDispatch, useAppSelector } from '../../../store';
44
import CollectionPermissionsProvider from '../../services/context/collection-permissions/CollectionPermissionsProvider';
55
import { PopupsProvider } from '../../services/context/popups-context';
@@ -17,7 +17,7 @@ import Request from '../query-runner/request/Request';
1717
import { Sidebar } from '../sidebar/Sidebar';
1818
import { LayoutResizeHandler } from './LayoutResizeHandler';
1919
import { useResizeHandle } from '@fluentui-contrib/react-resize-handle';
20-
import { useLayoutResizeStyles, useLayoutStyles, SIDEBAR_SIZE_CSS_VAR } from './LayoutStyles';
20+
import { useLayoutResizeStyles, useLayoutStyles, SIDEBAR_SIZE_CSS_VAR, REQUEST_HEIGHT_CSS_VAR } from './LayoutStyles';
2121
import { useDetectMobileScreen } from '../../utils/useDetectMobileScreen';
2222

2323
interface LayoutProps {
@@ -30,9 +30,12 @@ export const Layout = (props: LayoutProps) => {
3030
const resizeStyles = useLayoutResizeStyles();
3131
const dispatch = useAppDispatch();
3232
const sampleQuery = useAppSelector((state) => state.sampleQuery);
33+
const [sampleBody, setSampleBody] = useState('');
3334
const { mobileScreen, showSidebar } = useAppSelector((state) => state.sidebarProperties);
3435
const [initialSidebarWidth, setInitialSidebarWidth] = useState(456);
3536
const [sidebarElement, setSidebarElement] = useState<HTMLElement | null>(null);
37+
const [requestHeight, setRequestHeight] = useState(300);
38+
const requestRef = useRef<HTMLDivElement | null>(null);
3639

3740
const {
3841
handleRef: sidebarHandleRef,
@@ -44,8 +47,6 @@ export const Layout = (props: LayoutProps) => {
4447
growDirection: 'end'
4548
});
4649

47-
const [sampleBody, setSampleBody] = useState('');
48-
4950
useEffect(() => {
5051
if (sampleQuery.selectedVerb !== 'GET') {
5152
const query = { ...sampleQuery };
@@ -117,6 +118,40 @@ export const Layout = (props: LayoutProps) => {
117118
}
118119
};
119120

121+
const updateRequestHeight = (newHeight: number) => {
122+
const min = 150;
123+
const max = window.innerHeight * 0.5;
124+
const finalHeight = Math.max(min, Math.min(max, newHeight));
125+
126+
document.documentElement.style.setProperty(REQUEST_HEIGHT_CSS_VAR, `${finalHeight}px`);
127+
setRequestHeight(finalHeight);
128+
};
129+
130+
const handleRequestResizeStart = (e: React.MouseEvent) => {
131+
e.preventDefault();
132+
133+
const startY = e.clientY;
134+
const startHeight = requestRef.current
135+
? parseInt(getComputedStyle(requestRef.current).height, 10)
136+
: requestHeight;
137+
138+
const onMouseMove = (event: MouseEvent) => {
139+
const newHeight = startHeight + (event.clientY - startY);
140+
updateRequestHeight(newHeight);
141+
};
142+
143+
const onMouseUp = () => {
144+
window.removeEventListener('mousemove', onMouseMove);
145+
window.removeEventListener('mouseup', onMouseUp);
146+
};
147+
148+
window.addEventListener('mousemove', onMouseMove);
149+
window.addEventListener('mouseup', onMouseUp);
150+
};
151+
152+
useEffect(() => {
153+
document.documentElement.style.setProperty(REQUEST_HEIGHT_CSS_VAR, `${requestHeight}px`);
154+
}, []);
120155
return (
121156
<>
122157
<PopupsProvider>
@@ -128,7 +163,7 @@ export const Layout = (props: LayoutProps) => {
128163
<Sidebar handleToggleSelect={handleToggleSelect} />
129164
{!mobileScreen && (
130165
<LayoutResizeHandler
131-
position="end"
166+
position='end'
132167
ref={sidebarHandleRef}
133168
onDoubleClick={() => updateSidebarSize(456)}
134169
onMouseDown={handleResizeStart}
@@ -150,8 +185,20 @@ export const Layout = (props: LayoutProps) => {
150185
<QueryRunner onSelectVerb={props.handleSelectVerb} />
151186
</div>
152187
<div id='request-response-area' className={layoutStyles.requestResponseArea}>
153-
<div id='request-area' className={layoutStyles.requestArea}>
188+
<div
189+
id='request-area'
190+
className={layoutStyles.requestArea}
191+
ref={requestRef}
192+
style={{ height: `var(${REQUEST_HEIGHT_CSS_VAR})` }}
193+
>
154194
<Request handleOnEditorChange={handleOnEditorChange} sampleQuery={sampleQuery} />
195+
{!mobileScreen && (
196+
<LayoutResizeHandler
197+
position='bottom'
198+
onMouseDown={handleRequestResizeStart}
199+
onDoubleClick={() => updateRequestHeight(300)}
200+
/>
201+
)}
155202
</div>
156203
<div style={{ margin: '0 10px' }}>
157204
<StatusMessages />

src/app/views/layout/LayoutResizeHandler.tsx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,30 @@ export const LayoutResizeHandler = React.forwardRef<HTMLDivElement, HandleProps>
3838
: position === 'start'
3939
? 'right'
4040
: 'left';
41-
42-
const positioningProps =
43-
position === 'start' || position === 'end'
44-
? {
41+
const positioningProps = (() => {
42+
if (position === 'start' || position === 'end') {
43+
return {
4544
[positioningAttr]: '-5px',
4645
top: '50%',
4746
transform: 'translateY(-50%)',
48-
width: '6px',
47+
width: '8px',
4948
height: '100%',
5049
cursor: 'col-resize'
51-
}
52-
: {
53-
...(position === 'top' ? { top: '-6.5px' } : { bottom: '-6.5px' }),
54-
left: '50%',
55-
transform: 'translateX(-50%)',
50+
};
51+
}
52+
53+
if (position === 'top' || position === 'bottom') {
54+
return {
55+
[position]: '0',
56+
left: '0',
5657
width: '100%',
57-
height: '3px',
58+
height: '6px',
5859
cursor: 'row-resize'
5960
};
61+
}
62+
63+
return {};
64+
})();
6065

6166
return (
6267
<div

src/app/views/layout/LayoutStyles.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { makeResetStyles, tokens, makeStyles } from '@fluentui/react-components';
22

33
export const SIDEBAR_SIZE_CSS_VAR = '--sidebar-size';
4+
export const REQUEST_HEIGHT_CSS_VAR = '--request-area-height';
45

56
export const useLayoutResizeStyles = makeResetStyles({
67
[SIDEBAR_SIZE_CSS_VAR]: '23%'
@@ -22,9 +23,9 @@ export const useLayoutStyles = makeStyles({
2223
},
2324
sidebar: {
2425
flex: '0 0 auto',
25-
flexBasis: `clamp(40px, var(${SIDEBAR_SIZE_CSS_VAR}), 25vw)`,
26-
maxWidth: '25vw',
27-
minWidth: '40px',
26+
flexBasis: `var(${SIDEBAR_SIZE_CSS_VAR})`,
27+
minWidth: '48px',
28+
maxWidth: '50vw',
2829
position: 'relative',
2930
overflow: 'hidden',
3031
transition: 'flex-basis 0.2s ease-in-out',
@@ -48,17 +49,19 @@ export const useLayoutStyles = makeStyles({
4849
minHeight: 0
4950
},
5051
requestResponseArea: {
51-
flex: 1,
5252
display: 'flex',
5353
flexDirection: 'column',
54-
minHeight: 0,
55-
overflowY: 'auto',
56-
overflowX: 'hidden'
54+
flexGrow: 1,
55+
overflow: 'hidden'
5756
},
5857
requestArea: {
59-
flex: 1,
60-
minHeight: '200px',
58+
height: `var(${REQUEST_HEIGHT_CSS_VAR})`,
59+
minHeight: '150px',
60+
maxHeight: '50vh',
61+
position: 'relative',
6162
overflow: 'auto',
63+
flexShrink: 0,
64+
transition: 'height 0.2s ease-in-out',
6265
borderRadius: tokens.borderRadiusMedium,
6366
padding: tokens.spacingHorizontalS
6467
},

src/app/views/sidebar/Sidebar.styles.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export const useSidebarStyles = makeStyles({
1616
}
1717
},
1818
sidebarToggle: {
19-
marginLeft: 'auto'
19+
marginLeft: 'auto',
20+
padding: '10px'
2021
},
2122
tree: {
2223
flexGrow: 1,

0 commit comments

Comments
 (0)