Skip to content

Commit 8460181

Browse files
committed
ack PR comment
1 parent 61d96ad commit 8460181

File tree

2 files changed

+27
-37
lines changed

2 files changed

+27
-37
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/workflow-block.tsx

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import { useSelectorDisplayName } from '@/hooks/use-selector-display-name'
4040
import { useVariablesStore } from '@/stores/panel/variables/store'
4141
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
4242
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
43+
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
44+
import { wouldCreateCycle } from '@/stores/workflows/workflow/utils'
4345

4446
const logger = createLogger('WorkflowBlock')
4547

@@ -844,7 +846,11 @@ export const WorkflowBlock = memo(function WorkflowBlock({
844846
data-handleid='target'
845847
isConnectableStart={false}
846848
isConnectableEnd={true}
847-
isValidConnection={(connection) => connection.source !== id}
849+
isValidConnection={(connection) => {
850+
if (connection.source === id) return false
851+
const edges = useWorkflowStore.getState().edges
852+
return !wouldCreateCycle(edges, connection.source!, connection.target!)
853+
}}
848854
/>
849855
)}
850856

@@ -1045,7 +1051,11 @@ export const WorkflowBlock = memo(function WorkflowBlock({
10451051
data-handleid={`condition-${cond.id}`}
10461052
isConnectableStart={true}
10471053
isConnectableEnd={false}
1048-
isValidConnection={(connection) => connection.target !== id}
1054+
isValidConnection={(connection) => {
1055+
if (connection.target === id) return false
1056+
const edges = useWorkflowStore.getState().edges
1057+
return !wouldCreateCycle(edges, connection.source!, connection.target!)
1058+
}}
10491059
/>
10501060
)
10511061
})}
@@ -1064,7 +1074,11 @@ export const WorkflowBlock = memo(function WorkflowBlock({
10641074
data-handleid='error'
10651075
isConnectableStart={true}
10661076
isConnectableEnd={false}
1067-
isValidConnection={(connection) => connection.target !== id}
1077+
isValidConnection={(connection) => {
1078+
if (connection.target === id) return false
1079+
const edges = useWorkflowStore.getState().edges
1080+
return !wouldCreateCycle(edges, connection.source!, connection.target!)
1081+
}}
10681082
/>
10691083
</>
10701084
)}
@@ -1081,7 +1095,11 @@ export const WorkflowBlock = memo(function WorkflowBlock({
10811095
data-handleid='source'
10821096
isConnectableStart={true}
10831097
isConnectableEnd={false}
1084-
isValidConnection={(connection) => connection.target !== id}
1098+
isValidConnection={(connection) => {
1099+
if (connection.target === id) return false
1100+
const edges = useWorkflowStore.getState().edges
1101+
return !wouldCreateCycle(edges, connection.source!, connection.target!)
1102+
}}
10851103
/>
10861104

10871105
{shouldShowDefaultHandles && (
@@ -1100,7 +1118,11 @@ export const WorkflowBlock = memo(function WorkflowBlock({
11001118
data-handleid='error'
11011119
isConnectableStart={true}
11021120
isConnectableEnd={false}
1103-
isValidConnection={(connection) => connection.target !== id}
1121+
isValidConnection={(connection) => {
1122+
if (connection.target === id) return false
1123+
const edges = useWorkflowStore.getState().edges
1124+
return !wouldCreateCycle(edges, connection.source!, connection.target!)
1125+
}}
11041126
/>
11051127
)}
11061128
</>

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ import { useWorkflowDiffStore } from '@/stores/workflow-diff/store'
5656
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
5757
import { getUniqueBlockName } from '@/stores/workflows/utils'
5858
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
59-
import { wouldCreateCycle } from '@/stores/workflows/workflow/utils'
6059

6160
/** Lazy-loaded components for non-critical UI that can load after initial render */
6261
const LazyChat = lazy(() =>
@@ -1639,40 +1638,10 @@ const WorkflowContent = React.memo(() => {
16391638
setIsErrorConnectionDrag(false)
16401639
}, [])
16411640

1642-
/**
1643-
* Validates if a connection is allowed before it's created.
1644-
* Prevents cycles and other invalid connections.
1645-
*/
1646-
const isValidConnection = useCallback(
1647-
(connection: { source: string | null; target: string | null }) => {
1648-
if (!connection.source || !connection.target) {
1649-
return false
1650-
}
1651-
1652-
if (connection.source === connection.target) {
1653-
return false
1654-
}
1655-
1656-
const currentEdges = useWorkflowStore.getState().edges
1657-
1658-
if (wouldCreateCycle(currentEdges, connection.source, connection.target)) {
1659-
return false
1660-
}
1661-
1662-
return true
1663-
},
1664-
[]
1665-
)
1666-
16671641
/** Handles new edge connections with container boundary validation. */
16681642
const onConnect = useCallback(
16691643
(connection: any) => {
16701644
if (connection.source && connection.target) {
1671-
// Prevent self-connections
1672-
if (connection.source === connection.target) {
1673-
return
1674-
}
1675-
16761645
// Check if connecting nodes across container boundaries
16771646
const sourceNode = getNodes().find((n) => n.id === connection.source)
16781647
const targetNode = getNodes().find((n) => n.id === connection.target)
@@ -2275,7 +2244,6 @@ const WorkflowContent = React.memo(() => {
22752244
onConnect={effectivePermissions.canEdit ? onConnect : undefined}
22762245
onConnectStart={effectivePermissions.canEdit ? onConnectStart : undefined}
22772246
onConnectEnd={effectivePermissions.canEdit ? onConnectEnd : undefined}
2278-
isValidConnection={effectivePermissions.canEdit ? isValidConnection : undefined}
22792247
nodeTypes={nodeTypes}
22802248
edgeTypes={edgeTypes}
22812249
onDrop={effectivePermissions.canEdit ? onDrop : undefined}

0 commit comments

Comments
 (0)