This commit is contained in:
Cristhian Zanforlin Lousa 2023-09-27 23:51:29 -03:00
commit 3f964ea60b
4 changed files with 28 additions and 24 deletions

View file

@ -529,7 +529,7 @@ export const URL_EXCLUDED_FROM_ERROR_RETRIES = [
"http://localhost:7860/login", "http://localhost:7860/login",
]; ];
export const skipNodeUpdate = ["CustomComponent"]; export const skipNodeUpdate = ["CustomComponent", "PromptTemplate"];
export const CONTROL_INPUT_STATE = { export const CONTROL_INPUT_STATE = {
password: "", password: "",

View file

@ -33,6 +33,7 @@ export default function GenericModal({
}: genericModalPropsType): JSX.Element { }: genericModalPropsType): JSX.Element {
const [myButtonText] = useState(buttonText); const [myButtonText] = useState(buttonText);
const [myModalTitle] = useState(modalTitle); const [myModalTitle] = useState(modalTitle);
const [modalOpen, setModalOpen] = useState(false);
const [myModalType] = useState(type); const [myModalType] = useState(type);
const [inputValue, setInputValue] = useState(value); const [inputValue, setInputValue] = useState(value);
const [isEdit, setIsEdit] = useState(true); const [isEdit, setIsEdit] = useState(true);
@ -85,7 +86,7 @@ export default function GenericModal({
useEffect(() => { useEffect(() => {
setInputValue(value); setInputValue(value);
}, [value]); }, [value, modalOpen]);
const coloredContent = (inputValue || "") const coloredContent = (inputValue || "")
.replace(/</g, "&lt;") .replace(/</g, "&lt;")
@ -109,11 +110,6 @@ export default function GenericModal({
postValidatePrompt(field_name, inputValue, nodeClass!) postValidatePrompt(field_name, inputValue, nodeClass!)
.then((apiReturn) => { .then((apiReturn) => {
if (apiReturn.data) { if (apiReturn.data) {
setValue(inputValue);
apiReturn.data.frontend_node["template"]["template"]["value"] =
inputValue;
setNodeClass!(apiReturn?.data?.frontend_node);
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);
@ -121,6 +117,15 @@ export default function GenericModal({
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);
apiReturn.data.frontend_node["template"]["template"]["value"] =
inputValue;
} else { } else {
setIsEdit(false); setIsEdit(false);
setSuccessData({ setSuccessData({
@ -133,6 +138,8 @@ export default function GenericModal({
setNodeClass!(apiReturn.data?.frontend_node); setNodeClass!(apiReturn.data?.frontend_node);
setModalOpen(closeModal); setModalOpen(closeModal);
setValue(inputValue); setValue(inputValue);
apiReturn.data.frontend_node["template"]["template"]["value"] =
inputValue;
} }
} else { } else {
setIsEdit(true); setIsEdit(true);
@ -142,16 +149,15 @@ export default function GenericModal({
} }
}) })
.catch((error) => { .catch((error) => {
console.log(error);
setIsEdit(true); setIsEdit(true);
return setErrorData({ return setErrorData({
title: "There is something wrong with this prompt, please review it", title: "There is something wrong with this prompt, please review it",
list: [error?.response?.data?.detail], list: [error.toString()],
}); });
}); });
} }
const [modalOpen, setModalOpen] = useState(false);
return ( return (
<BaseModal <BaseModal
onChangeOpenModal={(open) => {}} onChangeOpenModal={(open) => {}}

View file

@ -114,13 +114,11 @@ export default function Page({
} }
} }
if (!isWrappedWithClass(event, "nodelete")) { if (!isWrappedWithClass(event, "nodelete")) {
console.log(event);
if ( if (
(event.key === "Delete" || event.key === "Backspace") && (event.key === "Delete" || event.key === "Backspace") &&
lastSelection lastSelection
) { ) {
event.preventDefault(); event.preventDefault();
console.log(lastSelection);
deleteNode(lastSelection.nodes.map((node) => node.id)); deleteNode(lastSelection.nodes.map((node) => node.id));
} }
} }