fixed validation
This commit is contained in:
parent
c3dffa3508
commit
f97586813c
2 changed files with 166 additions and 187 deletions
|
|
@ -62,5 +62,5 @@
|
|||
"last 1 safari version"
|
||||
]
|
||||
},
|
||||
"proxy": "http://backend:7860"
|
||||
"proxy": "http://127.0.0.1:7860"
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ import { useContext, useState, useEffect, useRef } from "react";
|
|||
import { NodeDataType } from "../../types/flow";
|
||||
import { alertContext } from "../../contexts/alertContext";
|
||||
import { useCallback } from "react";
|
||||
|
||||
import { TabsContext } from "../../contexts/tabsContext";
|
||||
export default function GenericNode({
|
||||
data,
|
||||
selected,
|
||||
|
|
@ -26,71 +26,50 @@ export default function GenericNode({
|
|||
const Icon = nodeIcons[types[data.type]];
|
||||
const [validationStatus, setValidationStatus] = useState("idle");
|
||||
// State for outline color
|
||||
const [isGreenOutline, setIsGreenOutline] = useState(false);
|
||||
const [isRedOutline, setIsRedOutline] = useState(false);
|
||||
const [isValid, setIsValid] = useState(false);
|
||||
const {save} = useContext(TabsContext)
|
||||
const { reactFlowInstance } = useContext(typesContext);
|
||||
const [params, setParams] = useState([]);
|
||||
|
||||
console.log();
|
||||
|
||||
useEffect(() => {
|
||||
if (reactFlowInstance) {
|
||||
setParams(Object.values(reactFlowInstance.toObject()));
|
||||
}
|
||||
}, [reactFlowInstance]);
|
||||
|
||||
const debouncedValidateNode = useDebouncedCallback(async () => {
|
||||
// Check if the validationStatus is "success"
|
||||
// if (validationStatus === "success") return;
|
||||
}, [save]);
|
||||
|
||||
useEffect(() => {
|
||||
try {
|
||||
const response = await fetch(`/validate/node/${data.id}`, {
|
||||
fetch(`/validate/node/${data.id}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(reactFlowInstance.toObject()),
|
||||
});
|
||||
}).then((response) => {
|
||||
console.log(response.status, response.body);
|
||||
|
||||
if (response.status === 200) {
|
||||
setValidationStatus("success");
|
||||
} else if (response.status === 500) {
|
||||
setValidationStatus("error");
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error validating node:", error);
|
||||
setValidationStatus("error");
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
const validateNode = useCallback(() => {
|
||||
debouncedValidateNode();
|
||||
}, [debouncedValidateNode]);
|
||||
|
||||
useEffect(() => {
|
||||
validateNode();
|
||||
}, [validateNode, params]);
|
||||
}, [params]);
|
||||
|
||||
useEffect(() => {
|
||||
if (validationStatus === "success") {
|
||||
setIsGreenOutline(true);
|
||||
setIsRedOutline(false);
|
||||
setTimeout(() => {
|
||||
setIsGreenOutline(false);
|
||||
}, 1000);
|
||||
} else if (validationStatus === "error") {
|
||||
setIsRedOutline(true);
|
||||
setIsGreenOutline(false);
|
||||
setIsValid(true);
|
||||
} else {
|
||||
setIsGreenOutline(false);
|
||||
setIsRedOutline(false);
|
||||
setIsValid(false);
|
||||
}
|
||||
}, [validationStatus]);
|
||||
|
||||
const outlineColor = isGreenOutline
|
||||
? "animate-pulse-green"
|
||||
: isRedOutline
|
||||
? "border-red-outline"
|
||||
: "";
|
||||
|
||||
if (!Icon) {
|
||||
if (showError.current) {
|
||||
setErrorData({
|
||||
|
|
@ -107,7 +86,7 @@ export default function GenericNode({
|
|||
return (
|
||||
<div
|
||||
className={classNames(
|
||||
outlineColor,
|
||||
isValid ? "animate-pulse-green" : "border-red-outline",
|
||||
selected ? "border border-blue-500" : "border dark:border-gray-700",
|
||||
"prompt-node relative bg-white dark:bg-gray-900 w-96 rounded-lg flex flex-col justify-center"
|
||||
)}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue