Skip to content

Commit

Permalink
Clean up isValidConnection
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Ohlsen <[email protected]>
  • Loading branch information
ohltyler committed Oct 4, 2023
1 parent 303c70e commit 8288542
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions public/pages/workflow_detail/workspace_component/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,23 @@ export function isValidConnection(
const sourceHandle = connection.sourceHandle;
const targetHandle = connection.targetHandle;
const targetNodeId = connection.target;
const inputClass = sourceHandle || '';

// We store the output classes in a pipe-delimited string. Converting back to a list.
const outputClasses = targetHandle?.split('|') || [];
const sourceClasses = sourceHandle?.split('|') || [];
const targetClass = targetHandle || '';

if (outputClasses?.includes(inputClass)) {
if (sourceClasses?.includes(targetClass)) {
const targetNode = rfInstance.getNode(targetNodeId || '');
if (targetNode) {
const inputConfig = targetNode.data.inputs.find(
(input: IComponentInput) => input.baseClass === inputClass
(input: IComponentInput) => sourceClasses.includes(input.baseClass)
) as IComponentInput;
const existingEdge = rfInstance
.getEdges()
.find((edge) => edge.targetHandle === targetHandle);
.find(
(edge) =>
edge.target === targetNodeId && edge.targetHandle === targetHandle
);
if (existingEdge && inputConfig.acceptMultiple === false) {
return false;
}
Expand Down

0 comments on commit 8288542

Please sign in to comment.