MCPcopy Index your code
hub / github.com/simstudioai/sim / useUndoRedo

Function useUndoRedo

apps/sim/hooks/use-undo-redo.ts:52–2087  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

50const logger = createLogger('UndoRedo')
51
52export function useUndoRedo() {
53 const { data: session } = useSession()
54 const activeWorkflowId = useWorkflowRegistry((state) => state.activeWorkflowId)
55 const { addToQueue } = useOperationQueue()
56
57 const userId = session?.user?.id || 'unknown'
58
59 const recordBatchAddBlocks = useCallback(
60 (
61 blockSnapshots: BlockState[],
62 edgeSnapshots: Edge[] = [],
63 subBlockValues: Record<string, Record<string, unknown>> = {}
64 ) => {
65 if (!activeWorkflowId || blockSnapshots.length === 0) return
66
67 const operation: BatchAddBlocksOperation = {
68 id: generateId(),
69 type: UNDO_REDO_OPERATIONS.BATCH_ADD_BLOCKS,
70 timestamp: Date.now(),
71 workflowId: activeWorkflowId,
72 userId,
73 data: {
74 blockSnapshots,
75 edgeSnapshots,
76 subBlockValues,
77 },
78 }
79
80 const inverse: BatchRemoveBlocksOperation = {
81 id: generateId(),
82 type: UNDO_REDO_OPERATIONS.BATCH_REMOVE_BLOCKS,
83 timestamp: Date.now(),
84 workflowId: activeWorkflowId,
85 userId,
86 data: {
87 blockSnapshots,
88 edgeSnapshots,
89 subBlockValues,
90 },
91 }
92
93 const entry = createOperationEntry(operation, inverse)
94 useUndoRedoStore.getState().push(activeWorkflowId, userId, entry)
95
96 logger.debug('Recorded batch add blocks', {
97 blockCount: blockSnapshots.length,
98 edgeCount: edgeSnapshots.length,
99 workflowId: activeWorkflowId,
100 })
101 },
102 [activeWorkflowId, userId]
103 )
104
105 const recordBatchRemoveBlocks = useCallback(
106 (
107 blockSnapshots: BlockState[],
108 edgeSnapshots: Edge[] = [],
109 subBlockValues: Record<string, Record<string, unknown>> = {}

Callers 1

useCollaborativeWorkflowFunction · 0.90

Calls 15

useSessionFunction · 0.90
useOperationQueueFunction · 0.90
generateIdFunction · 0.90
createOperationEntryFunction · 0.90
captureLatestEdgesFunction · 0.90
deriveDiffFlagsFunction · 0.90
stripWorkflowDiffMarkersFunction · 0.85
debugMethod · 0.80
infoMethod · 0.80

Tested by

no test coverage detected