(props: Props)
| 13 | * This view is simpler and generally preferable for short lists of files. |
| 14 | */ |
| 15 | export function FileList(props: Props) { |
| 16 | const {filePairs, selectedIndex, fileChangeHandler} = props; |
| 17 | |
| 18 | const anyWithDiffstats = filePairs.some(fp => fp.num_add !== null || fp.num_delete !== null); |
| 19 | const maxDelta = React.useMemo(() => { |
| 20 | return Math.max(1, ...filePairs.map(fp => (fp.num_add ?? 0) + (fp.num_delete ?? 0))); |
| 21 | }, [filePairs]); |
| 22 | |
| 23 | const lis = filePairs.map((filePair, idx) => { |
| 24 | const displayName = filePairDisplayName(filePair); |
| 25 | const content = |
| 26 | idx !== selectedIndex ? ( |
| 27 | <a |
| 28 | onClick={() => { |
| 29 | fileChangeHandler(idx); |
| 30 | }} |
| 31 | href="#"> |
| 32 | {displayName} |
| 33 | </a> |
| 34 | ) : ( |
| 35 | <b>{displayName}</b> |
| 36 | ); |
| 37 | return ( |
| 38 | <li key={idx}> |
| 39 | {anyWithDiffstats ? ( |
| 40 | <SparkChart |
| 41 | maxDelta={maxDelta} |
| 42 | numAdd={filePair.num_add} |
| 43 | numDelete={filePair.num_delete} |
| 44 | /> |
| 45 | ) : null} |
| 46 | <span title={filePair.type} className={`diff ${filePair.type}`} /> |
| 47 | {content} |
| 48 | </li> |
| 49 | ); |
| 50 | }); |
| 51 | return <ul className="file-list">{lis}</ul>; |
| 52 | } |
| 53 | |
| 54 | interface SparkChartProps { |
| 55 | maxDelta: number; |
nothing calls this directly
no test coverage detected