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

Loading…
Cancel
Save