🐛 fix(codeAreaModal/index.tsx): update condition in useEffect to check if nodeClass.template has more than 2 fields instead of 1
✨ feat(codeAreaModal/index.tsx): refactor handleClick function to call processCode function instead of directly calling postValidateCode function ✨ feat(codeAreaModal/index.tsx): add support for processing non-dynamic fields by calling postValidateCode function and updating success and error data accordingly ✨ feat(codeAreaModal/index.tsx): add support for processing dynamic fields by calling postCustomComponent function and updating nodeClass and error data accordingly
This commit is contained in:
parent
e0d086e85a
commit
5d4aae9ba3
1 changed files with 57 additions and 45 deletions
|
|
@ -41,64 +41,76 @@ export default function CodeAreaModal({
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// if nodeClass.template has more fields other than code and dynamic is true
|
// if nodeClass.template has more fields other than code and dynamic is true
|
||||||
// do not run handleClick
|
// do not run handleClick
|
||||||
if (dynamic && Object.keys(nodeClass.template).length > 1) {
|
if (dynamic && Object.keys(nodeClass.template).length > 2) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
handleClick();
|
processCode();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
function handleClick() {
|
function processNonDynamicField() {
|
||||||
if (!dynamic) {
|
postValidateCode(code)
|
||||||
postValidateCode(code)
|
.then((apiReturn) => {
|
||||||
.then((apiReturn) => {
|
if (apiReturn.data) {
|
||||||
if (apiReturn.data) {
|
let importsErrors = apiReturn.data.imports.errors;
|
||||||
let importsErrors = apiReturn.data.imports.errors;
|
let funcErrors = apiReturn.data.function.errors;
|
||||||
let funcErrors = apiReturn.data.function.errors;
|
if (funcErrors.length === 0 && importsErrors.length === 0) {
|
||||||
if (funcErrors.length === 0 && importsErrors.length === 0) {
|
setSuccessData({
|
||||||
setSuccessData({
|
title: "Code is ready to run",
|
||||||
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",
|
|
||||||
});
|
});
|
||||||
|
// 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 {
|
||||||
.catch((_) => {
|
|
||||||
setErrorData({
|
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 {
|
} else {
|
||||||
postCustomComponent(code, nodeClass)
|
processDynamicField();
|
||||||
.then((apiReturn) => {
|
|
||||||
const { data } = apiReturn;
|
|
||||||
if (data) {
|
|
||||||
setNodeClass(data);
|
|
||||||
setOpen(false);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
setError(err.response.data);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleClick() {
|
||||||
|
processCode();
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Function to be executed after the state changes
|
// Function to be executed after the state changes
|
||||||
const delayedFunction = setTimeout(() => {
|
const delayedFunction = setTimeout(() => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue