Fixed delete block in loop error

This commit is contained in:
Emir Karabeg
2025-02-11 16:12:29 -08:00
parent 7ddb4ca0f0
commit bddc6cb7f7
4 changed files with 26 additions and 18 deletions
@@ -8,8 +8,14 @@ interface WorkflowLoopProps {
// Pure calculation function - no hooks
function calculateLoopBounds(loop: Loop, blocks: Record<string, any>) {
// Get all blocks in this loop
const loopBlocks = loop.nodes.map((id) => blocks[id])
// Get all blocks in this loop and filter out any undefined blocks
const loopBlocks = loop.nodes
.map((id) => blocks[id])
.filter(
(block): block is NonNullable<typeof block> =>
block !== undefined && block.position !== undefined
)
if (!loopBlocks.length) return null
// Calculate bounds of all blocks in loop
-1
View File
@@ -18,7 +18,6 @@ import { useWorkflowRegistry } from '@/stores/workflow/registry'
import { useWorkflowStore } from '@/stores/workflow/store'
import { NotificationList } from '@/app/w/components/notifications/notifications'
import { getBlock } from '../../../blocks'
import { useWorkflowExecution } from '../hooks/use-workflow-execution'
import { CustomEdge } from './components/custom-edge/custom-edge'
import { WorkflowBlock } from './components/workflow-block/workflow-block'
import { createLoopNode, getRelativeLoopPosition } from './components/workflow-loop/workflow-loop'
-15
View File
@@ -12,21 +12,6 @@ import { cn } from '@/lib/utils'
// This file is not typed correctly from shadcn, so we're disabling the type checker
// @ts-nocheck
// This file is not typed correctly from shadcn, so we're disabling the type checker
// @ts-nocheck
// This file is not typed correctly from shadcn, so we're disabling the type checker
// @ts-nocheck
// This file is not typed correctly from shadcn, so we're disabling the type checker
// @ts-nocheck
// This file is not typed correctly from shadcn, so we're disabling the type checker
// @ts-nocheck
// This file is not typed correctly from shadcn, so we're disabling the type checker
// @ts-nocheck
const Command = React.forwardRef<
React.ElementRef<typeof CommandPrimitive>,
React.ComponentPropsWithoutRef<typeof CommandPrimitive> & {
+18
View File
@@ -175,6 +175,24 @@ export const useWorkflowStore = create<WorkflowStoreWithHistory>()(
edges: [...get().edges].filter((edge) => edge.source !== id && edge.target !== id),
loops: { ...get().loops },
}
// Remove the block from any loops that contain it
Object.entries(newState.loops).forEach(([loopId, loop]) => {
if (loop.nodes.includes(id)) {
// If the loop would only have 1 or 0 nodes after removal, delete the loop
if (loop.nodes.length <= 2) {
delete newState.loops[loopId]
} else {
// Otherwise, just remove the node from the loop
newState.loops[loopId] = {
...loop,
nodes: loop.nodes.filter((nodeId) => nodeId !== id)
}
}
}
})
// Delete the block itself
delete newState.blocks[id]
set(newState)