fix(sockets): redrawing edges should not lead to socket ops (#2804) · simstudioai/sim@e3fa40a · GitHub
Skip to content

Commit e3fa40a

Browse files
fix(sockets): redrawing edges should not lead to socket ops (#2804)
* fix(sockets): redrawing edges should not lead to socket ops * consolidate
1 parent 6e0055f commit e3fa40a

4 files changed

Lines changed: 34 additions & 39 deletions

File tree

apps/sim/hooks/use-collaborative-workflow.ts

Lines changed: 11 additions & 5 deletions

apps/sim/stores/workflows/utils.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
import type { Edge } from 'reactflow'
22
import { v4 as uuidv4 } from 'uuid'
3+
4+
export function filterNewEdges(edgesToAdd: Edge[], currentEdges: Edge[]): Edge[] {
5+
return edgesToAdd.filter((edge) => {
6+
if (edge.source === edge.target) return false
7+
return !currentEdges.some(
8+
(e) =>
9+
e.source === edge.source &&
10+
e.sourceHandle === edge.sourceHandle &&
11+
e.target === edge.target &&
12+
e.targetHandle === edge.targetHandle
13+
)
14+
})
15+
}
16+
317
import { getBlockOutputs } from '@/lib/workflows/blocks/block-outputs'
418
import { getBlock } from '@/blocks'
519
import { normalizeName } from '@/executor/constants'

apps/sim/stores/workflows/workflow/store.test.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ describe('workflow store', () => {
297297
expectEdgeConnects(edges, 'block-1', 'block-2')
298298
})
299299

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

303303
addBlock('block-1', 'starter', 'Start', { x: 0, y: 0 })
@@ -309,17 +309,6 @@ describe('workflow store', () => {
309309
const state = useWorkflowStore.getState()
310310
expectEdgeCount(state, 1)
311311
})
312-
313-
it('should prevent self-referencing edges', () => {
314-
const { addBlock, batchAddEdges } = useWorkflowStore.getState()
315-
316-
addBlock('block-1', 'function', 'Self', { x: 0, y: 0 })
317-
318-
batchAddEdges([{ id: 'e1', source: 'block-1', target: 'block-1' }])
319-
320-
const state = useWorkflowStore.getState()
321-
expectEdgeCount(state, 0)
322-
})
323312
})
324313

325314
describe('batchRemoveEdges', () => {

apps/sim/stores/workflows/workflow/store.ts

Lines changed: 8 additions & 22 deletions

0 commit comments

Comments
 (0)