chore(genericModal/index.tsx): add comments to indicate that the validatePrompt function needs review

fix(genericModal/index.tsx): fix condition for checking if inputVariables is empty or null
refactor(genericModal/index.tsx): remove unnecessary code and reorganize code logic in the validatePrompt function
This commit is contained in:
anovazzi1 2023-11-29 18:00:57 -03:00
commit 030c19808e

View file

@ -106,9 +106,9 @@ export default function GenericModal({
: "code-nohighlight"; : "code-nohighlight";
} }
// Function need some review, working for now
function validatePrompt(closeModal: boolean): void { function validatePrompt(closeModal: boolean): void {
//nodeClass is always null on tweaks //nodeClass is always null on tweaks
postValidatePrompt(field_name, inputValue, nodeClass!) postValidatePrompt(field_name, inputValue, nodeClass!)
.then((apiReturn) => { .then((apiReturn) => {
// if field_name is an empty string, then we need to set it // if field_name is an empty string, then we need to set it
@ -123,38 +123,24 @@ export default function GenericModal({
} }
if (apiReturn.data) { if (apiReturn.data) {
let inputVariables = apiReturn.data.input_variables ?? []; let inputVariables = apiReturn.data.input_variables ?? [];
if (inputVariables && inputVariables.length === 0) { if (!inputVariables || inputVariables.length === 0) {
setIsEdit(true); setIsEdit(true);
setNoticeData({ setNoticeData({
title: "Your template does not have any variables.", title: "Your template does not have any variables.",
}); });
setModalOpen(false); setModalOpen(false);
if (
JSON.stringify(apiReturn.data?.frontend_node) !==
JSON.stringify({})
)
setNodeClass!(apiReturn.data?.frontend_node);
setModalOpen(closeModal);
setValue(inputValue);
if (field_name !== "") {
apiReturn.data.frontend_node["template"][field_name]["value"] =
inputValue;
}
} else { } else {
setIsEdit(false);
setSuccessData({
title: "Prompt is ready",
});
if ( if (
JSON.stringify(apiReturn.data?.frontend_node) !== JSON.stringify(apiReturn.data?.frontend_node) !==
JSON.stringify({}) JSON.stringify({})
) ) {
setNodeClass!(apiReturn.data?.frontend_node); setNodeClass!(apiReturn.data?.frontend_node);
setModalOpen(closeModal); setModalOpen(closeModal);
setValue(inputValue); setValue(inputValue);
if (field_name !== "") { setIsEdit(false);
apiReturn.data.frontend_node["template"][field_name]["value"] = setSuccessData({
inputValue; title: "Prompt is ready",
});
} }
} }
} else { } else {