Skip to content

Commit 0bf817b

Browse files
committed
refactor(workflow): remove addBlock in favor of batchAddBlocks
- Migrated undo-redo to use batchAddBlocks instead of addBlock loop - Removed addBlock method from workflow store (now unused) - Updated tests to use helper function wrapping batchAddBlocks - This fixes the cursor bot comments about inconsistent parent checking
1 parent d7c0364 commit 0bf817b

File tree

4 files changed

+75
-296
lines changed

4 files changed

+75
-296
lines changed

apps/sim/hooks/use-undo-redo.ts

Lines changed: 6 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import {
2929
useUndoRedoStore,
3030
} from '@/stores/undo-redo'
3131
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
32-
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
3332
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
3433
import type { BlockState } from '@/stores/workflows/workflow/types'
3534

@@ -504,47 +503,9 @@ export function useUndoRedo() {
504503
userId,
505504
})
506505

507-
blocksToAdd.forEach((block) => {
508-
useWorkflowStore
509-
.getState()
510-
.addBlock(
511-
block.id,
512-
block.type,
513-
block.name,
514-
block.position,
515-
block.data,
516-
block.data?.parentId,
517-
block.data?.extent,
518-
{
519-
enabled: block.enabled,
520-
horizontalHandles: block.horizontalHandles,
521-
advancedMode: block.advancedMode,
522-
triggerMode: block.triggerMode,
523-
height: block.height,
524-
}
525-
)
526-
})
527-
528-
if (subBlockValues && Object.keys(subBlockValues).length > 0) {
529-
useSubBlockStore.setState((state) => ({
530-
workflowValues: {
531-
...state.workflowValues,
532-
[activeWorkflowId]: {
533-
...state.workflowValues[activeWorkflowId],
534-
...subBlockValues,
535-
},
536-
},
537-
}))
538-
}
539-
540-
if (edgeSnapshots && edgeSnapshots.length > 0) {
541-
const edgesToAdd = edgeSnapshots.filter(
542-
(edge) => !useWorkflowStore.getState().edges.find((e) => e.id === edge.id)
543-
)
544-
if (edgesToAdd.length > 0) {
545-
useWorkflowStore.getState().batchAddEdges(edgesToAdd)
546-
}
547-
}
506+
useWorkflowStore
507+
.getState()
508+
.batchAddBlocks(blocksToAdd, edgeSnapshots || [], subBlockValues || {})
548509
break
549510
}
550511
case UNDO_REDO_OPERATIONS.BATCH_REMOVE_EDGES: {
@@ -1085,47 +1046,9 @@ export function useUndoRedo() {
10851046
userId,
10861047
})
10871048

1088-
blocksToAdd.forEach((block) => {
1089-
useWorkflowStore
1090-
.getState()
1091-
.addBlock(
1092-
block.id,
1093-
block.type,
1094-
block.name,
1095-
block.position,
1096-
block.data,
1097-
block.data?.parentId,
1098-
block.data?.extent,
1099-
{
1100-
enabled: block.enabled,
1101-
horizontalHandles: block.horizontalHandles,
1102-
advancedMode: block.advancedMode,
1103-
triggerMode: block.triggerMode,
1104-
height: block.height,
1105-
}
1106-
)
1107-
})
1108-
1109-
if (subBlockValues && Object.keys(subBlockValues).length > 0) {
1110-
useSubBlockStore.setState((state) => ({
1111-
workflowValues: {
1112-
...state.workflowValues,
1113-
[activeWorkflowId]: {
1114-
...state.workflowValues[activeWorkflowId],
1115-
...subBlockValues,
1116-
},
1117-
},
1118-
}))
1119-
}
1120-
1121-
if (edgeSnapshots && edgeSnapshots.length > 0) {
1122-
const edgesToAdd = edgeSnapshots.filter(
1123-
(edge) => !useWorkflowStore.getState().edges.find((e) => e.id === edge.id)
1124-
)
1125-
if (edgesToAdd.length > 0) {
1126-
useWorkflowStore.getState().batchAddEdges(edgesToAdd)
1127-
}
1128-
}
1049+
useWorkflowStore
1050+
.getState()
1051+
.batchAddBlocks(blocksToAdd, edgeSnapshots || [], subBlockValues || {})
11291052
break
11301053
}
11311054
case UNDO_REDO_OPERATIONS.BATCH_REMOVE_BLOCKS: {

0 commit comments

Comments
 (0)