From 2c235402ca5b7235908845d8209926d4890ec752 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Tue, 28 Mar 2023 20:17:51 -0300 Subject: [PATCH] improvement of error check on code modal --- .../src/CustomNodes/GenericNode/index.tsx | 2 - .../components/codeAreaComponent/index.tsx | 68 ++++++++++++------- src/frontend/src/controllers/API/index.ts | 3 +- .../src/modals/codeAreaModal/index.tsx | 41 +++++++++-- src/frontend/src/types/api/index.ts | 3 +- 5 files changed, 81 insertions(+), 36 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/index.tsx b/src/frontend/src/CustomNodes/GenericNode/index.tsx index 4432b3f6b..6e3aa6e67 100644 --- a/src/frontend/src/CustomNodes/GenericNode/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/index.tsx @@ -23,7 +23,6 @@ export default function GenericNode({ const { types, deleteNode } = useContext(typesContext); const Icon = nodeIcons[types[data.type]]; if (!Icon) { - console.log(data); if (showError.current) { setErrorData({ title: data.type @@ -34,7 +33,6 @@ export default function GenericNode({ } return; } - console.log(data) return (
{ - if (disabled) { - setMyValue(""); - onChange(""); - } - }, [disabled, onChange]); - return ( -
-
- - {myValue !== "" ? myValue : 'Text empty'} - - -
-
- ); +export default function CodeAreaComponent({ + value, + onChange, + disabled, +}: TextAreaComponentType) { + const [myValue, setMyValue] = useState(value); + const { openPopUp } = useContext(PopUpContext); + useEffect(() => { + if (disabled) { + setMyValue(""); + onChange(""); + } + }, [disabled, onChange]); + return ( +
+
+ + {myValue !== "" ? myValue : "Text empty"} + + +
+
+ ); } diff --git a/src/frontend/src/controllers/API/index.ts b/src/frontend/src/controllers/API/index.ts index 2d3346a07..c6315d1b3 100644 --- a/src/frontend/src/controllers/API/index.ts +++ b/src/frontend/src/controllers/API/index.ts @@ -1,3 +1,4 @@ +import { errorsTypeAPI } from './../../types/api/index'; import { APIObjectType, sendAllProps } from '../../types/api/index'; import axios, { AxiosResponse } from "axios"; @@ -9,7 +10,7 @@ export async function sendAll(data:sendAllProps) { return await axios.post(`/predict`, data); } -export async function checkCode(code:string){ +export async function checkCode(code:string):Promise>{ return await axios.post('/validate',{code}) } \ No newline at end of file diff --git a/src/frontend/src/modals/codeAreaModal/index.tsx b/src/frontend/src/modals/codeAreaModal/index.tsx index ac5952406..72b40ed40 100644 --- a/src/frontend/src/modals/codeAreaModal/index.tsx +++ b/src/frontend/src/modals/codeAreaModal/index.tsx @@ -120,13 +120,42 @@ export default function CodeAreaModal({ type="button" className="inline-flex w-full justify-center rounded-md border border-transparent bg-indigo-600 px-4 py-2 text-base font-medium text-white shadow-sm hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 sm:ml-3 sm:w-auto sm:text-sm" onClick={() => { - setValue(code) checkCode(code) - .then((_) =>{ - setSuccessData({ title: "Code is ready to run" }) - setModalOpen(false) - } - ) + .then((apiReturn) => { + console.log(apiReturn); + if (apiReturn.data) { + console.log(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", + }); + setModalOpen(false); + 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((_) => setErrorData({ title: diff --git a/src/frontend/src/types/api/index.ts b/src/frontend/src/types/api/index.ts index f85605ce4..e7ab4e0da 100644 --- a/src/frontend/src/types/api/index.ts +++ b/src/frontend/src/types/api/index.ts @@ -15,4 +15,5 @@ export type sendAllProps={ message:string; chatHistory:{message:string,isSend:boolean}[], -}; \ No newline at end of file +}; +export type errorsTypeAPI={function:{errors:Array},imports:{errors:Array}} \ No newline at end of file