Skip to content

Commit e1036e3

Browse files
committed
more
1 parent 757343d commit e1036e3

File tree

4 files changed

+63
-21
lines changed

4 files changed

+63
-21
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2396,11 +2396,14 @@ const WorkflowContent = React.memo(() => {
23962396
const selectedNodes = allNodes.filter((n) => n.selected)
23972397
multiNodeDragStartRef.current.clear()
23982398
selectedNodes.forEach((n) => {
2399-
multiNodeDragStartRef.current.set(n.id, {
2400-
x: n.position.x,
2401-
y: n.position.y,
2402-
parentId: blocks[n.id]?.data?.parentId,
2403-
})
2399+
const block = blocks[n.id]
2400+
if (block) {
2401+
multiNodeDragStartRef.current.set(n.id, {
2402+
x: n.position.x,
2403+
y: n.position.y,
2404+
parentId: block.data?.parentId,
2405+
})
2406+
}
24042407
})
24052408
},
24062409
[blocks, setDragStartPosition, getNodes]

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -682,11 +682,10 @@ export function useUndoRedo() {
682682
userId,
683683
})
684684

685+
// Use setBlockEnabled to directly restore to previous state
686+
// This is more robust than conditional toggle in collaborative scenarios
685687
validBlockIds.forEach((blockId) => {
686-
const targetState = previousStates[blockId]
687-
if (workflowStore.blocks[blockId].enabled !== targetState) {
688-
workflowStore.toggleBlockEnabled(blockId)
689-
}
688+
workflowStore.setBlockEnabled(blockId, previousStates[blockId])
690689
})
691690
break
692691
}
@@ -711,11 +710,10 @@ export function useUndoRedo() {
711710
userId,
712711
})
713712

713+
// Use setBlockHandles to directly restore to previous state
714+
// This is more robust than conditional toggle in collaborative scenarios
714715
validBlockIds.forEach((blockId) => {
715-
const targetState = previousStates[blockId]
716-
if (workflowStore.blocks[blockId].horizontalHandles !== targetState) {
717-
workflowStore.toggleBlockHandles(blockId)
718-
}
716+
workflowStore.setBlockHandles(blockId, previousStates[blockId])
719717
})
720718
break
721719
}
@@ -1192,11 +1190,10 @@ export function useUndoRedo() {
11921190
userId,
11931191
})
11941192

1193+
// Use setBlockEnabled to directly set to toggled state
1194+
// Redo sets to !previousStates (the state after the original toggle)
11951195
validBlockIds.forEach((blockId) => {
1196-
const targetState = !previousStates[blockId]
1197-
if (workflowStore.blocks[blockId].enabled !== targetState) {
1198-
workflowStore.toggleBlockEnabled(blockId)
1199-
}
1196+
workflowStore.setBlockEnabled(blockId, !previousStates[blockId])
12001197
})
12011198
break
12021199
}
@@ -1221,11 +1218,10 @@ export function useUndoRedo() {
12211218
userId,
12221219
})
12231220

1221+
// Use setBlockHandles to directly set to toggled state
1222+
// Redo sets to !previousStates (the state after the original toggle)
12241223
validBlockIds.forEach((blockId) => {
1225-
const targetState = !previousStates[blockId]
1226-
if (workflowStore.blocks[blockId].horizontalHandles !== targetState) {
1227-
workflowStore.toggleBlockHandles(blockId)
1228-
}
1224+
workflowStore.setBlockHandles(blockId, !previousStates[blockId])
12291225
})
12301226
break
12311227
}

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,27 @@ export const useWorkflowStore = create<WorkflowStore>()(
586586
// Note: Socket.IO handles real-time sync automatically
587587
},
588588

589+
setBlockEnabled: (id: string, enabled: boolean) => {
590+
const block = get().blocks[id]
591+
if (!block || block.enabled === enabled) return
592+
593+
const newState = {
594+
blocks: {
595+
...get().blocks,
596+
[id]: {
597+
...block,
598+
enabled,
599+
},
600+
},
601+
edges: [...get().edges],
602+
loops: { ...get().loops },
603+
parallels: { ...get().parallels },
604+
}
605+
606+
set(newState)
607+
get().updateLastSaved()
608+
},
609+
589610
duplicateBlock: (id: string) => {
590611
const block = get().blocks[id]
591612
if (!block) return
@@ -668,6 +689,26 @@ export const useWorkflowStore = create<WorkflowStore>()(
668689
// Note: Socket.IO handles real-time sync automatically
669690
},
670691

692+
setBlockHandles: (id: string, horizontalHandles: boolean) => {
693+
const block = get().blocks[id]
694+
if (!block || block.horizontalHandles === horizontalHandles) return
695+
696+
const newState = {
697+
blocks: {
698+
...get().blocks,
699+
[id]: {
700+
...block,
701+
horizontalHandles,
702+
},
703+
},
704+
edges: [...get().edges],
705+
loops: { ...get().loops },
706+
}
707+
708+
set(newState)
709+
get().updateLastSaved()
710+
},
711+
671712
updateBlockName: (id: string, name: string) => {
672713
const oldBlock = get().blocks[id]
673714
if (!oldBlock) return { success: false, changedSubblocks: [] }

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,10 @@ export interface WorkflowActions {
195195
clear: () => Partial<WorkflowState>
196196
updateLastSaved: () => void
197197
toggleBlockEnabled: (id: string) => void
198+
setBlockEnabled: (id: string, enabled: boolean) => void
198199
duplicateBlock: (id: string) => void
199200
toggleBlockHandles: (id: string) => void
201+
setBlockHandles: (id: string, horizontalHandles: boolean) => void
200202
updateBlockName: (
201203
id: string,
202204
name: string

0 commit comments

Comments
 (0)