mirror of
https://github.com/simstudioai/sim.git
synced 2026-09-24 15:45:35 +08:00
Fixed delete block in loop error
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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> & {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user