@@ -18,6 +18,7 @@ import {
18
18
type MRT_Updater ,
19
19
type MRT_ColumnFiltersState ,
20
20
type MRT_TableOptions ,
21
+ type MRT_TableInstance ,
21
22
} from 'material-react-table' ;
22
23
import { type Theme } from "@mui/material/styles" ;
23
24
import { parse } from "date-fns" ;
@@ -35,21 +36,15 @@ import {
35
36
RunStatuses ,
36
37
} from "../../lib/paddles.d" ;
37
38
import useDefaultTableOptions from "../../lib/table" ;
39
+ import Typography from '@mui/material/Typography' ;
40
+ import Box from '@mui/material/Box' ;
38
41
39
42
40
43
const DEFAULT_PAGE_SIZE = 25 ;
41
44
const NON_FILTER_PARAMS = [
42
45
"page" ,
43
46
"pageSize" ,
44
47
] ;
45
- const FILTER_COLUMNS = [
46
- "status" ,
47
- "scheduled" ,
48
- "suite" ,
49
- "branch" ,
50
- "machine_type" ,
51
- "sha1" ,
52
- ]
53
48
54
49
const _columns : MRT_ColumnDef < Run > [ ] = [
55
50
{
@@ -289,6 +284,7 @@ export default function RunList(props: RunListProps) {
289
284
} ,
290
285
onColumnFiltersChange,
291
286
columnFilterDisplayMode : 'custom' ,
287
+ enableColumnFilters : false ,
292
288
muiFilterTextFieldProps : ( { column } ) => ( {
293
289
label : `Filter by ${ column . columnDef . header } ` ,
294
290
} ) ,
@@ -321,30 +317,76 @@ export default function RunList(props: RunListProps) {
321
317
if ( query . isError ) return null ;
322
318
return (
323
319
< div >
324
- { openFilterMenu ? (
325
- < Grid container spacing = { 3 } style = { { padding : "10px" } } >
320
+ < Button onClick = { toggleFilterMenu ( ! openFilterMenu ) } >
321
+ { openFilterMenu ? "Hide" : "Show" } Filters
322
+ </ Button >
323
+ < FilterMenu isOpen = { openFilterMenu } table = { table } />
324
+ < MaterialReactTable table = { table } />
325
+ </ div >
326
+ )
327
+ }
328
+
329
+
330
+ // FilterMenu
331
+
332
+ type FilterMenuProps = {
333
+ isOpen : boolean ;
334
+ table : MRT_TableInstance < Run > ;
335
+ } ;
336
+
337
+
338
+ const FILTER_SECTIONS = [ "run" , "build" , "result" ]
339
+ const FILTER_SECTIONS_COLUMNS = [
340
+ [ "scheduled" , "suite" , "machine_type" ] ,
341
+ [ "branch" , "sha1" ] ,
342
+ [ "status" ] ,
343
+ ]
344
+
345
+ function FilterMenu ( { isOpen, table} : FilterMenuProps ) {
346
+ if ( ! isOpen ) {
347
+ return null ;
348
+ }
349
+
350
+ return (
351
+ < Box
352
+ sx = { {
353
+ padding : '0.5em' ,
354
+ margin : '1em' ,
355
+ border : '2px dashed grey' ,
356
+ borderRadius : '8px' ,
357
+ maxWidth : '100%' ,
358
+ } }
359
+ >
360
+ { FILTER_SECTIONS_COLUMNS . map ( ( _ , sectionIndex ) => (
361
+ < Box
362
+ key = { `section-${ sectionIndex } ` }
363
+ sx = { {
364
+ marginBottom : '1.5em' ,
365
+ paddingBottom : '0.5em' ,
366
+ marginLeft : '0.5em' ,
367
+ } }
368
+ >
369
+ < Typography variant = "body2" gutterBottom color = "gray" >
370
+ Filter by { FILTER_SECTIONS [ sectionIndex ] } details...
371
+ </ Typography >
372
+ < Grid container spacing = { 1 } alignItems = "center" >
326
373
{ table . getLeafHeaders ( ) . map ( ( header ) => {
327
- console . log ( header . id )
328
- if ( FILTER_COLUMNS . includes ( header . id ) ) {
374
+ if ( FILTER_SECTIONS_COLUMNS [ sectionIndex ] . includes ( header . id ) ) {
329
375
return (
330
- < Grid item xs = { 2 } >
376
+ < Grid item xs = { 2 } key = { header . id } marginLeft = { "1.5em" } >
331
377
< MRT_TableHeadCellFilterContainer
332
- key = { header . id }
333
378
header = { header }
334
379
table = { table }
335
- style = { { backgroundColor : "None" } }
336
- in
380
+ style = { { backgroundColor : 'transparent' , width : '100%' } }
337
381
/>
338
382
</ Grid >
339
- )
340
- }
383
+ ) ;
384
+ }
385
+ return null ;
341
386
} ) }
342
- </ Grid > )
343
- : "" }
344
- < Button onClick = { toggleFilterMenu ( ! openFilterMenu ) } >
345
- { openFilterMenu ? "Hide" : "Show" } Filters
346
- </ Button >
347
- < MaterialReactTable table = { table } />
348
- </ div >
349
- )
387
+ </ Grid >
388
+ </ Box >
389
+ ) ) }
390
+ </ Box >
391
+ )
350
392
}
0 commit comments