From 5d4aae9ba3ea6146d2ad60035998e8b6cdd2e1df Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 18 Jul 2023 15:39:43 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(codeAreaModal/index.tsx):=20?= =?UTF-8?q?update=20condition=20in=20useEffect=20to=20check=20if=20nodeCla?= =?UTF-8?q?ss.template=20has=20more=20than=202=20fields=20instead=20of=201?= =?UTF-8?q?=20=E2=9C=A8=20feat(codeAreaModal/index.tsx):=20refactor=20hand?= =?UTF-8?q?leClick=20function=20to=20call=20processCode=20function=20inste?= =?UTF-8?q?ad=20of=20directly=20calling=20postValidateCode=20function=20?= =?UTF-8?q?=E2=9C=A8=20feat(codeAreaModal/index.tsx):=20add=20support=20fo?= =?UTF-8?q?r=20processing=20non-dynamic=20fields=20by=20calling=20postVali?= =?UTF-8?q?dateCode=20function=20and=20updating=20success=20and=20error=20?= =?UTF-8?q?data=20accordingly=20=E2=9C=A8=20feat(codeAreaModal/index.tsx):?= =?UTF-8?q?=20add=20support=20for=20processing=20dynamic=20fields=20by=20c?= =?UTF-8?q?alling=20postCustomComponent=20function=20and=20updating=20node?= =?UTF-8?q?Class=20and=20error=20data=20accordingly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/modals/codeAreaModal/index.tsx | 102 ++++++++++-------- 1 file changed, 57 insertions(+), 45 deletions(-) diff --git a/src/frontend/src/modals/codeAreaModal/index.tsx b/src/frontend/src/modals/codeAreaModal/index.tsx index 6cb59f4de..5f5c96a90 100644 --- a/src/frontend/src/modals/codeAreaModal/index.tsx +++ b/src/frontend/src/modals/codeAreaModal/index.tsx @@ -41,64 +41,76 @@ export default function CodeAreaModal({ useEffect(() => { // if nodeClass.template has more fields other than code and dynamic is true // do not run handleClick - if (dynamic && Object.keys(nodeClass.template).length > 1) { + if (dynamic && Object.keys(nodeClass.template).length > 2) { return; } - handleClick(); + processCode(); }, []); - function handleClick() { - if (!dynamic) { - postValidateCode(code) - .then((apiReturn) => { - 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", + function processNonDynamicField() { + postValidateCode(code) + .then((apiReturn) => { + 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, + }); + } } - }) - .catch((_) => { + } else { setErrorData({ - title: "There is something wrong with this code, please review it", + title: "Something went wrong, please try again", }); + } + }) + .catch((_) => { + setErrorData({ + title: "There is something wrong with this code, please review it", }); + }); + } + + function processDynamicField() { + postCustomComponent(code, nodeClass) + .then((apiReturn) => { + const { data } = apiReturn; + if (data) { + setNodeClass(data); + setOpen(false); + } + }) + .catch((err) => { + setError(err.response.data); + }); + } + + function processCode() { + if (!dynamic) { + processNonDynamicField(); } else { - postCustomComponent(code, nodeClass) - .then((apiReturn) => { - const { data } = apiReturn; - if (data) { - setNodeClass(data); - setOpen(false); - } - }) - .catch((err) => { - setError(err.response.data); - }); + processDynamicField(); } } + function handleClick() { + processCode(); + } + useEffect(() => { // Function to be executed after the state changes const delayedFunction = setTimeout(() => {