Skip to content

Commit 49e4330

Browse files
authored
fix: improve the request body tab layout (#3540)
* feat: remove RequestHeaders component and its related code * feat: integrate ResizeContext for dynamic editor height adjustment
1 parent 9ec53d3 commit 49e4330

File tree

2 files changed

+9
-159
lines changed

2 files changed

+9
-159
lines changed

src/app/views/common/monaco/Monaco.tsx

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import Editor, { OnChange, loader } from '@monaco-editor/react';
22
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
3-
import { useEffect, useRef, useState } from 'react';
3+
import { useContext, useEffect, useRef, useState } from 'react';
44
import { ThemeContext } from '../../../../themes/theme-context';
5-
import { convertPercentToPx } from '../dimensions/dimensions-adjustment';
5+
import { ResizeContext } from '../../../services/context/resize-context/ResizeContext';
66
import { formatJsonStringForAllBrowsers } from './util/format-json';
77
interface IMonaco {
88
body: object | string | undefined;
@@ -17,6 +17,7 @@ interface IMonaco {
1717
export function Monaco(props: IMonaco) {
1818
let { body } = props;
1919
const { onChange, language, readOnly } = props;
20+
const { parentHeight, dragValue, initiator } = useContext(ResizeContext);
2021

2122
if (body && typeof body !== 'string') {
2223
body = formatJsonStringForAllBrowsers(body);
@@ -42,28 +43,14 @@ export function Monaco(props: IMonaco) {
4243

4344
const editorRef = useRef<monaco.editor.IStandaloneCodeEditor | null>(null);
4445
const [editorHeight, setEditorHeight] = useState(300);
45-
4646
useEffect(() => {
47-
const handleResize = (e: Event) => {
48-
const layout = document.getElementById('layout');
49-
if (layout) {
50-
const parentHeight = layout.parentElement?.offsetHeight ?? 0;
51-
const customEvent = e as CustomEvent;
52-
const { initiator, value } = customEvent.detail as {
53-
initiator: string;
54-
value: number;
55-
};
56-
if (initiator === 'responseSize') {
57-
if (editorRef.current && value > 0) {
58-
const newHeight = parentHeight - value - 124;
59-
setEditorHeight(newHeight);
60-
}
61-
}
47+
if (initiator === 'responseSize') {
48+
if (editorRef.current && dragValue > 0) {
49+
const newHeight = parentHeight - dragValue - 124;
50+
setEditorHeight(Math.max(300, newHeight));
6251
}
63-
};
64-
window.addEventListener('onResizeDragEnd', handleResize);
65-
return () => window.removeEventListener('resize', handleResize);
66-
}, []);
52+
}
53+
}, [parentHeight, dragValue, initiator]);
6754

6855
return (
6956
<>

src/app/views/query-runner/request/headers/RequestHeaders.tsx

Lines changed: 0 additions & 137 deletions
This file was deleted.

0 commit comments

Comments
 (0)