Browse Source

fix: prevent SwitchNode from deleting last switch

Add guard in handleDelete and hide the delete button when only one
switch remains, matching ConditionalSwitchNode's existing behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
handoff-20260429-1057
shrimbly 5 months ago
parent
commit
3a7051e4ee
  1. 5
      src/components/nodes/SwitchNode.tsx

5
src/components/nodes/SwitchNode.tsx

@ -92,6 +92,7 @@ export const SwitchNode = memo(({ id, data, selected }: NodeProps<WorkflowNode>)
// Handle delete switch // Handle delete switch
const handleDelete = useCallback( const handleDelete = useCallback(
(switchId: string) => { (switchId: string) => {
if (nodeData.switches.length <= 1) return;
const updatedSwitches = nodeData.switches.filter((sw) => sw.id !== switchId); const updatedSwitches = nodeData.switches.filter((sw) => sw.id !== switchId);
updateNodeData(id, { switches: updatedSwitches }); updateNodeData(id, { switches: updatedSwitches });
@ -227,7 +228,8 @@ export const SwitchNode = memo(({ id, data, selected }: NodeProps<WorkflowNode>)
</span> </span>
)} )}
{/* Delete button */} {/* Delete button (hidden if only one switch) */}
{nodeData.switches.length > 1 && (
<button <button
className="opacity-0 group-hover:opacity-100 text-neutral-400 hover:text-red-400 transition-opacity" className="opacity-0 group-hover:opacity-100 text-neutral-400 hover:text-red-400 transition-opacity"
onClick={() => handleDelete(sw.id)} onClick={() => handleDelete(sw.id)}
@ -247,6 +249,7 @@ export const SwitchNode = memo(({ id, data, selected }: NodeProps<WorkflowNode>)
/> />
</svg> </svg>
</button> </button>
)}
</div> </div>
))} ))}

Loading…
Cancel
Save