@@ -60,6 +60,35 @@ function CategorySummary({
6060 ) ;
6161}
6262
63+ type SortMode =
64+ | "name"
65+ | "pass-rate-desc"
66+ | "pass-rate-asc"
67+ | "pass-count-desc"
68+ | "pass-count-asc" ;
69+
70+ function getSortValue (
71+ report : DayReport ,
72+ testNames : string [ ] ,
73+ mode : SortMode ,
74+ ) : number {
75+ // Aggregate across all available OSes for sorting
76+ let totalPass = 0 ;
77+ let totalCount = 0 ;
78+ for ( const os of [ "linux" , "windows" , "darwin" ] as const ) {
79+ const r = report [ os ] ;
80+ if ( ! r ) continue ;
81+ const rate = getRateForSubset ( r , testNames ) ;
82+ if ( rate ) {
83+ totalPass += rate . pass ;
84+ totalCount += rate . total ;
85+ }
86+ }
87+ if ( totalCount === 0 ) return mode . includes ( "desc" ) ? - 1 : Infinity ;
88+ if ( mode . startsWith ( "pass-rate" ) ) return totalPass / totalCount ;
89+ return totalPass ;
90+ }
91+
6392export function ReportTable ( props : { class ?: string ; report : DayReport } ) {
6493 const { report } = props ;
6594
@@ -68,6 +97,7 @@ export function ReportTable(props: { class?: string; report: DayReport }) {
6897 const date = report . date ;
6998
7099 const [ expanded , setExpanded ] = useState < Record < string , boolean > > ( { } ) ;
100+ const [ sortMode , setSortMode ] = useState < SortMode > ( "name" ) ;
71101
72102 const toggleCategory = ( category : string ) => {
73103 setExpanded ( ( prev ) => ( { ...prev , [ category ] : ! prev [ category ] } ) ) ;
@@ -85,24 +115,59 @@ export function ReportTable(props: { class?: string; report: DayReport }) {
85115 setExpanded ( { } ) ;
86116 } ;
87117
118+ const sortedCategories = sortMode === "name"
119+ ? testCategories
120+ : [ ...testCategories ] . sort ( ( a , b ) => {
121+ const va = getSortValue ( report , a [ 1 ] , sortMode ) ;
122+ const vb = getSortValue ( report , b [ 1 ] , sortMode ) ;
123+ return sortMode . endsWith ( "desc" ) ? vb - va : va - vb ;
124+ } ) ;
125+
88126 return (
89127 < div class = { props . class ?? "" } >
90- < div class = "flex justify-end gap-2 mb-2 px-3" >
91- < button
92- type = "button"
93- onClick = { expandAll }
94- class = "text-xs text-blue-500 dark:text-blue-400 hover:underline"
95- >
96- Expand all
97- </ button >
98- < span class = "text-gray-400" > |</ span >
99- < button
100- type = "button"
101- onClick = { collapseAll }
102- class = "text-xs text-blue-500 dark:text-blue-400 hover:underline"
103- >
104- Collapse all
105- </ button >
128+ < div class = "flex flex-wrap items-center justify-between gap-2 mb-2 px-3" >
129+ < div class = "flex items-center gap-1 text-xs text-gray-600 dark:text-gray-400" >
130+ < span > Sort:</ span >
131+ { (
132+ [
133+ [ "name" , "Name" ] ,
134+ [ "pass-rate-desc" , "Rate \u2193" ] ,
135+ [ "pass-rate-asc" , "Rate \u2191" ] ,
136+ [ "pass-count-desc" , "Passing \u2193" ] ,
137+ [ "pass-count-asc" , "Passing \u2191" ] ,
138+ ] as [ SortMode , string ] [ ]
139+ ) . map ( ( [ mode , label ] ) => (
140+ < button
141+ key = { mode }
142+ type = "button"
143+ onClick = { ( ) => setSortMode ( mode ) }
144+ class = { `px-1.5 py-0.5 rounded ${
145+ sortMode === mode
146+ ? "bg-blue-500 text-white dark:bg-blue-600"
147+ : "text-blue-500 dark:text-blue-400 hover:underline"
148+ } `}
149+ >
150+ { label }
151+ </ button >
152+ ) ) }
153+ </ div >
154+ < div class = "flex gap-2" >
155+ < button
156+ type = "button"
157+ onClick = { expandAll }
158+ class = "text-xs text-blue-500 dark:text-blue-400 hover:underline"
159+ >
160+ Expand all
161+ </ button >
162+ < span class = "text-gray-400" > |</ span >
163+ < button
164+ type = "button"
165+ onClick = { collapseAll }
166+ class = "text-xs text-blue-500 dark:text-blue-400 hover:underline"
167+ >
168+ Collapse all
169+ </ button >
170+ </ div >
106171 </ div >
107172 < table class = "border-collapse table-fixed w-full" >
108173 < thead >
@@ -156,7 +221,7 @@ export function ReportTable(props: { class?: string; report: DayReport }) {
156221 </ th >
157222 </ tr >
158223 </ thead >
159- { testCategories . map ( ( [ category , testNames ] ) => {
224+ { sortedCategories . map ( ( [ category , testNames ] ) => {
160225 testNames . sort ( ) ;
161226 const linux = report . linux ;
162227 const windows = report . windows ;
0 commit comments