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