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

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

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                                                                                                                                                                   
/**
 * HTTP Node Component
 *
 * Node for making HTTP requests.
 */
 
import { memo } from 'react';
import { Handle, Position, NodeProps, Node } from '@xyflow/react';
import type { HttpNodeData } from '../../../lib/workflow-builder/types';
 
const methodColors: Record<string, string> = {
  GET: 'bg-green-100 text-green-700',
  POST: 'bg-blue-100 text-blue-700',
  PUT: 'bg-yellow-100 text-yellow-700',
  DELETE: 'bg-red-100 text-red-700',
  PATCH: 'bg-purple-100 text-purple-700',
};
 
export const HttpNode = memo(({ data, selected }: NodeProps<Node<HttpNodeData>>) => {
  const hasUrl = Boolean(data.url);
 
  return (
    <div
      className={`
        px-4 py-3 rounded-lg border-2 min-w-[200px]
        bg-slate-50 border-slate-300
        ${selected ? 'border-slate-500 shadow-lg shadow-slate-200' : ''}
      `}
    >
      {/* Input Handle */}
      <Handle
        type="target"
        position={Position.Left}
        className="w-3 h-3 bg-slate-400 border-2 border-white"
      />
 
      {/* Output Handle */}
      <Handle
        type="source"
        position={Position.Right}
        className="w-3 h-3 bg-slate-500 border-2 border-white"
      />
 
      {/* Header */}
      <div className="flex items-center gap-2 mb-2">
        <span className="text-lg">🌐</span>
        <span className="font-medium text-slate-800">{data.label}</span>
      </div>
 
      {/* Method Badge */}
      <div className="flex items-center gap-2 mb-2">
        <span className={`text-xs font-bold px-2 py-0.5 rounded ${methodColors[data.method]}`}>
          {data.method}
        </span>
      </div>
 
      {/* URL */}
      <div className={`text-sm font-mono bg-slate-100 rounded px-2 py-1 truncate ${hasUrl ? 'text-slate-600' : 'text-slate-400 italic'}`}>
        {hasUrl ? data.url : 'No URL specified'}
      </div>
 
      {/* Headers Count */}
      {Object.keys(data.headers).length > 0 && (
        <div className="text-xs text-slate-500 mt-2">
          {Object.keys(data.headers).length} header(s)
        </div>
      )}
 
      {/* Body Indicator */}
      {data.body && (
        <div className="text-xs text-slate-500 mt-1">
          Has body content
        </div>
      )}
    </div>
  );
});
 
HttpNode.displayName = 'HttpNode';
 
export default HttpNode;