From 144fdbd09810668c1d4c3952774e6d86bc0026de Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Thu, 14 Sep 2023 14:18:30 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(parameterComponent):=20fix?= =?UTF-8?q?=20data=20mutation=20by=20cloning=20data=20object=20before=20up?= =?UTF-8?q?dating=20it=20=F0=9F=90=9B=20fix(parameterComponent):=20fix=20d?= =?UTF-8?q?ata=20mutation=20by=20cloning=20data=20object=20before=20updati?= =?UTF-8?q?ng=20it=20=F0=9F=90=9B=20fix(genericModal):=20remove=20unnecess?= =?UTF-8?q?ary=20cloning=20of=20nodeClass=20object=20=F0=9F=90=9B=20fix(ge?= =?UTF-8?q?nericModal):=20fix=20validation=20logic=20for=20PROMPT=20type?= =?UTF-8?q?=20modal=20=F0=9F=90=9B=20fix(reactflowUtils):=20remove=20conso?= =?UTF-8?q?le.log=20statement=20in=20handleKeyDown=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/parameterComponent/index.tsx | 7 ++++++- .../src/modals/genericModal/index.tsx | 21 ++++++++----------- src/frontend/src/utils/reactflowUtils.ts | 8 +++---- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index 72c2a8e4d..dca4866d1 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -321,11 +321,16 @@ export default function ParameterComponent({ field_name={name} setNodeClass={(nodeClass) => { data.node = nodeClass; + const clone = cloneDeep(data); + clone.node = nodeClass; + setData(clone); }} nodeClass={data.node} disabled={disabled} value={data.node.template[name].value ?? ""} - onChange={handleOnNewValue} + onChange={(e) => { + handleOnNewValue(e); + }} /> ) : ( diff --git a/src/frontend/src/modals/genericModal/index.tsx b/src/frontend/src/modals/genericModal/index.tsx index 9175cac07..5935e2184 100644 --- a/src/frontend/src/modals/genericModal/index.tsx +++ b/src/frontend/src/modals/genericModal/index.tsx @@ -1,4 +1,3 @@ -import { cloneDeep } from "lodash"; import { ReactNode, useContext, useEffect, useRef, useState } from "react"; import SanitizedHTMLWrapper from "../../components/SanitizedHTMLWrapper"; import ShadTooltip from "../../components/ShadTooltipComponent"; @@ -133,21 +132,21 @@ export default function GenericModal({ function validatePrompt(closeModal: boolean): void { //nodeClass is always null on tweaks - if (nodeClass) { - const nodeClassCp = cloneDeep(nodeClass); - nodeClassCp["template"]["template"]["value"] = inputValue; - nodeClass = nodeClassCp; - } + postValidatePrompt(field_name, inputValue, nodeClass!) .then((apiReturn) => { if (apiReturn.data) { + setValue(inputValue); + apiReturn.data.frontend_node["template"]["template"]["value"] = + inputValue; + setNodeClass!(apiReturn?.data?.frontend_node); + let inputVariables = apiReturn.data.input_variables ?? []; if (inputVariables && inputVariables.length === 0) { setIsEdit(true); setNoticeData({ title: "Your template does not have any variables.", }); - setNodeClass!(apiReturn?.data?.frontend_node); setModalOpen(closeModal); } else { setIsEdit(false); @@ -157,9 +156,9 @@ export default function GenericModal({ if ( JSON.stringify(apiReturn.data?.frontend_node) !== JSON.stringify({}) - ) + ) { setModalOpen(closeModal); - setValue(inputValue); + } } } else { setIsEdit(true); @@ -306,9 +305,7 @@ export default function GenericModal({ setModalOpen(false); break; case TypeModal.PROMPT: - !inputValue || inputValue === "" - ? setModalOpen(false) - : validatePrompt(false); + validatePrompt(false); break; default: diff --git a/src/frontend/src/utils/reactflowUtils.ts b/src/frontend/src/utils/reactflowUtils.ts index 9a42c5f04..d21028c70 100644 --- a/src/frontend/src/utils/reactflowUtils.ts +++ b/src/frontend/src/utils/reactflowUtils.ts @@ -200,10 +200,9 @@ export function validateNode( e.targetHandle.split("|")[2] === n.id ) ? [ - `${type} is missing ${ - template.display_name || toNormalCase(template[t].name) - }.`, - ] + `${type} is missing ${template.display_name || toNormalCase(template[t].name) + }.`, + ] : [] ), [] as string[] @@ -239,7 +238,6 @@ export function handleKeyDown( inputValue: string | string[] | null, block: string ) { - console.log(e, inputValue, block); //condition to fix bug control+backspace on Windows/Linux if ( (typeof inputValue === "string" &&