All files / src/components/WorkflowBuilder/nodes ConditionNode.tsx

0% Statements 0/52
0% Branches 0/1
0% Functions 0/1
0% Lines 0/52

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82                                                                                                                                                                   
/**
 * Condition Node Component
 *
 * Node for conditional branching.
 */
 
import { memo } from 'react';
import { Handle, Position, NodeProps, Node } from '@xyflow/react';
import type { ConditionNodeData } from '../../../lib/workflow-builder/types';
 
type ConditionNodeType = Node<ConditionNodeData>;
 
export const ConditionNode = memo(({ data, selected }: NodeProps<ConditionNodeType>) => {
  const branchCount = data.branches.length + (data.hasDefault ? 1 : 0);
 
  return (
    <div
      className={`
        px-4 py-3 rounded-lg border-2 min-w-[200px]
        bg-orange-50 border-orange-300
        ${selected ? 'border-orange-500 shadow-lg shadow-orange-200' : ''}
      `}
    >
      {/* Input Handle */}
      <Handle
        type="target"
        position={Position.Left}
        className="w-3 h-3 bg-orange-400 border-2 border-white"
      />
 
      {/* Header */}
      <div className="flex items-center gap-2 mb-2">
        <span className="text-lg">🔀</span>
        <span className="font-medium text-orange-800">{data.label}</span>
      </div>
 
      {/* Condition Preview */}
      <div className="text-sm text-orange-600 bg-orange-100 rounded px-2 py-1 font-mono mb-2">
        {data.condition || 'No condition'}
      </div>
 
      {/* Branches */}
      <div className="space-y-1">
        {data.branches.map((branch: { label?: string; when: string }, index: number) => (
          <div key={index} className="flex items-center justify-between">
            <div className="relative">
              {/* Branch Output Handle */}
              <Handle
                type="source"
                position={Position.Right}
                id={`branch-${index}`}
                style={{ top: `${((index + 1) / (branchCount + 1)) * 100}%` }}
                className="w-3 h-3 bg-orange-400 border-2 border-white"
              />
            </div>
            <span className="text-xs text-orange-500 truncate max-w-[120px]">
              {branch.label || branch.when}
            </span>
          </div>
        ))}
 
        {data.hasDefault && (
          <div className="flex items-center justify-between">
            <Handle
              type="source"
              position={Position.Right}
              id="default"
              style={{ top: '100%' }}
              className="w-3 h-3 bg-gray-400 border-2 border-white"
            />
            <span className="text-xs text-gray-500">Default</span>
          </div>
        )}
      </div>
    </div>
  );
});
 
ConditionNode.displayName = 'ConditionNode';
 
export default ConditionNode;