Skip to content

Commit 0568704

Browse files
committed
remove dead subflow-specific ops
1 parent a8fb76b commit 0568704

File tree

7 files changed

+54
-124
lines changed

7 files changed

+54
-124
lines changed

apps/sim/hooks/use-undo-redo.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,8 @@ export function useUndoRedo() {
425425
break
426426
}
427427
case 'batch-add-blocks': {
428-
const batchAddOp = entry.operation as BatchAddBlocksOperation
428+
// Undoing a removal: inverse is batch-add-blocks, use entry.inverse for data
429+
const batchAddOp = entry.inverse as BatchAddBlocksOperation
429430
const { blockSnapshots, edgeSnapshots, subBlockValues } = batchAddOp.data
430431

431432
const blocksToAdd = blockSnapshots.filter((b) => !workflowStore.blocks[b.id])

apps/sim/stores/undo-redo/store.test.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
import {
1414
createAddBlockEntry,
1515
createAddEdgeEntry,
16+
createBatchRemoveEdgesEntry,
1617
createBlock,
1718
createMockStorage,
1819
createMoveBlockEntry,
1920
createRemoveBlockEntry,
20-
createRemoveEdgeEntry,
2121
createUpdateParentEntry,
2222
} from '@sim/testing'
2323
import { beforeEach, describe, expect, it } from 'vitest'
@@ -603,16 +603,17 @@ describe('useUndoRedoStore', () => {
603603
expect(getStackSizes(workflowId, userId).undoSize).toBe(2)
604604
})
605605

606-
it('should handle remove-edge operations', () => {
606+
it('should handle batch-remove-edges operations', () => {
607607
const { push, undo, getStackSizes } = useUndoRedoStore.getState()
608608

609-
push(workflowId, userId, createRemoveEdgeEntry('edge-1', null, { workflowId, userId }))
609+
const edgeSnapshot = { id: 'edge-1', source: 'block-1', target: 'block-2' }
610+
push(workflowId, userId, createBatchRemoveEdgesEntry([edgeSnapshot], { workflowId, userId }))
610611

611612
expect(getStackSizes(workflowId, userId).undoSize).toBe(1)
612613

613614
const entry = undo(workflowId, userId)
614-
expect(entry?.operation.type).toBe('remove-edge')
615-
expect(entry?.inverse.type).toBe('add-edge')
615+
expect(entry?.operation.type).toBe('batch-remove-edges')
616+
expect(entry?.inverse.type).toBe('batch-add-edges')
616617
})
617618
})
618619

@@ -672,8 +673,10 @@ describe('useUndoRedoStore', () => {
672673
it('should remove entries for non-existent edges', () => {
673674
const { push, pruneInvalidEntries, getStackSizes } = useUndoRedoStore.getState()
674675

675-
push(workflowId, userId, createRemoveEdgeEntry('edge-1', null, { workflowId, userId }))
676-
push(workflowId, userId, createRemoveEdgeEntry('edge-2', null, { workflowId, userId }))
676+
const edge1 = { id: 'edge-1', source: 'a', target: 'b' }
677+
const edge2 = { id: 'edge-2', source: 'c', target: 'd' }
678+
push(workflowId, userId, createBatchRemoveEdgesEntry([edge1], { workflowId, userId }))
679+
push(workflowId, userId, createBatchRemoveEdgesEntry([edge2], { workflowId, userId }))
677680

678681
expect(getStackSizes(workflowId, userId).undoSize).toBe(2)
679682

@@ -686,6 +689,8 @@ describe('useUndoRedoStore', () => {
686689

687690
pruneInvalidEntries(workflowId, userId, graph as any)
688691

692+
// edge-1 exists in graph, so we can't undo its removal (can't add it back) → pruned
693+
// edge-2 doesn't exist, so we can undo its removal (can add it back) → kept
689694
expect(getStackSizes(workflowId, userId).undoSize).toBe(1)
690695
})
691696
})

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { create } from 'zustand'
44
import { createJSONStorage, persist } from 'zustand/middleware'
55
import type {
66
BatchAddBlocksOperation,
7+
BatchAddEdgesOperation,
78
BatchMoveBlocksOperation,
89
BatchRemoveBlocksOperation,
910
BatchRemoveEdgesOperation,
@@ -104,17 +105,14 @@ function isOperationApplicable(
104105
const op = operation as BatchRemoveEdgesOperation
105106
return op.data.edgeSnapshots.every((edge) => Boolean(graph.edgesById[edge.id]))
106107
}
108+
case 'batch-add-edges': {
109+
const op = operation as BatchAddEdgesOperation
110+
return op.data.edgeSnapshots.every((edge) => !graph.edgesById[edge.id])
111+
}
107112
case 'add-edge': {
108113
const edgeId = operation.data.edgeId
109114
return !graph.edgesById[edgeId]
110115
}
111-
case 'add-subflow':
112-
case 'remove-subflow': {
113-
const subflowId = operation.data.subflowId
114-
return operation.type === 'remove-subflow'
115-
? Boolean(graph.blocksById[subflowId])
116-
: !graph.blocksById[subflowId]
117-
}
118116
default:
119117
return true
120118
}

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

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ export type OperationType =
77
| 'add-edge'
88
| 'batch-add-edges'
99
| 'batch-remove-edges'
10-
| 'add-subflow'
11-
| 'remove-subflow'
1210
| 'batch-move-blocks'
13-
| 'move-subflow'
1411
| 'update-parent'
1512
| 'batch-toggle-enabled'
1613
| 'batch-toggle-handles'
@@ -65,21 +62,6 @@ export interface BatchRemoveEdgesOperation extends BaseOperation {
6562
}
6663
}
6764

68-
export interface AddSubflowOperation extends BaseOperation {
69-
type: 'add-subflow'
70-
data: {
71-
subflowId: string
72-
}
73-
}
74-
75-
export interface RemoveSubflowOperation extends BaseOperation {
76-
type: 'remove-subflow'
77-
data: {
78-
subflowId: string
79-
subflowSnapshot: BlockState | null
80-
}
81-
}
82-
8365
export interface BatchMoveBlocksOperation extends BaseOperation {
8466
type: 'batch-move-blocks'
8567
data: {
@@ -91,21 +73,6 @@ export interface BatchMoveBlocksOperation extends BaseOperation {
9173
}
9274
}
9375

94-
export interface MoveSubflowOperation extends BaseOperation {
95-
type: 'move-subflow'
96-
data: {
97-
subflowId: string
98-
before: {
99-
x: number
100-
y: number
101-
}
102-
after: {
103-
x: number
104-
y: number
105-
}
106-
}
107-
}
108-
10976
export interface UpdateParentOperation extends BaseOperation {
11077
type: 'update-parent'
11178
data: {
@@ -169,10 +136,7 @@ export type Operation =
169136
| AddEdgeOperation
170137
| BatchAddEdgesOperation
171138
| BatchRemoveEdgesOperation
172-
| AddSubflowOperation
173-
| RemoveSubflowOperation
174139
| BatchMoveBlocksOperation
175-
| MoveSubflowOperation
176140
| UpdateParentOperation
177141
| BatchToggleEnabledOperation
178142
| BatchToggleHandlesOperation

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

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -79,25 +79,6 @@ export function createInverseOperation(operation: Operation): Operation {
7979
} as BatchAddEdgesOperation
8080
}
8181

82-
case 'add-subflow':
83-
return {
84-
...operation,
85-
type: 'remove-subflow',
86-
data: {
87-
subflowId: operation.data.subflowId,
88-
subflowSnapshot: null,
89-
},
90-
}
91-
92-
case 'remove-subflow':
93-
return {
94-
...operation,
95-
type: 'add-subflow',
96-
data: {
97-
subflowId: operation.data.subflowId,
98-
},
99-
}
100-
10182
case 'batch-move-blocks': {
10283
const op = operation as BatchMoveBlocksOperation
10384
return {
@@ -113,16 +94,6 @@ export function createInverseOperation(operation: Operation): Operation {
11394
} as BatchMoveBlocksOperation
11495
}
11596

116-
case 'move-subflow':
117-
return {
118-
...operation,
119-
data: {
120-
subflowId: operation.data.subflowId,
121-
before: operation.data.after,
122-
after: operation.data.before,
123-
},
124-
}
125-
12697
case 'update-parent':
12798
return {
12899
...operation,
@@ -256,20 +227,6 @@ export function operationToCollaborativePayload(operation: Operation): {
256227
}
257228
}
258229

259-
case 'add-subflow':
260-
return {
261-
operation: 'add',
262-
target: 'subflow',
263-
payload: { id: operation.data.subflowId },
264-
}
265-
266-
case 'remove-subflow':
267-
return {
268-
operation: 'remove',
269-
target: 'subflow',
270-
payload: { id: operation.data.subflowId },
271-
}
272-
273230
case 'batch-move-blocks': {
274231
const op = operation as BatchMoveBlocksOperation
275232
return {
@@ -286,17 +243,6 @@ export function operationToCollaborativePayload(operation: Operation): {
286243
}
287244
}
288245

289-
case 'move-subflow':
290-
return {
291-
operation: 'update-position',
292-
target: 'subflow',
293-
payload: {
294-
id: operation.data.subflowId,
295-
x: operation.data.after.x,
296-
y: operation.data.after.y,
297-
},
298-
}
299-
300246
case 'update-parent':
301247
return {
302248
operation: 'update-parent',

packages/testing/src/factories/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,19 @@ export {
123123
type AddEdgeOperation,
124124
type BaseOperation,
125125
type BatchAddBlocksOperation,
126+
type BatchAddEdgesOperation,
126127
type BatchMoveBlocksOperation,
127128
type BatchRemoveBlocksOperation,
129+
type BatchRemoveEdgesOperation,
128130
createAddBlockEntry,
129131
createAddEdgeEntry,
132+
createBatchRemoveEdgesEntry,
130133
createMoveBlockEntry,
131134
createRemoveBlockEntry,
132-
createRemoveEdgeEntry,
133135
createUpdateParentEntry,
134136
type Operation,
135137
type OperationEntry,
136138
type OperationType,
137-
type RemoveEdgeOperation,
138139
type UpdateParentOperation,
139140
} from './undo-redo.factory'
140141
// User/workspace factories

packages/testing/src/factories/undo-redo.factory.ts

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ export type OperationType =
99
| 'batch-add-blocks'
1010
| 'batch-remove-blocks'
1111
| 'add-edge'
12-
| 'remove-edge'
12+
| 'batch-add-edges'
13+
| 'batch-remove-edges'
1314
| 'batch-move-blocks'
1415
| 'update-parent'
1516

@@ -71,11 +72,19 @@ export interface AddEdgeOperation extends BaseOperation {
7172
}
7273

7374
/**
74-
* Remove edge operation data.
75+
* Batch add edges operation data.
7576
*/
76-
export interface RemoveEdgeOperation extends BaseOperation {
77-
type: 'remove-edge'
78-
data: { edgeId: string; edgeSnapshot: any }
77+
export interface BatchAddEdgesOperation extends BaseOperation {
78+
type: 'batch-add-edges'
79+
data: { edgeSnapshots: any[] }
80+
}
81+
82+
/**
83+
* Batch remove edges operation data.
84+
*/
85+
export interface BatchRemoveEdgesOperation extends BaseOperation {
86+
type: 'batch-remove-edges'
87+
data: { edgeSnapshots: any[] }
7988
}
8089

8190
/**
@@ -96,7 +105,8 @@ export type Operation =
96105
| BatchAddBlocksOperation
97106
| BatchRemoveBlocksOperation
98107
| AddEdgeOperation
99-
| RemoveEdgeOperation
108+
| BatchAddEdgesOperation
109+
| BatchRemoveEdgesOperation
100110
| BatchMoveBlocksOperation
101111
| UpdateParentOperation
102112

@@ -212,10 +222,16 @@ export function createRemoveBlockEntry(
212222
/**
213223
* Creates a mock add-edge operation entry.
214224
*/
215-
export function createAddEdgeEntry(edgeId: string, options: OperationEntryOptions = {}): any {
225+
export function createAddEdgeEntry(
226+
edgeId: string,
227+
edgeSnapshot: any = null,
228+
options: OperationEntryOptions = {}
229+
): any {
216230
const { id = nanoid(8), workflowId = 'wf-1', userId = 'user-1', createdAt = Date.now() } = options
217231
const timestamp = Date.now()
218232

233+
const snapshot = edgeSnapshot || { id: edgeId, source: 'block-1', target: 'block-2' }
234+
219235
return {
220236
id,
221237
createdAt,
@@ -229,21 +245,20 @@ export function createAddEdgeEntry(edgeId: string, options: OperationEntryOption
229245
},
230246
inverse: {
231247
id: nanoid(8),
232-
type: 'remove-edge',
248+
type: 'batch-remove-edges',
233249
timestamp,
234250
workflowId,
235251
userId,
236-
data: { edgeId, edgeSnapshot: null },
252+
data: { edgeSnapshots: [snapshot] },
237253
},
238254
}
239255
}
240256

241257
/**
242-
* Creates a mock remove-edge operation entry.
258+
* Creates a mock batch-remove-edges operation entry.
243259
*/
244-
export function createRemoveEdgeEntry(
245-
edgeId: string,
246-
edgeSnapshot: any = null,
260+
export function createBatchRemoveEdgesEntry(
261+
edgeSnapshots: any[],
247262
options: OperationEntryOptions = {}
248263
): any {
249264
const { id = nanoid(8), workflowId = 'wf-1', userId = 'user-1', createdAt = Date.now() } = options
@@ -254,19 +269,19 @@ export function createRemoveEdgeEntry(
254269
createdAt,
255270
operation: {
256271
id: nanoid(8),
257-
type: 'remove-edge',
272+
type: 'batch-remove-edges',
258273
timestamp,
259274
workflowId,
260275
userId,
261-
data: { edgeId, edgeSnapshot },
276+
data: { edgeSnapshots },
262277
},
263278
inverse: {
264279
id: nanoid(8),
265-
type: 'add-edge',
280+
type: 'batch-add-edges',
266281
timestamp,
267282
workflowId,
268283
userId,
269-
data: { edgeId },
284+
data: { edgeSnapshots },
270285
},
271286
}
272287
}

0 commit comments

Comments
 (0)