From e1036e33ffc1e0722c485952a9bc219692d625ee Mon Sep 17 00:00:00 2001 From: waleed Date: Thu, 8 Jan 2026 18:56:27 -0800 Subject: [PATCH] more --- .../[workspaceId]/w/[workflowId]/workflow.tsx | 13 +++--- apps/sim/hooks/use-undo-redo.ts | 28 ++++++------- apps/sim/stores/workflows/workflow/store.ts | 41 +++++++++++++++++++ apps/sim/stores/workflows/workflow/types.ts | 2 + 4 files changed, 63 insertions(+), 21 deletions(-) diff --git a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx index 2462672ea3..bb24aa3af7 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx @@ -2396,11 +2396,14 @@ const WorkflowContent = React.memo(() => { const selectedNodes = allNodes.filter((n) => n.selected) multiNodeDragStartRef.current.clear() selectedNodes.forEach((n) => { - multiNodeDragStartRef.current.set(n.id, { - x: n.position.x, - y: n.position.y, - parentId: blocks[n.id]?.data?.parentId, - }) + const block = blocks[n.id] + if (block) { + multiNodeDragStartRef.current.set(n.id, { + x: n.position.x, + y: n.position.y, + parentId: block.data?.parentId, + }) + } }) }, [blocks, setDragStartPosition, getNodes] diff --git a/apps/sim/hooks/use-undo-redo.ts b/apps/sim/hooks/use-undo-redo.ts index 536941c720..318b752a3c 100644 --- a/apps/sim/hooks/use-undo-redo.ts +++ b/apps/sim/hooks/use-undo-redo.ts @@ -682,11 +682,10 @@ export function useUndoRedo() { userId, }) + // Use setBlockEnabled to directly restore to previous state + // This is more robust than conditional toggle in collaborative scenarios validBlockIds.forEach((blockId) => { - const targetState = previousStates[blockId] - if (workflowStore.blocks[blockId].enabled !== targetState) { - workflowStore.toggleBlockEnabled(blockId) - } + workflowStore.setBlockEnabled(blockId, previousStates[blockId]) }) break } @@ -711,11 +710,10 @@ export function useUndoRedo() { userId, }) + // Use setBlockHandles to directly restore to previous state + // This is more robust than conditional toggle in collaborative scenarios validBlockIds.forEach((blockId) => { - const targetState = previousStates[blockId] - if (workflowStore.blocks[blockId].horizontalHandles !== targetState) { - workflowStore.toggleBlockHandles(blockId) - } + workflowStore.setBlockHandles(blockId, previousStates[blockId]) }) break } @@ -1192,11 +1190,10 @@ export function useUndoRedo() { userId, }) + // Use setBlockEnabled to directly set to toggled state + // Redo sets to !previousStates (the state after the original toggle) validBlockIds.forEach((blockId) => { - const targetState = !previousStates[blockId] - if (workflowStore.blocks[blockId].enabled !== targetState) { - workflowStore.toggleBlockEnabled(blockId) - } + workflowStore.setBlockEnabled(blockId, !previousStates[blockId]) }) break } @@ -1221,11 +1218,10 @@ export function useUndoRedo() { userId, }) + // Use setBlockHandles to directly set to toggled state + // Redo sets to !previousStates (the state after the original toggle) validBlockIds.forEach((blockId) => { - const targetState = !previousStates[blockId] - if (workflowStore.blocks[blockId].horizontalHandles !== targetState) { - workflowStore.toggleBlockHandles(blockId) - } + workflowStore.setBlockHandles(blockId, !previousStates[blockId]) }) break } diff --git a/apps/sim/stores/workflows/workflow/store.ts b/apps/sim/stores/workflows/workflow/store.ts index 41d3051637..a217964b36 100644 --- a/apps/sim/stores/workflows/workflow/store.ts +++ b/apps/sim/stores/workflows/workflow/store.ts @@ -586,6 +586,27 @@ export const useWorkflowStore = create()( // Note: Socket.IO handles real-time sync automatically }, + setBlockEnabled: (id: string, enabled: boolean) => { + const block = get().blocks[id] + if (!block || block.enabled === enabled) return + + const newState = { + blocks: { + ...get().blocks, + [id]: { + ...block, + enabled, + }, + }, + edges: [...get().edges], + loops: { ...get().loops }, + parallels: { ...get().parallels }, + } + + set(newState) + get().updateLastSaved() + }, + duplicateBlock: (id: string) => { const block = get().blocks[id] if (!block) return @@ -668,6 +689,26 @@ export const useWorkflowStore = create()( // Note: Socket.IO handles real-time sync automatically }, + setBlockHandles: (id: string, horizontalHandles: boolean) => { + const block = get().blocks[id] + if (!block || block.horizontalHandles === horizontalHandles) return + + const newState = { + blocks: { + ...get().blocks, + [id]: { + ...block, + horizontalHandles, + }, + }, + edges: [...get().edges], + loops: { ...get().loops }, + } + + set(newState) + get().updateLastSaved() + }, + updateBlockName: (id: string, name: string) => { const oldBlock = get().blocks[id] if (!oldBlock) return { success: false, changedSubblocks: [] } diff --git a/apps/sim/stores/workflows/workflow/types.ts b/apps/sim/stores/workflows/workflow/types.ts index c836b8040c..023a223dec 100644 --- a/apps/sim/stores/workflows/workflow/types.ts +++ b/apps/sim/stores/workflows/workflow/types.ts @@ -195,8 +195,10 @@ export interface WorkflowActions { clear: () => Partial updateLastSaved: () => void toggleBlockEnabled: (id: string) => void + setBlockEnabled: (id: string, enabled: boolean) => void duplicateBlock: (id: string) => void toggleBlockHandles: (id: string) => void + setBlockHandles: (id: string, horizontalHandles: boolean) => void updateBlockName: ( id: string, name: string