import { useMemo } from 'react'; import type { Node, SortKey, SortOrder } from '../types'; import { metricValue } from '../slices'; import { formatCount, formatMtime, formatSize, percent } from '../format'; interface FileTableProps { children: Node[]; colorMap: Map; apparent: boolean; useSIPrefix: boolean; total: number; sort: SortKey; order: SortOrder; onSortChange: (key: SortKey) => void; hoveredPath: string | null; onHover: (path: string | null) => void; onSelect: (node: Node) => void; } const COLUMNS: { key: SortKey; label: string; numeric: boolean }[] = [ { key: 'name', label: 'Name', numeric: false }, { key: 'size', label: 'Size', numeric: true }, { key: 'itemCount', label: 'Items', numeric: true }, { key: 'mtime', label: 'Modified', numeric: true }, ]; export function FileTable({ children, colorMap, apparent, useSIPrefix, total, sort, order, onSortChange, hoveredPath, onHover, onSelect, }: FileTableProps) { const maxValue = useMemo( () => children.reduce((max, n) => Math.max(max, metricValue(n, apparent)), 0), [children, apparent], ); return ( {COLUMNS.map((col) => ( ))} {children.map((node) => { const value = metricValue(node, apparent); const barWidth = maxValue > 0 ? (value / maxValue) * 100 : 0; const color = colorMap.get(node.path) ?? 'var(--other)'; const isHovered = node.path === hoveredPath; return ( onHover(node.path)} onMouseLeave={() => onHover(null)} onClick={() => node.isDir && onSelect(node)} style={{ cursor: node.isDir ? 'pointer' : 'default' }} > ); })} {children.length === 0 && ( )}
onSortChange(col.key)} > {col.label} {sort === col.key && ( {order === 'asc' ? ' ▲' : ' ▼'} )}
{node.isDir ? '📁' : '📄'} {node.name} {node.flag === '!' && !} {formatSize(value, useSIPrefix)} {formatCount(node.itemCount)} {formatMtime(node.mtime)}
Empty directory
{children.length} items {formatSize(total, useSIPrefix)} {percent(total, total) > 0 ? '100%' : ''}
); }