ack PR comments

This commit is contained in:
waleed
2026-01-08 18:34:07 -08:00
parent e054cef0d6
commit 757343df84
4 changed files with 69 additions and 38 deletions

View File

@@ -6,6 +6,7 @@ import { enqueueReplaceWorkflowState } from '@/lib/workflows/operations/socket-o
import { useOperationQueue } from '@/stores/operation-queue/store'
import {
type BatchAddBlocksOperation,
type BatchAddEdgesOperation,
type BatchMoveBlocksOperation,
type BatchRemoveBlocksOperation,
type BatchRemoveEdgesOperation,
@@ -141,7 +142,6 @@ export function useUndoRedo() {
data: { edgeId },
}
// Inverse is batch-remove-edges with a single edge
const inverse: BatchRemoveEdgesOperation = {
id: crypto.randomUUID(),
type: 'batch-remove-edges',
@@ -176,10 +176,9 @@ export function useUndoRedo() {
},
}
// Inverse is batch-add-edges (using the snapshots to restore)
const inverse: BatchRemoveEdgesOperation = {
const inverse: BatchAddEdgesOperation = {
id: crypto.randomUUID(),
type: 'batch-remove-edges',
type: 'batch-add-edges',
timestamp: Date.now(),
workflowId: activeWorkflowId,
userId,

View File

@@ -703,25 +703,22 @@ async function handleBlocksOperationTx(
`Batch toggling enabled state for ${blockIds.length} blocks in workflow ${workflowId}`
)
for (const blockId of blockIds) {
const block = await tx
.select({ enabled: workflowBlocks.enabled })
.from(workflowBlocks)
.where(and(eq(workflowBlocks.id, blockId), eq(workflowBlocks.workflowId, workflowId)))
.limit(1)
const blocks = await tx
.select({ id: workflowBlocks.id, enabled: workflowBlocks.enabled })
.from(workflowBlocks)
.where(and(eq(workflowBlocks.workflowId, workflowId), inArray(workflowBlocks.id, blockIds)))
if (block.length > 0) {
await tx
.update(workflowBlocks)
.set({
enabled: !block[0].enabled,
updatedAt: new Date(),
})
.where(and(eq(workflowBlocks.id, blockId), eq(workflowBlocks.workflowId, workflowId)))
}
for (const block of blocks) {
await tx
.update(workflowBlocks)
.set({
enabled: !block.enabled,
updatedAt: new Date(),
})
.where(and(eq(workflowBlocks.id, block.id), eq(workflowBlocks.workflowId, workflowId)))
}
logger.debug(`Batch toggled enabled state for ${blockIds.length} blocks`)
logger.debug(`Batch toggled enabled state for ${blocks.length} blocks`)
break
}
@@ -733,25 +730,22 @@ async function handleBlocksOperationTx(
logger.info(`Batch toggling handles for ${blockIds.length} blocks in workflow ${workflowId}`)
for (const blockId of blockIds) {
const block = await tx
.select({ horizontalHandles: workflowBlocks.horizontalHandles })
.from(workflowBlocks)
.where(and(eq(workflowBlocks.id, blockId), eq(workflowBlocks.workflowId, workflowId)))
.limit(1)
const blocks = await tx
.select({ id: workflowBlocks.id, horizontalHandles: workflowBlocks.horizontalHandles })
.from(workflowBlocks)
.where(and(eq(workflowBlocks.workflowId, workflowId), inArray(workflowBlocks.id, blockIds)))
if (block.length > 0) {
await tx
.update(workflowBlocks)
.set({
horizontalHandles: !block[0].horizontalHandles,
updatedAt: new Date(),
})
.where(and(eq(workflowBlocks.id, blockId), eq(workflowBlocks.workflowId, workflowId)))
}
for (const block of blocks) {
await tx
.update(workflowBlocks)
.set({
horizontalHandles: !block.horizontalHandles,
updatedAt: new Date(),
})
.where(and(eq(workflowBlocks.id, block.id), eq(workflowBlocks.workflowId, workflowId)))
}
logger.debug(`Batch toggled handles for ${blockIds.length} blocks`)
logger.debug(`Batch toggled handles for ${blocks.length} blocks`)
break
}

View File

@@ -5,6 +5,7 @@ export type OperationType =
| 'batch-add-blocks'
| 'batch-remove-blocks'
| 'add-edge'
| 'batch-add-edges'
| 'batch-remove-edges'
| 'add-subflow'
| 'remove-subflow'
@@ -50,6 +51,13 @@ export interface AddEdgeOperation extends BaseOperation {
}
}
export interface BatchAddEdgesOperation extends BaseOperation {
type: 'batch-add-edges'
data: {
edgeSnapshots: Edge[]
}
}
export interface BatchRemoveEdgesOperation extends BaseOperation {
type: 'batch-remove-edges'
data: {
@@ -159,6 +167,7 @@ export type Operation =
| BatchAddBlocksOperation
| BatchRemoveBlocksOperation
| AddEdgeOperation
| BatchAddEdgesOperation
| BatchRemoveEdgesOperation
| AddSubflowOperation
| RemoveSubflowOperation

View File

@@ -1,5 +1,6 @@
import type {
BatchAddBlocksOperation,
BatchAddEdgesOperation,
BatchMoveBlocksOperation,
BatchRemoveBlocksOperation,
BatchRemoveEdgesOperation,
@@ -56,8 +57,8 @@ export function createInverseOperation(operation: Operation): Operation {
},
} as BatchRemoveEdgesOperation
case 'batch-remove-edges': {
const op = operation as BatchRemoveEdgesOperation
case 'batch-add-edges': {
const op = operation as BatchAddEdgesOperation
return {
...operation,
type: 'batch-remove-edges',
@@ -67,6 +68,17 @@ export function createInverseOperation(operation: Operation): Operation {
} as BatchRemoveEdgesOperation
}
case 'batch-remove-edges': {
const op = operation as BatchRemoveEdgesOperation
return {
...operation,
type: 'batch-add-edges',
data: {
edgeSnapshots: op.data.edgeSnapshots,
},
} as BatchAddEdgesOperation
}
case 'add-subflow':
return {
...operation,
@@ -218,6 +230,23 @@ export function operationToCollaborativePayload(operation: Operation): {
payload: { id: operation.data.edgeId },
}
case 'batch-add-edges': {
const op = operation as BatchAddEdgesOperation
return {
operation: 'batch-add-edges',
target: 'edges',
payload: {
edges: op.data.edgeSnapshots.map((e) => ({
id: e.id,
source: e.source,
target: e.target,
sourceHandle: e.sourceHandle ?? null,
targetHandle: e.targetHandle ?? null,
})),
},
}
}
case 'batch-remove-edges': {
const op = operation as BatchRemoveEdgesOperation
return {