Skip to content

Commit 9a24aa9

Browse files
committed
fix(undo-redo): address PR review feedback
- collaborativeBatchSetSubblockValues: capture each field's real prior value before mutating instead of recording before: update.expectedValue, which was undefined when a caller omitted expectedValue (would undo a field to undefined) - List the stable recordSubflowFieldUpdate helper in the subflow methods' dependency arrays - Document that a multi-block batch undo reveals only its first block
1 parent 73e563b commit 9a24aa9

2 files changed

Lines changed: 15 additions & 12 deletions

File tree

apps/sim/hooks/use-collaborative-workflow.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,6 +1684,15 @@ export function useCollaborativeWorkflow() {
16841684
(update) => !isSyntheticToolSubBlockId(update.subblockId)
16851685
)
16861686

1687+
// Capture each field's real prior value before mutating, so undo restores the
1688+
// actual value rather than `undefined` when a caller omits `expectedValue`.
1689+
const undoChanges = persistedUpdates.map((update) => ({
1690+
blockId: update.blockId,
1691+
subBlockId: update.subblockId,
1692+
before: useSubBlockStore.getState().getValue(update.blockId, update.subblockId),
1693+
after: update.value,
1694+
}))
1695+
16871696
if (updates.length > 0) {
16881697
updates.forEach((update) => {
16891698
useSubBlockStore.getState().setValue(update.blockId, update.subblockId, update.value)
@@ -1707,15 +1716,7 @@ export function useCollaborativeWorkflow() {
17071716
}
17081717
}
17091718

1710-
undoRedo.recordBatchUpdateSubblocks(
1711-
persistedUpdates.map((update) => ({
1712-
blockId: update.blockId,
1713-
subBlockId: update.subblockId,
1714-
before: update.expectedValue,
1715-
after: update.value,
1716-
})),
1717-
undoSubflowUpdates
1718-
)
1719+
undoRedo.recordBatchUpdateSubblocks(undoChanges, undoSubflowUpdates)
17191720

17201721
return true
17211722
},
@@ -1953,7 +1954,7 @@ export function useCollaborativeWorkflow() {
19531954
)
19541955
}
19551956
},
1956-
[executeQueuedOperation]
1957+
[executeQueuedOperation, recordSubflowFieldUpdate]
19571958
)
19581959

19591960
const collaborativeUpdateIterationCollection = useCallback(
@@ -2054,7 +2055,7 @@ export function useCollaborativeWorkflow() {
20542055
)
20552056
}
20562057
},
2057-
[executeQueuedOperation]
2058+
[executeQueuedOperation, recordSubflowFieldUpdate]
20582059
)
20592060

20602061
const collaborativeUpdateParallelBatchSize = useCallback(
@@ -2093,7 +2094,7 @@ export function useCollaborativeWorkflow() {
20932094
() => useWorkflowStore.getState().updateParallelBatchSize(parallelId, clampedBatchSize)
20942095
)
20952096
},
2096-
[executeQueuedOperation]
2097+
[executeQueuedOperation, recordSubflowFieldUpdate]
20972098
)
20982099

20992100
const collaborativeUpdateVariable = useCallback(

apps/sim/stores/undo-redo/reveal.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export interface UndoRedoRevealTarget {
1515
export function getRevealTarget(operation: Operation): UndoRedoRevealTarget | null {
1616
if (operation.type !== UNDO_REDO_OPERATIONS.BATCH_UPDATE_SUBBLOCKS) return null
1717
const { updates, subflowUpdates } = (operation as BatchUpdateSubblocksOperation).data
18+
// A batch that spans multiple blocks (e.g. a search-replace across several fields)
19+
// reveals only its first block — we can't open multiple editor panels at once.
1820
const blockId = updates[0]?.blockId ?? subflowUpdates?.[0]?.blockId
1921
return blockId ? { blockId } : null
2022
}

0 commit comments

Comments
 (0)