Fixed bug where the node internals are not updated at the PromptTemplate
This commit is contained in:
parent
dadaaa895d
commit
18b2226b12
1 changed files with 13 additions and 8 deletions
|
|
@ -6,6 +6,8 @@ import { TypeModal } from "../../utils";
|
|||
import { INPUT_STYLE } from "../../constants";
|
||||
import { ExternalLink } from "lucide-react";
|
||||
import { postValidatePrompt } from "../../controllers/API";
|
||||
import { typesContext } from "../../contexts/typesContext";
|
||||
import * as _ from "lodash";
|
||||
|
||||
export default function PromptAreaComponent({
|
||||
setNodeClass,
|
||||
|
|
@ -15,8 +17,10 @@ export default function PromptAreaComponent({
|
|||
disabled,
|
||||
editNode = false,
|
||||
}: TextAreaComponentType) {
|
||||
const [myValue, setMyValue] = useState(value);
|
||||
const [myValue, setMyValue] = useState("");
|
||||
const { openPopUp } = useContext(PopUpContext);
|
||||
const { reactFlowInstance } = useContext(typesContext);
|
||||
|
||||
useEffect(() => {
|
||||
if (disabled) {
|
||||
setMyValue("");
|
||||
|
|
@ -25,20 +29,21 @@ export default function PromptAreaComponent({
|
|||
}, [disabled, onChange]);
|
||||
|
||||
useEffect(() => {
|
||||
if (value) {
|
||||
postValidatePrompt(myValue, nodeClass)
|
||||
if (value !== "") { // only executed once
|
||||
setMyValue(value);
|
||||
postValidatePrompt(value, nodeClass)
|
||||
.then((apiReturn) => {
|
||||
if (apiReturn.data) {
|
||||
setNodeClass(apiReturn.data.frontend_node);
|
||||
if(reactFlowInstance){
|
||||
// need to update reactFlowInstance to re-render the nodes.
|
||||
reactFlowInstance.setEdges(_.cloneDeep(reactFlowInstance.getEdges()));
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch((error) => {});
|
||||
}
|
||||
}, [value]);
|
||||
|
||||
useEffect(() => {
|
||||
setMyValue(value);
|
||||
}, [value]);
|
||||
}, [reactFlowInstance]);
|
||||
|
||||
return (
|
||||
<div
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue