fix(sockets): redrawing edges should not lead to socket ops by icecrasher321 · Pull Request #2804 · simstudioai/sim · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions apps/sim/hooks/use-collaborative-workflow.ts
14 changes: 14 additions & 0 deletions apps/sim/stores/workflows/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
import type { Edge } from 'reactflow'
import { v4 as uuidv4 } from 'uuid'

export function filterNewEdges(edgesToAdd: Edge[], currentEdges: Edge[]): Edge[] {
return edgesToAdd.filter((edge) => {
if (edge.source === edge.target) return false
return !currentEdges.some(
(e) =>
e.source === edge.source &&
e.sourceHandle === edge.sourceHandle &&
e.target === edge.target &&
e.targetHandle === edge.targetHandle
)
})
}

import { getBlockOutputs } from '@/lib/workflows/blocks/block-outputs'
import { getBlock } from '@/blocks'
import { normalizeName } from '@/executor/constants'
Expand Down
13 changes: 1 addition & 12 deletions apps/sim/stores/workflows/workflow/store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ describe('workflow store', () => {
expectEdgeConnects(edges, 'block-1', 'block-2')
})

it('should not add duplicate edges', () => {
it('should not add duplicate connections', () => {
const { addBlock, batchAddEdges } = useWorkflowStore.getState()

addBlock('block-1', 'starter', 'Start', { x: 0, y: 0 })
Expand All @@ -309,17 +309,6 @@ describe('workflow store', () => {
const state = useWorkflowStore.getState()
expectEdgeCount(state, 1)
})

it('should prevent self-referencing edges', () => {
const { addBlock, batchAddEdges } = useWorkflowStore.getState()

addBlock('block-1', 'function', 'Self', { x: 0, y: 0 })

batchAddEdges([{ id: 'e1', source: 'block-1', target: 'block-1' }])

const state = useWorkflowStore.getState()
expectEdgeCount(state, 0)
})
})

describe('batchRemoveEdges', () => {
Expand Down
30 changes: 8 additions & 22 deletions apps/sim/stores/workflows/workflow/store.ts