diff --git a/src/frontend/src/components/codeAreaComponent/index.tsx b/src/frontend/src/components/codeAreaComponent/index.tsx index f34a105dc..83861dbd0 100644 --- a/src/frontend/src/components/codeAreaComponent/index.tsx +++ b/src/frontend/src/components/codeAreaComponent/index.tsx @@ -63,6 +63,7 @@ export default function CodeAreaComponent({ onClick={() => { openPopUp( = ({ children }) => { + +const Content: React.FC = ({ children }) => { return ( -
- {children} -
) -} -const Second: React.FC<{ children: ReactNode }> = ({ children }) => { - return ( -
+
{children}
) } @@ -39,16 +33,16 @@ const Header: React.FC<{ children: ReactNode, description:string }> = ({ childre ) } -interface TwoColumnsModalProps { - children: [React.ReactElement, React.ReactElement, React.ReactElement]; +interface BaseModalProps { + children: [React.ReactElement, React.ReactElement]; open: boolean; setOpen: (open: boolean) => void; } -function TwoColumnsModal({ +function BaseModal({ open, setOpen, children, -}: TwoColumnsModalProps) { +}: BaseModalProps) { const {closePopUp, setCloseEdit} = useContext(PopUpContext) function setModalOpen(x: boolean) { @@ -60,14 +54,10 @@ function TwoColumnsModal({ }, 300); } } - const firstChild = React.Children.toArray(children).find( - (child) => (child as React.ReactElement).type === First - ); - - const secondChild = React.Children.toArray(children).find( - (child) => (child as React.ReactElement).type === Second - ); const headerChild = React.Children.toArray(children).find((child) => (child as React.ReactElement).type === Header); + const ContentChild = React.Children.toArray(children).find( + (child) => (child as React.ReactElement).type === Content + ); //UPDATE COLORS AND STYLE CLASSSES return ( @@ -75,15 +65,14 @@ function TwoColumnsModal({ {headerChild}
- {firstChild} - {secondChild} + {ContentChild}
); } -TwoColumnsModal.First = First; -TwoColumnsModal.Second = Second; -TwoColumnsModal.Header = Header; -export default TwoColumnsModal; \ No newline at end of file + +BaseModal.Content = Content; +BaseModal.Header = Header; +export default BaseModal; \ No newline at end of file diff --git a/src/frontend/src/modals/codeAreaModal/v2.tsx b/src/frontend/src/modals/codeAreaModal/v2.tsx index 34521b993..965acf05b 100644 --- a/src/frontend/src/modals/codeAreaModal/v2.tsx +++ b/src/frontend/src/modals/codeAreaModal/v2.tsx @@ -1,4 +1,4 @@ -import { useContext, useRef, useState } from "react"; +import { useContext, useEffect, useRef, useState } from "react"; import { PopUpContext } from "../../contexts/popUpContext"; import 'ace-builds/src-noconflict/ace'; import { darkContext } from "../../contexts/darkContext"; @@ -7,112 +7,151 @@ import { alertContext } from "../../contexts/alertContext"; import { Button } from "../../components/ui/button"; import { CODE_PROMPT_DIALOG_SUBTITLE } from "../../constants"; import { APIClassType } from "../../types/api"; -import { - Tabs, - TabsContent, - TabsList, - TabsTrigger, -} from "../../components/ui/tabs"; -import TwoColumnsModal from "../twoColumnsModal"; +import TwoColumnsModal from "../baseModal"; +import { DialogTitle } from "@radix-ui/react-dialog"; +import { TerminalSquare } from "lucide-react"; +import AceEditor from "react-ace"; +import "ace-builds/src-noconflict/mode-python"; +import "ace-builds/src-noconflict/theme-github"; +import "ace-builds/src-noconflict/theme-twilight"; +import "ace-builds/src-noconflict/ext-language_tools"; +import 'ace-builds/src-noconflict/ace'; +import { XCircle } from 'lucide-react'; +import BaseModal from "../baseModal"; export default function CodeAreaModal({ - value, - setValue, - nodeClass, - setNodeClass, - dynamic + value, + setValue, + nodeClass, + setNodeClass, + dynamic }: { - setValue: (value: string) => void; - value: string; - nodeClass: APIClassType; - setNodeClass: (Class: APIClassType) => void; - dynamic?: boolean; + setValue: (value: string) => void; + value: string; + nodeClass: APIClassType; + setNodeClass: (Class: APIClassType) => void; + dynamic?: boolean; }) { - const [open, setOpen] = useState(true); - const [code, setCode] = useState(value); - const [loading, setLoading] = useState(false); - const { dark } = useContext(darkContext); - const { setErrorData, setSuccessData } = useContext(alertContext); - const [activeTab, setActiveTab] = useState("0"); - 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) { - setTimeout(() => { - setCloseEdit("editcode"); - closePopUp(); - }, 300); - } - } - console.log(dynamic); - - function handleClick() { - setLoading(true); - if (!dynamic) { - postValidateCode(code) - .then((apiReturn) => { - setLoading(false); - if (apiReturn.data) { - let importsErrors = apiReturn.data.imports.errors; - let funcErrors = apiReturn.data.function.errors; - if (funcErrors.length === 0 && importsErrors.length === 0) { - setSuccessData({ - title: "Code is ready to run", - }); - // setValue(code); - } else { - if (funcErrors.length !== 0) { - setErrorData({ - title: "There is an error in your function", - list: funcErrors, - }); - } - if (importsErrors.length !== 0) { - setErrorData({ - title: "There is an error in your imports", - list: importsErrors, - }); - } - } - } else { - setErrorData({ - title: "Something went wrong, please try again", - }); - } - }) - .catch((_) => { - setLoading(false); - setErrorData({ - title: "There is something wrong with this code, please review it", - }); - }); - } - else { - postCustomComponent(code, nodeClass).then((apiReturn) => { - const { data } = apiReturn; - if (data) { - setNodeClass(data); - setModalOpen(false); + const [open, setOpen] = useState(true); + const [code, setCode] = useState(value); + const [loading, setLoading] = useState(false); + const { dark } = useContext(darkContext); + const { setErrorData, setSuccessData } = useContext(alertContext); + const [activeTab, setActiveTab] = useState("0"); + 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) { + setTimeout(() => { + setCloseEdit("editcode"); + closePopUp(); + }, 300); } - }).catch((err) => { - setErrorData({ - title: "There is something wrong with this code, please see the error on the errors tab", - }); - console.log(err.response.data); - setError(err.response.data); - }); } + useEffect(() => { + setValue(code); + }, [code, setValue]) - } - const tabs = [{ name: "code" }, { name: "errors" }] + function handleClick() { + setLoading(true); + if (!dynamic) { + postValidateCode(code) + .then((apiReturn) => { + setLoading(false); + if (apiReturn.data) { + let importsErrors = apiReturn.data.imports.errors; + let funcErrors = apiReturn.data.function.errors; + if (funcErrors.length === 0 && importsErrors.length === 0) { + setSuccessData({ + title: "Code is ready to run", + }); + // setValue(code); + } else { + if (funcErrors.length !== 0) { + setErrorData({ + title: "There is an error in your function", + list: funcErrors, + }); + } + if (importsErrors.length !== 0) { + setErrorData({ + title: "There is an error in your imports", + list: importsErrors, + }); + } + } + } else { + setErrorData({ + title: "Something went wrong, please try again", + }); + } + }) + .catch((_) => { + setLoading(false); + setErrorData({ + title: "There is something wrong with this code, please review it", + }); + }); + } + else { + postCustomComponent(code, nodeClass).then((apiReturn) => { + const { data } = apiReturn; + if (data) { + setNodeClass(data); + setModalOpen(false); + } + }).catch((err) => { + setError(err.response.data); + }); + } - return ( - - {"A"} - {"A"} - {"B"} - - ); + } + const tabs = [{ name: "code" }, { name: "errors" }] + + return ( + + + + Edit Code + + +
+
+ { + setCode(value); + }} + className="w-full rounded-lg h-full custom-scroll border-[1px] border-gray-300 dark:border-gray-600" + /> +
+
+
+

{error?.detail?.error}

+
{error?.detail?.traceback}
+
+
+
+
+
+
+
+ ); }