import React from 'react'; import * as ContextMenu from '@radix-ui/react-context-menu'; import type { FileTreeNode as TreeNode } from '../utils/buildFileTree'; interface FileTreeNodeProps { node: TreeNode; expandedFolders: Set; onToggleFolder: (path: string) => void; activeFileIndex: number; onSelectFile: (index: number) => void; onDoubleClickFile?: (index: number) => void; viewedFiles: Set; onToggleViewed?: (filePath: string) => void; hideViewedFiles: boolean; getAnnotationCount: (filePath: string) => number; stagedFiles?: Set; scrollHighlightIndex?: number; /** Absolute repo root used to build the "Copy full path" menu item. Null in PR-review mode (files aren't on local disk). */ repoRoot?: string | null; } function hasVisibleChildren( node: TreeNode, viewedFiles: Set, activeFileIndex: number, hideViewedFiles: boolean, ): boolean { if (!hideViewedFiles) return true; if (!node.children) return false; return node.children.some(child => { if (child.type === 'file') { return child.fileIndex === activeFileIndex || !viewedFiles.has(child.path); } return hasVisibleChildren(child, viewedFiles, activeFileIndex, hideViewedFiles); }); } export const FileTreeNodeItem: React.FC = ({ node, expandedFolders, onToggleFolder, activeFileIndex, onSelectFile, onDoubleClickFile, viewedFiles, onToggleViewed, hideViewedFiles, getAnnotationCount, stagedFiles, scrollHighlightIndex, repoRoot, }) => { const paddingLeft = 4 + node.depth * 8; if (node.type === 'folder') { if (!hasVisibleChildren(node, viewedFiles, activeFileIndex, hideViewedFiles)) { return null; } const isExpanded = expandedFolders.has(node.path); return ( <> {isExpanded && node.children?.map(child => ( ))} ); } // File node const isActive = node.fileIndex === activeFileIndex; const isScrollActive = !isActive && scrollHighlightIndex != null && node.fileIndex === scrollHighlightIndex; const isViewed = viewedFiles.has(node.path); const isStaged = stagedFiles?.has(node.path) ?? false; const annotationCount = getAnnotationCount(node.path); if (hideViewedFiles && isViewed && !isActive) { return null; } return ( navigator.clipboard.writeText(node.path)} className="flex items-center gap-2 mx-1 px-2 py-1.5 text-xs rounded cursor-pointer outline-none text-foreground/80 data-[highlighted]:bg-muted data-[highlighted]:text-foreground" > Copy path navigator.clipboard.writeText(node.name)} className="flex items-center gap-2 mx-1 px-2 py-1.5 text-xs rounded cursor-pointer outline-none text-foreground/80 data-[highlighted]:bg-muted data-[highlighted]:text-foreground" > Copy filename {repoRoot && ( navigator.clipboard.writeText(`${repoRoot.replace(/\/$/, '')}/${node.path}`)} className="flex items-center gap-2 mx-1 px-2 py-1.5 text-xs rounded cursor-pointer outline-none text-foreground/80 data-[highlighted]:bg-muted data-[highlighted]:text-foreground" > Copy full path )} ); };