/**
* Visual mini-DAG diagram showing block relationships.
* Displays parent blocks → current block → child blocks.
*/
import { Link } from 'react-router-dom';
import { ArrowDown, Box, Layers } from 'lucide-react';
import { truncateHash } from '../lib/utils';
import { cn } from '../lib/utils';
interface BlockRelationshipDiagramProps {
currentHash: string;
parentHashes: string[];
childrenHashes: string[];
isChainBlock?: boolean;
mergeSetBlues?: string[];
mergeSetReds?: string[];
}
export default function BlockRelationshipDiagram({
currentHash,
parentHashes,
childrenHashes,
isChainBlock = true,
mergeSetBlues = [],
mergeSetReds = [],
}: BlockRelationshipDiagramProps) {
// Determine selected parent (first one by convention)
const selectedParent = parentHashes[0];
const otherParents = parentHashes.slice(1);
return (
{/* Background gradient */}
{/* Header */}
Block Relationships
{/* Parent Blocks */}
{parentHashes.length > 0 && (
<>
{selectedParent && (
)}
{otherParents.map((hash) => (
))}
{/* Arrow down */}
>
)}
{/* Current Block - Highlighted */}
{/* Glow effect */}
Current Block
{truncateHash(currentHash, 8, 8)}
{/* Chain block indicator */}
{isChainBlock && (
Chain
)}
{/* Arrow down to children */}
{childrenHashes.length > 0 && (
<>
{/* Child Blocks */}
{childrenHashes.map((hash) => (
))}
>
)}
{/* Merge set info */}
{(mergeSetBlues.length > 0 || mergeSetReds.length > 0) && (
{mergeSetBlues.length > 0 && (
{mergeSetBlues.length} blue merge
)}
{mergeSetReds.length > 0 && (
{mergeSetReds.length} red merge
)}
)}
);
}
interface BlockNodeProps {
hash: string;
type: 'parent' | 'child';
isSelected?: boolean;
label: string;
}
function BlockNode({ hash, type, isSelected, label }: BlockNodeProps) {
return (
{label}
{truncateHash(hash, 6, 6)}
{/* Selected indicator */}
{isSelected && (
)}
);
}