mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-12-04 22:21:21 +09:00
feat(19-4): Create custom ConnectionEdge component
- Extends smoothstep edge with labels - Shows connection type label (Routes to, Uses DB, etc.) - Color-coded by connection type - Selected state with glow effect - Delete button on selection Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
992d9cd14c
commit
7bad6c19e0
1 file changed
+80
@@ -0,0 +1,80 @@
|
||||
import React, { memo } from 'react';
|
||||
import { BaseEdge, EdgeLabelRenderer, getSmoothStepPath } from '@xyflow/react';
|
||||
import { X } from 'lucide-react';
|
||||
import { connectionLabels, connectionColors, getConnectionType } from '../../utils/connectionRules';
|
||||
|
||||
const ConnectionEdge = ({
|
||||
id,
|
||||
sourceX,
|
||||
sourceY,
|
||||
targetX,
|
||||
targetY,
|
||||
sourcePosition,
|
||||
targetPosition,
|
||||
source,
|
||||
target,
|
||||
sourceHandleId,
|
||||
selected,
|
||||
data,
|
||||
markerEnd
|
||||
}) => {
|
||||
const [edgePath, labelX, labelY] = getSmoothStepPath({
|
||||
sourceX,
|
||||
sourceY,
|
||||
sourcePosition,
|
||||
targetX,
|
||||
targetY,
|
||||
targetPosition,
|
||||
borderRadius: 8
|
||||
});
|
||||
|
||||
// Get connection type from data or derive from source/target
|
||||
const connectionType = data?.connectionType || getConnectionType(
|
||||
data?.sourceType || 'dockerApp',
|
||||
data?.targetType || 'dockerApp'
|
||||
);
|
||||
|
||||
const label = connectionLabels[connectionType] || 'Connected';
|
||||
const color = connectionColors[connectionType] || '#6366f1';
|
||||
|
||||
return (
|
||||
<>
|
||||
<BaseEdge
|
||||
id={id}
|
||||
path={edgePath}
|
||||
markerEnd={markerEnd}
|
||||
style={{
|
||||
stroke: selected ? '#fff' : color,
|
||||
strokeWidth: selected ? 2 : 1.5,
|
||||
filter: selected ? 'drop-shadow(0 0 4px rgba(255,255,255,0.5))' : 'none'
|
||||
}}
|
||||
/>
|
||||
<EdgeLabelRenderer>
|
||||
<div
|
||||
className={`edge-label ${selected ? 'edge-label-selected' : ''}`}
|
||||
style={{
|
||||
position: 'absolute',
|
||||
transform: `translate(-50%, -50%) translate(${labelX}px,${labelY}px)`,
|
||||
pointerEvents: 'all',
|
||||
backgroundColor: selected ? '#fff' : color
|
||||
}}
|
||||
>
|
||||
<span className="edge-label-text">{label}</span>
|
||||
{selected && data?.onDelete && (
|
||||
<button
|
||||
className="edge-delete-btn"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
data.onDelete(id);
|
||||
}}
|
||||
>
|
||||
<X size={12} />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</EdgeLabelRenderer>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default memo(ConnectionEdge);
|
||||
Reference in new issue
Block a user