({ entries, onNodeSelect }: Props)
| 51 | |
| 52 | /** Hierarchical tree view with CSS-based tree-line connectors */ |
| 53 | export default function TraverseResult({ entries, onNodeSelect }: Props) { |
| 54 | const [expanded, setExpanded] = useState(false); |
| 55 | |
| 56 | if (entries.length === 0) { |
| 57 | return <p className="result-empty">No results found.</p>; |
| 58 | } |
| 59 | |
| 60 | const visible = expanded ? entries : entries.slice(0, INITIAL_LIMIT); |
| 61 | const hasMore = entries.length > INITIAL_LIMIT; |
| 62 | const lastAtDepth = computeLastAtDepth(visible); |
| 63 | |
| 64 | return ( |
| 65 | <div className="result-traverse"> |
| 66 | {visible.map((entry, i) => { |
| 67 | const { node, relationship, depth } = entry; |
| 68 | const color = getNodeColor(node.type); |
| 69 | const isRoot = depth === 0; |
| 70 | const isLast = lastAtDepth.has(i); |
| 71 | |
| 72 | const classes = [ |
| 73 | 'result-traverse-entry', |
| 74 | isRoot && 'root-entry', |
| 75 | isLast && 'last-at-depth', |
| 76 | ] |
| 77 | .filter(Boolean) |
| 78 | .join(' '); |
| 79 | |
| 80 | return ( |
| 81 | <div |
| 82 | key={`${node.id}-${i}`} |
| 83 | className={classes} |
| 84 | style={{ paddingLeft: isRoot ? 0 : depth * 20 }} |
| 85 | > |
| 86 | {relationship && relationship.type && ( |
| 87 | <span className="result-traverse-rel">{relationship.type} →</span> |
| 88 | )} |
| 89 | <div |
| 90 | className="result-traverse-node" |
| 91 | onClick={() => onNodeSelect?.(node.id)} |
| 92 | > |
| 93 | <span className="result-type-badge" style={{ background: color }}> |
| 94 | {node.type} |
| 95 | </span> |
| 96 | <span className="result-node-name">{node.name}</span> |
| 97 | </div> |
| 98 | </div> |
| 99 | ); |
| 100 | })} |
| 101 | {hasMore && ( |
| 102 | <button |
| 103 | className="result-show-more" |
| 104 | onClick={() => setExpanded(!expanded)} |
| 105 | > |
| 106 | {expanded ? 'Show less' : `Show all ${entries.length}`} |
| 107 | </button> |
| 108 | )} |
| 109 | </div> |
| 110 | ); |
nothing calls this directly
no test coverage detected