From 02b5eebbef6e793fd3ea31fc6b06452f77d5d5c7 Mon Sep 17 00:00:00 2001 From: Denise Li Date: Wed, 21 Aug 2024 14:41:53 -0400 Subject: [PATCH] fix: clean up codemirror panel resizing (#2472) Issue: https://github.com/TBD54566975/ftl/issues/2458 Changes: * Response panel is only displayed when `Body` tab (i.e. Request tab) is selected, instead of taking screen real estate away from the read-only schema tabs * Border between request and response panels is replaced with a full-width draggable handle * Related: fixed the existing bugs in `components/ResizeableVerticalPanels.tsx` * All codemirror components automatically take the full height of their container https://github.com/user-attachments/assets/9594c696-1ddb-4412-bd13-722c73cd7662 --------- Co-authored-by: github-actions[bot] --- frontend/src/components/CodeEditor.tsx | 12 +++++++-- .../components/ResizeableVerticalPanels.tsx | 14 ++++++----- frontend/src/features/verbs/VerbFormInput.tsx | 4 +-- .../src/features/verbs/VerbRequestForm.tsx | 25 ++++++++++++------- 4 files changed, 36 insertions(+), 19 deletions(-) diff --git a/frontend/src/components/CodeEditor.tsx b/frontend/src/components/CodeEditor.tsx index 3d3c53d0a0..5e35805775 100644 --- a/frontend/src/components/CodeEditor.tsx +++ b/frontend/src/components/CodeEditor.tsx @@ -78,7 +78,15 @@ export const CodeEditor = ({ initialState, onTextChanged }: { initialState: Init const state = EditorState.create({ doc: initialState.initialText, - extensions: [commonExtensions, isDarkMode ? atomone : githubLight, json5(), editingExtensions], + extensions: [ + ...commonExtensions, + isDarkMode ? atomone : githubLight, + json5(), + editingExtensions, + EditorView.theme({ + '&': { height: '100%' }, + }), + ], }) const view = new EditorView({ @@ -94,5 +102,5 @@ export const CodeEditor = ({ initialState, onTextChanged }: { initialState: Init } }, [initialState, isDarkMode]) - return
+ return
} diff --git a/frontend/src/components/ResizeableVerticalPanels.tsx b/frontend/src/components/ResizeableVerticalPanels.tsx index 10661ef39e..7861378b05 100644 --- a/frontend/src/components/ResizeableVerticalPanels.tsx +++ b/frontend/src/components/ResizeableVerticalPanels.tsx @@ -44,12 +44,14 @@ export const ResizableVerticalPanels: React.FC = ( } const onDrag = (e: React.MouseEvent) => { - if (isDragging) { - const newHeight = e.clientY - const maxHeight = window.innerHeight - minBottomPanelHeight - if (newHeight >= minTopPanelHeight && newHeight <= maxHeight) { - setTopPanelHeight(newHeight - 44) - } + if (!isDragging || !containerRef.current) { + return + } + const containerDims = containerRef.current.getBoundingClientRect() + const newHeight = e.clientY - containerDims.top + const maxHeight = containerDims.height - minBottomPanelHeight + if (newHeight >= minTopPanelHeight && newHeight <= maxHeight) { + setTopPanelHeight(newHeight) } } diff --git a/frontend/src/features/verbs/VerbFormInput.tsx b/frontend/src/features/verbs/VerbFormInput.tsx index f96c597223..23488ee58e 100644 --- a/frontend/src/features/verbs/VerbFormInput.tsx +++ b/frontend/src/features/verbs/VerbFormInput.tsx @@ -27,7 +27,7 @@ export const VerbFormInput = ({ return (
- {requestType} + {requestType} setPath(event.target.value)} /> -
diff --git a/frontend/src/features/verbs/VerbRequestForm.tsx b/frontend/src/features/verbs/VerbRequestForm.tsx index b81d2b9e6a..7ed2d80bbb 100644 --- a/frontend/src/features/verbs/VerbRequestForm.tsx +++ b/frontend/src/features/verbs/VerbRequestForm.tsx @@ -1,5 +1,6 @@ import { useEffect, useState } from 'react' import { CodeEditor, type InitialState } from '../../components/CodeEditor' +import { ResizableVerticalPanels } from '../../components/ResizeableVerticalPanels' import { useClient } from '../../hooks/use-client' import type { Module, Verb } from '../../protos/xyz/block/ftl/v1/console/console_pb' import { VerbService } from '../../protos/xyz/block/ftl/v1/ftl_connect' @@ -101,8 +102,19 @@ export const VerbRequestForm = ({ module, verb }: { module?: Module; verb?: Verb const bottomText = response ?? error ?? '' + const bodyEditor = + const bodyPanels = + bottomText === '' ? ( + bodyEditor + ) : ( + } + /> + ) + return ( -
+
-
-
- {activeTabId === 'body' && } +
+ {activeTabId === 'body' && bodyPanels} {activeTabId === 'verbschema' && } {activeTabId === 'jsonschema' && } {activeTabId === 'headers' && }
- -
-
- -
)