Skip to content

Commit

Permalink
dont allow multiple connections to non flow sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuart Lee committed Oct 11, 2022
1 parent 648c6eb commit 5bb64b3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/components/InputSocket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ export default function InputSocket({
defaultValue,
}: InputSocketProps) {
const instance = useReactFlow();
const showFlowIcon = valueType === "flow";
const isFlowSocket = valueType === "flow";
const colorName = valueTypeColorMap[valueType];
const [backgroundColor, borderColor] = colors[colorName];
return (
<div className="flex grow items-center justify-start h-7">
{showFlowIcon && (
{isFlowSocket && (
<FontAwesomeIcon icon={faCaretRight} color="#ffffff" size="lg" />
)}
{showFlowIcon === false && (
{isFlowSocket === false && (
<>
<div className="capitalize mr-2">{name}</div>
{connected === false && (
Expand Down
6 changes: 3 additions & 3 deletions src/components/OutputSocket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ export default function OutputSocket({
name,
}: OutputSocketProps) {
const instance = useReactFlow();
const showFlowIcon = valueType === "flow";
const isFlowSocket = valueType === "flow";
const colorName = valueTypeColorMap[valueType];
const [backgroundColor, borderColor] = colors[colorName];

return (
<div className="flex grow items-center justify-end h-7">
{showFlowIcon && (
{isFlowSocket && (
<FontAwesomeIcon icon={faCaretRight} color="#ffffff" size="lg" />
)}
{showFlowIcon === false && <div className="capitalize">{name}</div>}
{isFlowSocket === false && <div className="capitalize">{name}</div>}
<Handle
id={name}
type="source"
Expand Down
10 changes: 10 additions & 0 deletions src/util/isValidConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Connection, ReactFlowInstance } from "react-flow-renderer/nocss";
import { getSocketsByNodeTypeAndHandleType } from "./getSocketsByNodeTypeAndHandleType";
import rawSpecJson from "behave-graph/dist/node-spec.json";
import { NodeSpecJSON } from "behave-graph";
import { isHandleConnected } from "./isHandleConnected";

const specJSON = rawSpecJson as NodeSpecJSON[];

Expand All @@ -13,6 +14,7 @@ export const isValidConnection = (

const sourceNode = instance.getNode(connection.source);
const targetNode = instance.getNode(connection.target);
const edges = instance.getEdges();

if (sourceNode === undefined || targetNode === undefined) return false;

Expand All @@ -38,5 +40,13 @@ export const isValidConnection = (

if (sourceSocket === undefined || targetSocket === undefined) return false;

// only flow sockets can have two inputs
if (
targetSocket.valueType !== "flow" &&
isHandleConnected(edges, targetNode.id, targetSocket.name, "target")
) {
return false;
}

return sourceSocket.valueType === targetSocket.valueType;
};

0 comments on commit 5bb64b3

Please sign in to comment.