mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-10 23:48:09 -05:00
Fix: edge connection logic (self-connect and duplicate connections)
This commit is contained in:
@@ -440,6 +440,11 @@ export function ConditionInput({ blockId, subBlockId, isConnecting }: ConditionI
|
||||
}}
|
||||
isConnectableStart={true}
|
||||
isConnectableEnd={false}
|
||||
isValidConnection={(connection) => {
|
||||
const sourceNodeId = connection.source?.split('-')[0]
|
||||
const targetNodeId = connection.target?.split('-')[0]
|
||||
return sourceNodeId !== targetNodeId
|
||||
}}
|
||||
/>
|
||||
<div className="flex items-center gap-1">
|
||||
<Tooltip>
|
||||
|
||||
@@ -191,6 +191,7 @@ export function WorkflowBlock({ id, data, selected }: NodeProps<WorkflowBlockPro
|
||||
data-handleid="target"
|
||||
isConnectableStart={false}
|
||||
isConnectableEnd={true}
|
||||
isValidConnection={(connection) => connection.source !== id}
|
||||
/>
|
||||
|
||||
{/* Block Header */}
|
||||
@@ -284,6 +285,7 @@ export function WorkflowBlock({ id, data, selected }: NodeProps<WorkflowBlockPro
|
||||
data-handleid="source"
|
||||
isConnectableStart={true}
|
||||
isConnectableEnd={false}
|
||||
isValidConnection={(connection) => connection.target !== id}
|
||||
/>
|
||||
)}
|
||||
</Card>
|
||||
|
||||
@@ -186,6 +186,20 @@ export const useWorkflowStore = create<WorkflowStoreWithHistory>()(
|
||||
},
|
||||
|
||||
addEdge: (edge: Edge) => {
|
||||
// Check for duplicate connections
|
||||
const isDuplicate = get().edges.some(
|
||||
(existingEdge) =>
|
||||
existingEdge.source === edge.source &&
|
||||
existingEdge.target === edge.target &&
|
||||
existingEdge.sourceHandle === edge.sourceHandle &&
|
||||
existingEdge.targetHandle === edge.targetHandle
|
||||
)
|
||||
|
||||
// If it's a duplicate connection, return early without adding the edge
|
||||
if (isDuplicate) {
|
||||
return
|
||||
}
|
||||
|
||||
const newEdge = {
|
||||
id: edge.id || crypto.randomUUID(),
|
||||
source: edge.source,
|
||||
|
||||
Reference in New Issue
Block a user