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 { INPUT_STYLE } from "../../constants";
|
||||||
import { ExternalLink } from "lucide-react";
|
import { ExternalLink } from "lucide-react";
|
||||||
import { postValidatePrompt } from "../../controllers/API";
|
import { postValidatePrompt } from "../../controllers/API";
|
||||||
|
import { typesContext } from "../../contexts/typesContext";
|
||||||
|
import * as _ from "lodash";
|
||||||
|
|
||||||
export default function PromptAreaComponent({
|
export default function PromptAreaComponent({
|
||||||
setNodeClass,
|
setNodeClass,
|
||||||
|
|
@ -15,8 +17,10 @@ export default function PromptAreaComponent({
|
||||||
disabled,
|
disabled,
|
||||||
editNode = false,
|
editNode = false,
|
||||||
}: TextAreaComponentType) {
|
}: TextAreaComponentType) {
|
||||||
const [myValue, setMyValue] = useState(value);
|
const [myValue, setMyValue] = useState("");
|
||||||
const { openPopUp } = useContext(PopUpContext);
|
const { openPopUp } = useContext(PopUpContext);
|
||||||
|
const { reactFlowInstance } = useContext(typesContext);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (disabled) {
|
if (disabled) {
|
||||||
setMyValue("");
|
setMyValue("");
|
||||||
|
|
@ -25,20 +29,21 @@ export default function PromptAreaComponent({
|
||||||
}, [disabled, onChange]);
|
}, [disabled, onChange]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (value) {
|
if (value !== "") { // only executed once
|
||||||
postValidatePrompt(myValue, nodeClass)
|
setMyValue(value);
|
||||||
|
postValidatePrompt(value, nodeClass)
|
||||||
.then((apiReturn) => {
|
.then((apiReturn) => {
|
||||||
if (apiReturn.data) {
|
if (apiReturn.data) {
|
||||||
setNodeClass(apiReturn.data.frontend_node);
|
setNodeClass(apiReturn.data.frontend_node);
|
||||||
|
if(reactFlowInstance){
|
||||||
|
// need to update reactFlowInstance to re-render the nodes.
|
||||||
|
reactFlowInstance.setEdges(_.cloneDeep(reactFlowInstance.getEdges()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {});
|
.catch((error) => {});
|
||||||
}
|
}
|
||||||
}, [value]);
|
}, [reactFlowInstance]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setMyValue(value);
|
|
||||||
}, [value]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue