@@ -489,21 +489,220 @@ function ViewAsFasta({
489
489
) ;
490
490
}
491
491
492
+ const readingFrameOptions = {
493
+ ALL : { label : "All" , filter : [ - 3 , - 2 , - 1 , 1 , 2 , 3 ] } ,
494
+ FORWARD : { label : "Forward" , filter : [ 1 , 2 , 3 ] } ,
495
+ REVERSE : { label : "Reverse" , filter : [ - 1 , - 2 , - 3 ] } ,
496
+ FIRST_FORWARD : { label : "First forward" , filter : [ 1 ] } ,
497
+ FIRST_REVERSE : { label : "First reverse" , filter : [ - 1 ] } ,
498
+ } ;
499
+
500
+ const orfHeadCells = [
501
+ {
502
+ id : "fullRangeBegin" ,
503
+ numeric : false ,
504
+ disablePadding : false ,
505
+ label : "Full Range Begin" ,
506
+ } ,
507
+ {
508
+ id : "fullRangeEnd" ,
509
+ numeric : false ,
510
+ disablePadding : false ,
511
+ label : "Full Range End" ,
512
+ } ,
513
+ {
514
+ id : "molecularWeight" ,
515
+ numeric : false ,
516
+ disablePadding : false ,
517
+ label : "Molecular Weight" ,
518
+ } ,
519
+ {
520
+ id : "readingFrame" ,
521
+ numeric : false ,
522
+ disablePadding : false ,
523
+ label : "Reading Frame" ,
524
+ } ,
525
+ {
526
+ id : "translation" ,
527
+ numeric : false ,
528
+ disablePadding : false ,
529
+ label : "Translation" ,
530
+ } ,
531
+ ] ;
532
+
492
533
function OrfTable ( {
493
534
show,
535
+ file,
494
536
idOfOrfTableTab,
495
537
} : { |
496
538
show : boolean ,
539
+ file : GalleryFile ,
497
540
idOfOrfTableTab : string ,
498
541
| } ) {
542
+ const [ order , setOrder ] = React . useState ( "desc" ) ;
543
+ const [ orderBy , setOrderBy ] = React . useState ( "version" ) ;
544
+ const [ page , setPage ] = React . useState ( 0 ) ;
545
+ const [ rowsPerPage , setRowsPerPage ] = React . useState ( 10 ) ;
546
+ const [ loading , setLoading ] = React . useState ( true ) ;
547
+ const [ readingFrameOption , setReadingFrameOption ] = React . useState ( "ALL" ) ;
548
+ const [ results , setResults ] = React . useState ( [ ] ) ;
549
+ const [ filteredResults , setFilteredResults ] = React . useState ( [ ] ) ;
550
+
551
+ const filterResults = ( passed_results ) => {
552
+ passed_results = passed_results || results ; // in case the results are not set yet
553
+ const to_include = readingFrameOptions [ readingFrameOption ] . filter ;
554
+ const filtered = passed_results . filter ( ( r ) =>
555
+ to_include . includes ( r . readingFrame )
556
+ ) ;
557
+ setFilteredResults ( filtered ) ;
558
+ } ;
559
+
560
+ const fetchData = ( ) => {
561
+ setLoading ( true ) ;
562
+
563
+ const url = `/molbiol/dna/orfs/${ file . id } ` ;
564
+ axios
565
+ . get ( url )
566
+ . then ( ( response ) => {
567
+ setResults ( response . data . ORFs ) ;
568
+ filterResults ( response . data . ORFs ) ;
569
+ } )
570
+ . catch ( ( error ) => {
571
+ RS . confirm ( error . response . data , "warning" , "infinite" ) ;
572
+ } )
573
+ . finally ( ( ) => {
574
+ setLoading ( false ) ;
575
+ } ) ;
576
+ } ;
577
+
578
+ React . useEffect ( ( ) => {
579
+ fetchData ( ) ;
580
+ /* eslint-disable-next-line react-hooks/exhaustive-deps --
581
+ * - fetchData will not meaningfully change
582
+ */
583
+ } , [ ] ) ;
584
+
585
+ React . useEffect ( ( ) => {
586
+ setPage ( 0 ) ;
587
+ filterResults ( ) ;
588
+ /* eslint-disable-next-line react-hooks/exhaustive-deps --
589
+ * - filterResultswill not meaningfully change
590
+ */
591
+ } , [ readingFrameOption ] ) ;
592
+
593
+ const handleRequestSort = ( event , property ) => {
594
+ const isDesc = orderBy === property && order === "desc" ;
595
+ setOrder ( isDesc ? "asc" : "desc" ) ;
596
+ setOrderBy ( property ) ;
597
+ setPage ( 0 ) ;
598
+ } ;
599
+
600
+ const handleChangePage = ( event , newPage ) => {
601
+ setPage ( newPage ) ;
602
+ } ;
603
+
604
+ const handleChangeRowsPerPage = ( event ) => {
605
+ setRowsPerPage ( parseInt ( event . target . value , 10 ) ) ;
606
+ setPage ( 0 ) ;
607
+ } ;
608
+
609
+ const emptyRows =
610
+ rowsPerPage -
611
+ Math . min ( rowsPerPage , filteredResults . length - page * rowsPerPage ) ;
612
+
499
613
return (
500
- < section
614
+ < Grid
615
+ container
616
+ spacing = { 2 }
617
+ flexWrap = "nowrap"
618
+ component = "section"
501
619
role = "tabpanel"
502
620
style = { { display : show ? "flex" : "none" } }
503
621
aria-labelledby = { idOfOrfTableTab }
504
622
>
505
- ORF Table
506
- </ section >
623
+ < Grid item sx = { { minWidth : 0 } } >
624
+ { loading && < LoadingCircular /> }
625
+ { ! loading && (
626
+ < >
627
+ < TableContainer style = { { maxHeight : "449px" } } >
628
+ < Table
629
+ stickyHeader
630
+ aria-labelledby = "ORF table"
631
+ size = "small"
632
+ aria-label = "enhanced table"
633
+ >
634
+ < EnhancedTableHead
635
+ headCells = { orfHeadCells }
636
+ order = { order }
637
+ orderBy = { orderBy }
638
+ onRequestSort = { handleRequestSort }
639
+ rowCount = { filteredResults . length }
640
+ />
641
+ < TableBody >
642
+ { stableSort ( filteredResults , getSorting ( order , orderBy ) )
643
+ . slice ( page * rowsPerPage , page * rowsPerPage + rowsPerPage )
644
+ . map ( ( result ) => (
645
+ < TableRow hover tabIndex = { - 1 } key = { result . id } >
646
+ < TableCell align = "left" >
647
+ { result . fullRangeBegin }
648
+ </ TableCell >
649
+ < TableCell align = "left" >
650
+ { result . fullRangeEnd }
651
+ </ TableCell >
652
+ < TableCell align = "left" >
653
+ { result . molecularWeight }
654
+ </ TableCell >
655
+ < TableCell align = "left" >
656
+ { result . readingFrame }
657
+ </ TableCell >
658
+ < TableCell align = "left" > { result . translation } </ TableCell >
659
+ </ TableRow >
660
+ ) ) }
661
+ { emptyRows > 0 && (
662
+ < TableRow style = { { height : 33 * emptyRows } } >
663
+ < TableCell colSpan = { 6 } />
664
+ </ TableRow >
665
+ ) }
666
+ </ TableBody >
667
+ </ Table >
668
+ </ TableContainer >
669
+ < TablePagination
670
+ rowsPerPageOptions = { paginationOptions ( filteredResults . length ) }
671
+ component = "div"
672
+ count = { filteredResults . length }
673
+ rowsPerPage = { rowsPerPage }
674
+ page = { page }
675
+ onPageChange = { handleChangePage }
676
+ onRowsPerPageChange = { handleChangeRowsPerPage }
677
+ />
678
+ </ >
679
+ ) }
680
+ </ Grid >
681
+
682
+ < Grid item sx = { { minWidth : "200px" } } >
683
+ < FormControl component = "fieldset" >
684
+ < FormLabel component = "legend" sx = { { textAlign : "right" } } >
685
+ Open Reading Frames
686
+ </ FormLabel >
687
+ < RadioGroup
688
+ aria-label = "Enzyme type"
689
+ name = "enzymeSet"
690
+ value = { readingFrameOption }
691
+ onChange = { ( event ) => setReadingFrameOption ( event . target . value ) }
692
+ >
693
+ { Object . keys ( readingFrameOptions ) . map ( ( key ) => (
694
+ < FormControlLabel
695
+ value = { key }
696
+ key = { key }
697
+ control = { < Radio color = "primary" /> }
698
+ label = { readingFrameOptions [ key ] . label }
699
+ labelPlacement = "start"
700
+ />
701
+ ) ) }
702
+ </ RadioGroup >
703
+ </ FormControl >
704
+ </ Grid >
705
+ </ Grid >
507
706
) ;
508
707
}
509
708
@@ -653,7 +852,7 @@ export function CallableSnapGenePreview({
653
852
</ ListItemButton >
654
853
</ ListItem >
655
854
</ CustomDrawer >
656
- < Stack orientation = "vertical" spacing = { 1 } flexGrow = { 1 } >
855
+ < Stack orientation = "vertical" spacing = { 1 } flexGrow = { 1 } sx = { { minWidth : 0 } } >
657
856
< DialogContent >
658
857
< DnaPreview
659
858
show = { tab === "DNA preview" }
@@ -672,6 +871,7 @@ export function CallableSnapGenePreview({
672
871
/>
673
872
< OrfTable
674
873
show = { tab === "ORF table" }
874
+ file = { file }
675
875
idOfOrfTableTab = { idOfOrfTableTab }
676
876
/>
677
877
</ DialogContent >
0 commit comments