1- import { useEffect , useState } from 'react' ;
1+ import { useMemo , useEffect , useState } from 'react' ;
22import { Link } from 'react-router-dom' ;
33import {
44 Anchor ,
@@ -17,7 +17,7 @@ import {
1717import { SortableHeader } from '../components/SortableHeader' ;
1818import { TestHistory } from '../components/TestHistory' ;
1919import { TestRow } from '../components/TestRow' ;
20- import { SortColumn , TestRecord } from '../types' ;
20+ import { SortColumn , SortDirection , TestRecord } from '../types' ;
2121import { sortRecords } from '../utils' ;
2222
2323export default function Home ( ) {
@@ -26,6 +26,8 @@ export default function Home() {
2626 const [ selectedHardware , setSelectedHardware ] = useState < Set < string > > ( new Set ( ) ) ;
2727 const [ adminToken , setAdminToken ] = useState ( '' ) ;
2828 const [ selectedRecord , setSelectedRecord ] = useState < TestRecord | null > ( null ) ;
29+ const [ sortCol , setSortCol ] = useState < SortColumn > ( 'pixelError' ) ;
30+ const [ sortDir , setSortDir ] = useState < SortDirection > ( 'desc' ) ;
2931
3032 useEffect ( ( ) => {
3133 fetch ( '/api/test-records' )
@@ -34,12 +36,13 @@ export default function Home() {
3436 const hardwares = [ ...new Set ( data . map ( ( r ) => r . hardware ) ) ] . sort ( ) ;
3537 setAllHardware ( hardwares ) ;
3638 setSelectedHardware ( new Set ( hardwares ) ) ;
37- setRecords ( sortRecords ( data , 'pixelError' ) ) ;
39+ setRecords ( data ) ;
3840 } ) ;
3941 } , [ ] ) ;
4042
4143 function handleSort ( column : SortColumn ) {
42- setRecords ( ( prev ) => sortRecords ( prev , column ) ) ;
44+ setSortDir ( ( prev ) => ( column === sortCol ? ( prev === 'asc' ? 'desc' : 'asc' ) : 'asc' ) ) ;
45+ setSortCol ( column ) ;
4346 }
4447
4548 function toggleHardware ( hw : string ) {
@@ -74,7 +77,10 @@ export default function Home() {
7477 }
7578 }
7679
77- const visibleRecords = records . filter ( ( r ) => selectedHardware . has ( r . hardware ) ) ;
80+ const visibleRecords = useMemo (
81+ ( ) => sortRecords ( records , sortCol , sortDir ) . filter ( ( r ) => selectedHardware . has ( r . hardware ) ) ,
82+ [ records , sortCol , sortDir , selectedHardware ]
83+ ) ;
7884
7985 return (
8086 < Box >
@@ -142,16 +148,18 @@ export default function Home() {
142148 < Table striped highlightOnHover withColumnBorders stickyHeader >
143149 < Table . Thead >
144150 < Table . Tr >
145- < SortableHeader sortKey = { 'pixelError' } label = { 'Error' } onSort = { handleSort } />
146- < SortableHeader sortKey = { 'group' } label = { 'Group' } onSort = { handleSort } />
147- < SortableHeader sortKey = { 'name' } label = { 'Name' } onSort = { handleSort } />
148- < SortableHeader sortKey = { 'hardware' } label = { 'Hardware' } onSort = { handleSort } />
149- < SortableHeader sortKey = { 'timing' } label = { 'Timing' } onSort = { handleSort } />
150- < SortableHeader sortKey = { 'commitHash' } label = { 'Commit' } onSort = { handleSort } />
151+ < SortableHeader sortKey = { 'pixelError' } label = { 'Error' } onSort = { handleSort } activeColumn = { sortCol } direction = { sortDir } />
152+ < SortableHeader sortKey = { 'group' } label = { 'Group' } onSort = { handleSort } activeColumn = { sortCol } direction = { sortDir } />
153+ < SortableHeader sortKey = { 'name' } label = { 'Name' } onSort = { handleSort } activeColumn = { sortCol } direction = { sortDir } />
154+ < SortableHeader sortKey = { 'hardware' } label = { 'Hardware' } onSort = { handleSort } activeColumn = { sortCol } direction = { sortDir } />
155+ < SortableHeader sortKey = { 'timing' } label = { 'Timing' } onSort = { handleSort } activeColumn = { sortCol } direction = { sortDir } />
156+ < SortableHeader sortKey = { 'commitHash' } label = { 'Commit' } onSort = { handleSort } activeColumn = { sortCol } direction = { sortDir } />
151157 < SortableHeader
152158 sortKey = { 'timeStamp' }
153159 label = { 'Timestamp' }
154160 onSort = { handleSort }
161+ activeColumn = { sortCol }
162+ direction = { sortDir }
155163 />
156164 < Table . Th > Candidate</ Table . Th >
157165 < Table . Th > Reference</ Table . Th >
0 commit comments