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. 41
      src/components/nodes/SwitchNode.tsx

41
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,26 +228,28 @@ export const SwitchNode = memo(({ id, data, selected }: NodeProps<WorkflowNode>)
</span> </span>
)} )}
{/* Delete button */} {/* Delete button (hidden if only one switch) */}
<button {nodeData.switches.length > 1 && (
className="opacity-0 group-hover:opacity-100 text-neutral-400 hover:text-red-400 transition-opacity" <button
onClick={() => handleDelete(sw.id)} className="opacity-0 group-hover:opacity-100 text-neutral-400 hover:text-red-400 transition-opacity"
title="Delete switch" onClick={() => handleDelete(sw.id)}
> title="Delete switch"
<svg
className="w-3 h-3"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
> >
<path <svg
strokeLinecap="round" className="w-3 h-3"
strokeLinejoin="round" fill="none"
strokeWidth={2} stroke="currentColor"
d="M6 18L18 6M6 6l12 12" viewBox="0 0 24 24"
/> >
</svg> <path
</button> strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M6 18L18 6M6 6l12 12"
/>
</svg>
</button>
)}
</div> </div>
))} ))}

Loading…
Cancel
Save