This commit is contained in:
waleed
2026-01-08 18:56:27 -08:00
parent 757343df84
commit e1036e33ff
4 changed files with 63 additions and 21 deletions

View File

@@ -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]

View File

@@ -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
}

View File

@@ -586,6 +586,27 @@ export const useWorkflowStore = create<WorkflowStore>()(
// 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<WorkflowStore>()(
// 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: [] }

View File

@@ -195,8 +195,10 @@ export interface WorkflowActions {
clear: () => Partial<WorkflowState>
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