From cd94c47b0e9844c78fb86eb97ed6ff4719f144cc Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Fri, 14 Jul 2023 18:11:29 -0300 Subject: [PATCH] fix bug of scroll on ace Editor --- src/frontend/src/modals/codeAreaModal/v2.tsx | 23 +++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/frontend/src/modals/codeAreaModal/v2.tsx b/src/frontend/src/modals/codeAreaModal/v2.tsx index 9655945f7..2f61b67c4 100644 --- a/src/frontend/src/modals/codeAreaModal/v2.tsx +++ b/src/frontend/src/modals/codeAreaModal/v2.tsx @@ -37,11 +37,11 @@ export default function CodeAreaModal({ const { dark } = useContext(darkContext); const { setErrorData, setSuccessData } = useContext(alertContext); const [activeTab, setActiveTab] = useState("0"); + const [height, setHeight] = useState(null); const [error, setError] = useState<{ detail: { error: string; traceback: string }; }>(null); const { closePopUp, setCloseEdit } = useContext(PopUpContext); - const ref = useRef(); function setModalOpen(x: boolean) { setOpen(x); if (x === false) { @@ -109,7 +109,23 @@ export default function CodeAreaModal({ }); } } - const tabs = [{ name: "code" }, { name: "errors" }]; + + /// use effect to update ace editor on error to handle right scroll + useEffect(() => { + // Function to be executed after the state changes + const delayedFunction = setTimeout(() => { + if (error?.detail.error !== undefined) { + //trigger to update the height, does not really apply any height + setHeight("90%"); + } + //600 to happen after the transition of 500ms + }, 600); + + // Cleanup function to clear the timeout if the component unmounts or the state changes again + return () => { + clearTimeout(delayedFunction); + }; + }, [error, setHeight]); return ( @@ -129,6 +145,7 @@ export default function CodeAreaModal({ -
+

{error?.detail?.error}