migrate isValidConnection to handle in JSON format

This commit is contained in:
anovazzi1 2023-08-02 22:23:16 -03:00
commit db473f6f0d

View file

@ -57,25 +57,21 @@ export function cleanEdges({
updateEdge(newEdges); updateEdge(newEdges);
} }
// add comments to this function
export function isValidConnection( export function isValidConnection(
{ source, target, sourceHandle, targetHandle }: Connection, { source, target, sourceHandle, targetHandle }: Connection,
reactFlowInstance: ReactFlowInstance reactFlowInstance: ReactFlowInstance
) { ) {
const targetHandleObject: targetHandleType = JSON.parse(targetHandle);
const sourceHandleObject: sourceHandleType = JSON.parse(sourceHandle);
if ( if (
targetHandle targetHandleObject.inputTypes?.some(
.split("|")[0] (n) => n === sourceHandleObject.dataType
.split(";") ) ||
.some((n) => n === sourceHandle.split("|")[0]) || sourceHandleObject.baseClasses.some((t) =>
sourceHandle targetHandleObject.inputTypes?.some((n) => n === t)
.split("|") ) ||
.slice(2) targetHandleObject.type === "str"
.some((t) =>
targetHandle
.split("|")[0]
.split(";")
.some((n) => n === t)
) ||
targetHandle.split("|")[0] === "str"
) { ) {
let targetNode = reactFlowInstance?.getNode(target)?.data?.node; let targetNode = reactFlowInstance?.getNode(target)?.data?.node;
if (!targetNode) { if (!targetNode) {
@ -87,11 +83,11 @@ export function isValidConnection(
return true; return true;
} }
} else if ( } else if (
(!targetNode.template[targetHandle.split("|")[1]].list && (!targetNode.template[targetHandleObject.fieldName].list &&
!reactFlowInstance !reactFlowInstance
.getEdges() .getEdges()
.find((e) => e.targetHandle === targetHandle)) || .find((e) => e.targetHandle === targetHandle)) ||
targetNode.template[targetHandle.split("|")[1]].list targetNode.template[targetHandleObject.fieldName].list
) { ) {
return true; return true;
} }