is validConnection migration done
This commit is contained in:
parent
3cb2548614
commit
81f25662f1
4 changed files with 49 additions and 46 deletions
|
|
@ -21,9 +21,11 @@ import {
|
||||||
classNames,
|
classNames,
|
||||||
getRandomKeyByssmm,
|
getRandomKeyByssmm,
|
||||||
groupByFamily,
|
groupByFamily,
|
||||||
isValidConnection,
|
|
||||||
} from "../../../../utils";
|
} from "../../../../utils";
|
||||||
import { cleanEdges } from "../../../../utils/reactflowUtils";
|
import {
|
||||||
|
cleanEdges,
|
||||||
|
isValidConnection,
|
||||||
|
} from "../../../../utils/reactflowUtils";
|
||||||
import {
|
import {
|
||||||
nodeColors,
|
nodeColors,
|
||||||
nodeIconsLucide,
|
nodeIconsLucide,
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import { typesContext } from "../../../../contexts/typesContext";
|
||||||
import { undoRedoContext } from "../../../../contexts/undoRedoContext";
|
import { undoRedoContext } from "../../../../contexts/undoRedoContext";
|
||||||
import { APIClassType } from "../../../../types/api";
|
import { APIClassType } from "../../../../types/api";
|
||||||
import { FlowType, NodeType } from "../../../../types/flow";
|
import { FlowType, NodeType } from "../../../../types/flow";
|
||||||
import { isValidConnection } from "../../../../utils";
|
import { isValidConnection } from "../../../../utils/reactflowUtils";
|
||||||
import ConnectionLineComponent from "../ConnectionLineComponent";
|
import ConnectionLineComponent from "../ConnectionLineComponent";
|
||||||
import ExtraSidebar from "../extraSidebarComponent";
|
import ExtraSidebar from "../extraSidebarComponent";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import clsx, { ClassValue } from "clsx";
|
import clsx, { ClassValue } from "clsx";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { Connection, ReactFlowInstance } from "reactflow";
|
import { ReactFlowInstance } from "reactflow";
|
||||||
import { twMerge } from "tailwind-merge";
|
import { twMerge } from "tailwind-merge";
|
||||||
import { ADJECTIVES, DESCRIPTIONS, NOUNS } from "./flow_constants";
|
import { ADJECTIVES, DESCRIPTIONS, NOUNS } from "./flow_constants";
|
||||||
import { APITemplateType } from "./types/api";
|
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);
|
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 {
|
export function removeApiKeys(flow: FlowType): FlowType {
|
||||||
let cleanFLow = _.cloneDeep(flow);
|
let cleanFLow = _.cloneDeep(flow);
|
||||||
cleanFLow.data.nodes.forEach((node) => {
|
cleanFLow.data.nodes.forEach((node) => {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
|
import { Connection, ReactFlowInstance } from "reactflow";
|
||||||
import { cleanEdgesType } from "../types/utils/reactflowUtils";
|
import { cleanEdgesType } from "../types/utils/reactflowUtils";
|
||||||
|
|
||||||
export function cleanEdges({
|
export function cleanEdges({
|
||||||
|
|
@ -44,3 +45,45 @@ export function cleanEdges({
|
||||||
});
|
});
|
||||||
updateEdge(newEdges);
|
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;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue