feat: meaningful labels by status
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
import { useCanvasStore } from '@/app/canvas/canvasStore'
|
||||
import { selectConnectionStatusForEdge } from '@/app/canvas/canvasStore.selectors'
|
||||
import { CONNECTION_STATUS_CLASS } from '@/lib/graph/connectionStatus'
|
||||
import { getConnectionLabelForTargetAndStatus } from '@/lib/graph/nodeRegistry'
|
||||
|
||||
const EDGE_STROKE_WIDTH = 2
|
||||
const DOT_MARKER_R = 1.5
|
||||
@@ -31,7 +32,10 @@ function AnimatedEdgeInner({
|
||||
)
|
||||
const statusClass = CONNECTION_STATUS_CLASS[connectionStatus]
|
||||
|
||||
const label = labelProp ?? (data as { connectionLabel?: string } | undefined)?.connectionLabel
|
||||
const targetType = (data as { targetType?: string } | undefined)?.targetType ?? ''
|
||||
const dataLabel = (data as { connectionLabel?: string } | undefined)?.connectionLabel
|
||||
const displayLabel =
|
||||
getConnectionLabelForTargetAndStatus(targetType, connectionStatus) ?? labelProp ?? dataLabel
|
||||
|
||||
const [edgePath, edgeLabelX, edgeLabelY] = getBezierPath({
|
||||
sourceX,
|
||||
@@ -92,7 +96,7 @@ function AnimatedEdgeInner({
|
||||
className={`animated-edge-path${statusClass ? ` ${statusClass}` : ''}`}
|
||||
interactionWidth={interactionWidth}
|
||||
/>
|
||||
{label != null && (
|
||||
{displayLabel != null && displayLabel !== '' && (
|
||||
<g transform={`translate(${edgeLabelX}, ${edgeLabelY})`} className="nodrag nopan">
|
||||
<rect
|
||||
x={-32}
|
||||
@@ -109,7 +113,7 @@ function AnimatedEdgeInner({
|
||||
dominantBaseline="middle"
|
||||
className="fill-foreground text-[10px] font-medium"
|
||||
>
|
||||
{label}
|
||||
{displayLabel}
|
||||
</text>
|
||||
</g>
|
||||
)}
|
||||
@@ -130,8 +134,10 @@ function edgePropsAreEqual(prev: EdgeProps, next: EdgeProps): boolean {
|
||||
prev.targetPosition === next.targetPosition &&
|
||||
prev.style === next.style &&
|
||||
prev.label === next.label &&
|
||||
(prev.data as { connectionLabel?: string } | undefined)?.connectionLabel ===
|
||||
(next.data as { connectionLabel?: string } | undefined)?.connectionLabel
|
||||
(prev.data as { connectionLabel?: string; targetType?: string } | undefined)?.connectionLabel ===
|
||||
(next.data as { connectionLabel?: string; targetType?: string } | undefined)?.connectionLabel &&
|
||||
(prev.data as { targetType?: string } | undefined)?.targetType ===
|
||||
(next.data as { targetType?: string } | undefined)?.targetType
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user