feat (GenericNode): replace validation with SSE validation
This commit is contained in:
parent
eaae1dda27
commit
68288be80e
1 changed files with 15 additions and 36 deletions
|
|
@ -33,6 +33,8 @@ import { NodeToolbar } from "reactflow";
|
||||||
import NodeToolbarComponent from "../../pages/FlowPage/components/nodeToolbarComponent";
|
import NodeToolbarComponent from "../../pages/FlowPage/components/nodeToolbarComponent";
|
||||||
|
|
||||||
import ShadTooltip from "../../components/ShadTooltipComponent";
|
import ShadTooltip from "../../components/ShadTooltipComponent";
|
||||||
|
import { useSSE } from "../../contexts/SSEContext";
|
||||||
|
|
||||||
export default function GenericNode({
|
export default function GenericNode({
|
||||||
data,
|
data,
|
||||||
selected,
|
selected,
|
||||||
|
|
@ -48,45 +50,22 @@ export default function GenericNode({
|
||||||
const Icon = nodeIcons[data.type] || nodeIcons[types[data.type]];
|
const Icon = nodeIcons[data.type] || nodeIcons[types[data.type]];
|
||||||
const [validationStatus, setValidationStatus] = useState(null);
|
const [validationStatus, setValidationStatus] = useState(null);
|
||||||
// State for outline color
|
// State for outline color
|
||||||
const [isValid, setIsValid] = useState(false);
|
const { sseData } = useSSE();
|
||||||
const { save } = useContext(TabsContext);
|
|
||||||
const { reactFlowInstance } = useContext(typesContext);
|
|
||||||
const [params, setParams] = useState([]);
|
|
||||||
|
|
||||||
|
// useEffect(() => {
|
||||||
|
// if (reactFlowInstance) {
|
||||||
|
// setParams(Object.values(reactFlowInstance.toObject()));
|
||||||
|
// }
|
||||||
|
// }, [save]);
|
||||||
|
|
||||||
|
// New useEffect to watch for changes in sseData and update validation status
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (reactFlowInstance) {
|
const relevantData = sseData[data.id];
|
||||||
setParams(Object.values(reactFlowInstance.toObject()));
|
if (relevantData) {
|
||||||
|
// Extract validation information from relevantData and update the validationStatus state
|
||||||
|
setValidationStatus(relevantData);
|
||||||
}
|
}
|
||||||
}, [save]);
|
}, [sseData, data.id]);
|
||||||
|
|
||||||
const validateNode = useCallback(
|
|
||||||
debounce(async () => {
|
|
||||||
try {
|
|
||||||
const response = await fetch(`/validate/node/${data.id}`, {
|
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
body: JSON.stringify(reactFlowInstance.toObject()),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.status === 200) {
|
|
||||||
let jsonResponse = await response.json();
|
|
||||||
let jsonResponseParsed = await JSON.parse(jsonResponse);
|
|
||||||
setValidationStatus(jsonResponseParsed);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
// console.error("Error validating node:", error);
|
|
||||||
setValidationStatus("error");
|
|
||||||
}
|
|
||||||
}, 1000), // Adjust the debounce delay (500ms) as needed
|
|
||||||
[reactFlowInstance, data.id]
|
|
||||||
);
|
|
||||||
useEffect(() => {
|
|
||||||
if (params.length > 0) {
|
|
||||||
validateNode();
|
|
||||||
}
|
|
||||||
}, [params, validateNode]);
|
|
||||||
|
|
||||||
if (!Icon) {
|
if (!Icon) {
|
||||||
if (showError.current) {
|
if (showError.current) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue