MCPcopy
hub / github.com/simstudioai/sim / useCollaborativeWorkflow

Function useCollaborativeWorkflow

apps/sim/hooks/use-collaborative-workflow.ts:61–2213  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

59const logger = createLogger('CollaborativeWorkflow')
60
61export function useCollaborativeWorkflow() {
62 const queryClient = useQueryClient()
63 const undoRedo = useUndoRedo()
64 const isUndoRedoInProgress = useRef(false)
65 const lastDiffOperationId = useRef<string | null>(null)
66
67 useEffect(() => {
68 const moveHandler = (e: any) => {
69 const { blockId, before, after } = e.detail || {}
70 if (!blockId || !before || !after) return
71 if (isUndoRedoInProgress.current) return
72 undoRedo.recordBatchMoveBlocks([{ blockId, before, after }])
73 }
74
75 const parentUpdateHandler = (e: any) => {
76 const { blockId, oldParentId, newParentId, oldPosition, newPosition, affectedEdges } =
77 e.detail || {}
78 if (!blockId) return
79 if (isUndoRedoInProgress.current) return
80 undoRedo.recordUpdateParent(
81 blockId,
82 oldParentId,
83 newParentId,
84 oldPosition,
85 newPosition,
86 affectedEdges
87 )
88 }
89
90 const diffOperationHandler = (e: any) => {
91 const {
92 type,
93 baselineSnapshot,
94 proposedState,
95 diffAnalysis,
96 beforeAccept,
97 afterAccept,
98 beforeReject,
99 afterReject,
100 } = e.detail || {}
101 // Don't record during undo/redo operations
102 if (isUndoRedoInProgress.current) return
103
104 // Generate a unique ID for this diff operation to prevent duplicates
105 // Use block keys from the relevant states for each operation type
106 let stateForId
107 if (type === 'apply-diff') {
108 stateForId = proposedState
109 } else if (type === 'accept-diff') {
110 stateForId = afterAccept
111 } else if (type === 'reject-diff') {
112 stateForId = afterReject
113 }
114
115 const blockKeys = stateForId?.blocks ? Object.keys(stateForId.blocks).sort().join(',') : ''
116 const operationId = `${type}-${blockKeys}`
117
118 if (lastDiffOperationId.current === operationId) {

Callers 13

workflow.tsxFile · 0.90
VariablesFunction · 0.90
WorkflowSearchReplaceFunction · 0.90
panel.tsxFile · 0.90
EditorFunction · 0.90
SelectorInputFunction · 0.90
tool-input.tsxFile · 0.90
useSubBlockValueFunction · 0.90
useSubflowEditorFunction · 0.90
action-bar.tsxFile · 0.90
useCodeUndoRedoFunction · 0.90

Calls 15

useUndoRedoFunction · 0.90
useSocketFunction · 0.90
useSessionFunction · 0.90
useOperationQueueFunction · 0.90
registerEmitFunctionsFunction · 0.90
generateIdFunction · 0.90
isBlockProtectedFunction · 0.90
normalizeNameFunction · 0.90
findAllDescendantNodesFunction · 0.90
filterValidEdgesFunction · 0.90
filterNewEdgesFunction · 0.90

Tested by

no test coverage detected