is validConnection migration done

This commit is contained in:
anovazzi1 2023-07-13 18:25:37 -03:00
commit 81f25662f1
4 changed files with 49 additions and 46 deletions

View file

@ -21,9 +21,11 @@ import {
classNames,
getRandomKeyByssmm,
groupByFamily,
isValidConnection,
} from "../../../../utils";
import { cleanEdges } from "../../../../utils/reactflowUtils";
import {
cleanEdges,
isValidConnection,
} from "../../../../utils/reactflowUtils";
import {
nodeColors,
nodeIconsLucide,

View file

@ -26,7 +26,7 @@ import { typesContext } from "../../../../contexts/typesContext";
import { undoRedoContext } from "../../../../contexts/undoRedoContext";
import { APIClassType } from "../../../../types/api";
import { FlowType, NodeType } from "../../../../types/flow";
import { isValidConnection } from "../../../../utils";
import { isValidConnection } from "../../../../utils/reactflowUtils";
import ConnectionLineComponent from "../ConnectionLineComponent";
import ExtraSidebar from "../extraSidebarComponent";

View file

@ -1,6 +1,6 @@
import clsx, { ClassValue } from "clsx";
import _ from "lodash";
import { Connection, ReactFlowInstance } from "reactflow";
import { ReactFlowInstance } from "reactflow";
import { twMerge } from "tailwind-merge";
import { ADJECTIVES, DESCRIPTIONS, NOUNS } from "./flow_constants";
import { APITemplateType } from "./types/api";
@ -74,48 +74,6 @@ export function roundNumber(x: number, decimals: number) {
return Math.round(x * Math.pow(10, decimals)) / Math.pow(10, decimals);
}
export function isValidConnection(
{ source, target, sourceHandle, targetHandle }: Connection,
reactFlowInstance: ReactFlowInstance
) {
if (
targetHandle
.split("|")[0]
.split(";")
.some((n) => n === sourceHandle.split("|")[0]) ||
sourceHandle
.split("|")
.slice(2)
.some((t) =>
targetHandle
.split("|")[0]
.split(";")
.some((n) => n === t)
) ||
targetHandle.split("|")[0] === "str"
) {
let targetNode = reactFlowInstance?.getNode(target)?.data?.node;
if (!targetNode) {
if (
!reactFlowInstance
.getEdges()
.find((e) => e.targetHandle === targetHandle)
) {
return true;
}
} else if (
(!targetNode.template[targetHandle.split("|")[1]].list &&
!reactFlowInstance
.getEdges()
.find((e) => e.targetHandle === targetHandle)) ||
targetNode.template[targetHandle.split("|")[1]].list
) {
return true;
}
}
return false;
}
export function removeApiKeys(flow: FlowType): FlowType {
let cleanFLow = _.cloneDeep(flow);
cleanFLow.data.nodes.forEach((node) => {

View file

@ -1,4 +1,5 @@
import _ from "lodash";
import { Connection, ReactFlowInstance } from "reactflow";
import { cleanEdgesType } from "../types/utils/reactflowUtils";
export function cleanEdges({
@ -44,3 +45,45 @@ export function cleanEdges({
});
updateEdge(newEdges);
}
export function isValidConnection(
{ source, target, sourceHandle, targetHandle }: Connection,
reactFlowInstance: ReactFlowInstance
) {
if (
targetHandle
.split("|")[0]
.split(";")
.some((n) => n === sourceHandle.split("|")[0]) ||
sourceHandle
.split("|")
.slice(2)
.some((t) =>
targetHandle
.split("|")[0]
.split(";")
.some((n) => n === t)
) ||
targetHandle.split("|")[0] === "str"
) {
let targetNode = reactFlowInstance?.getNode(target)?.data?.node;
if (!targetNode) {
if (
!reactFlowInstance
.getEdges()
.find((e) => e.targetHandle === targetHandle)
) {
return true;
}
} else if (
(!targetNode.template[targetHandle.split("|")[1]].list &&
!reactFlowInstance
.getEdges()
.find((e) => e.targetHandle === targetHandle)) ||
targetNode.template[targetHandle.split("|")[1]].list
) {
return true;
}
}
return false;
}