@@ -19,60 +19,41 @@ export const StatusFilter: React.FC<StatusFilterProps> = ({
1919 onStatusChange,
2020 counts,
2121} ) => {
22- const filters : { value : StatusFilterValue ; label : string } [ ] = [
23- { value : 'all' , label : 'All' } ,
24- { value : 'pending' , label : 'Pending' } ,
25- { value : 'running' , label : 'Running' } ,
26- { value : 'completed' , label : 'Completed' } ,
27- { value : 'failed' , label : 'Failed' } ,
28- ] ;
22+ const formatLabel = ( value : StatusFilterValue ) : string => {
23+ if ( value === 'all' ) {
24+ return `All Runs${ counts ? ` (${ counts . all } )` : '' } ` ;
25+ }
2926
30- return (
31- < div className = "mb-4 flex items-center gap-2" >
32- < span className = "text-sm font-medium text-gray-700 dark:text-gray-300" >
33- Filter by status:
34- </ span >
35- < div className = "inline-flex rounded-md shadow-sm" role = "group" >
36- { filters . map ( ( filter , index ) => {
37- const isActive = currentStatus === filter . value ;
38- const count = counts ?. [ filter . value ] ;
27+ const labels : Record < Exclude < StatusFilterValue , 'all' > , string > = {
28+ pending : 'Pending' ,
29+ running : 'Running' ,
30+ completed : 'Completed' ,
31+ failed : 'Failed' ,
32+ } ;
33+
34+ const label = labels [ value as Exclude < StatusFilterValue , 'all' > ] ;
35+ const count = counts ?. [ value ] ;
3936
40- return (
41- < button
42- key = { filter . value }
43- type = "button"
44- onClick = { ( ) => onStatusChange ( filter . value ) }
45- className = { `
46- px-4 py-2 text-sm font-medium
47- ${ index === 0 ? 'rounded-l-lg' : '' }
48- ${ index === filters . length - 1 ? 'rounded-r-lg' : '' }
49- ${
50- isActive
51- ? 'bg-blue-600 text-white hover:bg-blue-700 dark:bg-blue-700 dark:hover:bg-blue-800'
52- : 'bg-white text-gray-700 hover:bg-gray-50 dark:bg-gray-800 dark:text-gray-300 dark:hover:bg-gray-700'
53- }
54- border border-gray-300 dark:border-gray-600
55- ${ index !== 0 ? 'border-l-0' : '' }
56- focus:z-10 focus:ring-2 focus:ring-blue-500 focus:outline-none
57- transition-colors duration-200
58- ` }
59- >
60- { filter . label }
61- { count !== undefined && count > 0 && (
62- < span
63- className = { `ml-2 px-2 py-0.5 text-xs rounded-full ${
64- isActive
65- ? 'bg-blue-500 text-white'
66- : 'bg-gray-200 text-gray-700 dark:bg-gray-700 dark:text-gray-300'
67- } `}
68- >
69- { count }
70- </ span >
71- ) }
72- </ button >
73- ) ;
74- } ) }
75- </ div >
37+ return count !== undefined ? `${ label } (${ count } )` : label ;
38+ } ;
39+
40+ return (
41+ < div className = "flex items-center gap-2" >
42+ < label htmlFor = "status-filter" className = "text-sm font-medium text-gray-700 dark:text-gray-300" >
43+ Status:
44+ </ label >
45+ < select
46+ id = "status-filter"
47+ value = { currentStatus }
48+ onChange = { ( e ) => onStatusChange ( e . target . value as StatusFilterValue ) }
49+ className = "rounded-md border-gray-300 dark:border-gray-600 dark:bg-gray-700 dark:text-white shadow-sm focus:border-blue-500 focus:ring-blue-500 px-3 py-2"
50+ >
51+ < option value = "all" > { formatLabel ( 'all' ) } </ option >
52+ < option value = "pending" > { formatLabel ( 'pending' ) } </ option >
53+ < option value = "running" > { formatLabel ( 'running' ) } </ option >
54+ < option value = "completed" > { formatLabel ( 'completed' ) } </ option >
55+ < option value = "failed" > { formatLabel ( 'failed' ) } </ option >
56+ </ select >
7657 </ div >
7758 ) ;
7859} ;
0 commit comments