1- import { useMemo , useState , useCallback } from 'react'
2- import {
3- createColumnHelper ,
4- getCoreRowModel ,
5- getPaginationRowModel ,
6- getSortedRowModel ,
7- useReactTable ,
8- flexRender ,
9- } from '@tanstack/react-table'
1+ import { useCallback , useMemo , useState } from 'react'
102
11- import {
12- CascadingMenuButton ,
13- ErrorMessage ,
14- LoadingEllipses ,
15- } from '@jbrowse/core/ui'
3+ import { CascadingMenuButton , ErrorMessage } from '@jbrowse/core/ui'
164import { notEmpty , useLocalStorage } from '@jbrowse/core/util'
175import Help from '@mui/icons-material/Help'
186import MoreHoriz from '@mui/icons-material/MoreHoriz'
@@ -26,6 +14,14 @@ import {
2614 TextField ,
2715 Typography ,
2816} from '@mui/material'
17+ import {
18+ createColumnHelper ,
19+ flexRender ,
20+ getCoreRowModel ,
21+ getPaginationRowModel ,
22+ getSortedRowModel ,
23+ useReactTable ,
24+ } from '@tanstack/react-table'
2925import useSWR from 'swr'
3026import { makeStyles } from 'tss-react/mui'
3127
@@ -241,17 +237,21 @@ function SkeletonLoader({ classes }: { classes: any }) {
241237}
242238
243239function highlightText ( text : string , query : string ) : React . ReactNode {
244- if ( ! query || ! text ) return text
240+ if ( ! query || ! text ) {
241+ return text
242+ }
245243
246244 const queryLower = query . toLowerCase ( ) . trim ( )
247245 const textLower = text . toLowerCase ( )
248246
249247 const index = textLower . indexOf ( queryLower )
250- if ( index === - 1 ) return text
248+ if ( index === - 1 ) {
249+ return text
250+ }
251251
252- const beforeMatch = text . substring ( 0 , index )
253- const match = text . substring ( index , index + query . length )
254- const afterMatch = text . substring ( index + query . length )
252+ const beforeMatch = text . slice ( 0 , Math . max ( 0 , index ) )
253+ const match = text . slice ( index , index + query . length )
254+ const afterMatch = text . slice ( Math . max ( 0 , index + query . length ) )
255255
256256 return (
257257 < >
@@ -283,9 +283,7 @@ export default function GenomesDataTable({
283283 pageIndex : 0 ,
284284 pageSize : 50 ,
285285 } )
286- const [ sorting , setSorting ] = useState < Array < { id : string ; desc : boolean } > > (
287- [ ] ,
288- )
286+ const [ sorting , setSorting ] = useState < { id : string ; desc : boolean } [ ] > ( [ ] )
289287 const [ typeOption , setTypeOption ] = useLocalStorage (
290288 'startScreen-genArkChoice' ,
291289 'mammals' ,
@@ -336,11 +334,11 @@ export default function GenomesDataTable({
336334 }
337335 if ( filterOption === 'refseq' ) {
338336 return preRows ?. filter (
339- r => 'ncbiName' in r && r . ncbiName ? .startsWith ( 'GCF_' ) ,
337+ r => 'ncbiName' in r && r . ncbiName . startsWith ( 'GCF_' ) ,
340338 )
341339 } else if ( filterOption === 'genbank' ) {
342340 return preRows ?. filter (
343- r => 'ncbiName' in r && r . ncbiName ? .startsWith ( 'GCA_' ) ,
341+ r => 'ncbiName' in r && r . ncbiName . startsWith ( 'GCA_' ) ,
344342 )
345343 } else if ( filterOption === 'designatedReference' ) {
346344 return preRows ?. filter (
@@ -353,7 +351,7 @@ export default function GenomesDataTable({
353351 }
354352 } , [ filterOption , preRows , typeOption ] )
355353
356- const favs = new Set ( favorites . map ( r => r . id ) )
354+ const favs = useMemo ( ( ) => new Set ( favorites . map ( r => r . id ) ) , [ favorites ] )
357355
358356 // Filter rows based on search query
359357 const searchFilteredRows = useMemo ( ( ) => {
@@ -395,7 +393,7 @@ export default function GenomesDataTable({
395393 columnHelper . accessor ( 'name' , {
396394 header : 'Name' ,
397395 cell : info => {
398- const row = info . row . original as any
396+ const row = info . row . original
399397 const isFavorite = favs . has ( row . id )
400398 const websiteUrl = `https://genomes.jbrowse.org/ucsc/${ row . id } /`
401399
@@ -473,7 +471,7 @@ export default function GenomesDataTable({
473471 columnHelper . accessor ( 'commonName' , {
474472 header : 'Common Name' ,
475473 cell : info => {
476- const row = info . row . original as any
474+ const row = info . row . original
477475 const isFavorite = favs . has ( row . id )
478476 const websiteUrl = `https://genomes.jbrowse.org/accession/${ row . accession } /`
479477
@@ -537,7 +535,9 @@ export default function GenomesDataTable({
537535 header : 'Release Date' ,
538536 cell : info => {
539537 const date = info . getValue ( )
540- if ( ! date ) return ''
538+ if ( ! date ) {
539+ return ''
540+ }
541541 // Parse the date and format it to show only the date part (YYYY-MM-DD)
542542 const dateObj = new Date ( date )
543543 return dateObj . toISOString ( ) . split ( 'T' ) [ 0 ]
@@ -568,23 +568,21 @@ export default function GenomesDataTable({
568568 setFavorites ,
569569 launch ,
570570 onClose ,
571- multipleSelection ,
572571 searchQuery ,
573572 showAllColumns ,
574573 columnHelper ,
575574 ] )
576575
577576 // Create table instance
578577 const rowSelection = useMemo (
579- ( ) => selected . reduce ( ( acc , id ) => ( { ... acc , [ id ] : true } ) , { } ) ,
578+ ( ) => Object . fromEntries ( selected . map ( id => [ id , true ] ) ) ,
580579 [ selected ] ,
581580 )
582581
583582 const handleRowSelectionChange = useCallback (
584583 ( updater : any ) => {
585- const currentSelection = selected . reduce (
586- ( acc , id ) => ( { ...acc , [ id ] : true } ) ,
587- { } ,
584+ const currentSelection = Object . fromEntries (
585+ selected . map ( id => [ id , true ] ) ,
588586 )
589587 const newSelection =
590588 typeof updater === 'function' ? updater ( currentSelection ) : updater
@@ -604,7 +602,7 @@ export default function GenomesDataTable({
604602 )
605603
606604 const table = useReactTable ( {
607- data : finalFilteredRows || [ ] ,
605+ data : finalFilteredRows ,
608606 columns : tableColumns ,
609607 state : {
610608 sorting,
@@ -634,7 +632,7 @@ export default function GenomesDataTable({
634632 variant = "contained"
635633 disabled = { selected . length === 0 }
636634 onClick = { ( ) => {
637- if ( selected . length > 0 && finalFilteredRows ) {
635+ if ( selected . length > 0 ) {
638636 const selectedRows = selected
639637 . map ( id => finalFilteredRows . find ( row => row . id === id ) )
640638 . filter ( notEmpty )
@@ -657,17 +655,21 @@ export default function GenomesDataTable({
657655 type = "text"
658656 placeholder = "Search genomes..."
659657 value = { searchQuery }
660- onChange = { e => setSearchQuery ( e . target . value ) }
658+ onChange = { e => {
659+ setSearchQuery ( e . target . value )
660+ } }
661661 variant = "outlined"
662662 size = "small"
663663 className = { classes . ml }
664664 style = { { minWidth : 200 } }
665- InputProps = { {
666- startAdornment : (
667- < InputAdornment position = "start" >
668- < Search fontSize = "small" />
669- </ InputAdornment >
670- ) ,
665+ slotProps = { {
666+ input : {
667+ startAdornment : (
668+ < InputAdornment position = "start" >
669+ < Search fontSize = "small" />
670+ </ InputAdornment >
671+ ) ,
672+ } ,
671673 } }
672674 />
673675
@@ -790,10 +792,9 @@ export default function GenomesDataTable({
790792 < ErrorMessage error = { genArkError || mainGenomesError } />
791793 ) : null }
792794
793- { ! finalFilteredRows ||
794- ( finalFilteredRows . length === 0 && ! genArkData && ! mainGenomesData ) ? (
795+ { finalFilteredRows . length === 0 && ! genArkData && ! mainGenomesData ? (
795796 < SkeletonLoader classes = { classes } />
796- ) : finalFilteredRows ? (
797+ ) : (
797798 < div >
798799 < table className = { classes . table } >
799800 < thead >
@@ -860,14 +861,18 @@ export default function GenomesDataTable({
860861 < div className = { classes . paginationContainer } >
861862 < button
862863 className = { classes . paginationButton }
863- onClick = { ( ) => table . setPageIndex ( 0 ) }
864+ onClick = { ( ) => {
865+ table . setPageIndex ( 0 )
866+ } }
864867 disabled = { ! table . getCanPreviousPage ( ) }
865868 >
866869 { '<<' }
867870 </ button >
868871 < button
869872 className = { classes . paginationButton }
870- onClick = { ( ) => table . previousPage ( ) }
873+ onClick = { ( ) => {
874+ table . previousPage ( )
875+ } }
871876 disabled = { ! table . getCanPreviousPage ( ) }
872877 >
873878 { '<' }
@@ -881,14 +886,18 @@ export default function GenomesDataTable({
881886 </ span >
882887 < button
883888 className = { classes . paginationButton }
884- onClick = { ( ) => table . nextPage ( ) }
889+ onClick = { ( ) => {
890+ table . nextPage ( )
891+ } }
885892 disabled = { ! table . getCanNextPage ( ) }
886893 >
887894 { '>' }
888895 </ button >
889896 < button
890897 className = { classes . paginationButton }
891- onClick = { ( ) => table . setPageIndex ( table . getPageCount ( ) - 1 ) }
898+ onClick = { ( ) => {
899+ table . setPageIndex ( table . getPageCount ( ) - 1 )
900+ } }
892901 disabled = { ! table . getCanNextPage ( ) }
893902 >
894903 { '>>' }
@@ -923,8 +932,6 @@ export default function GenomesDataTable({
923932 </ span >
924933 </ div >
925934 </ div >
926- ) : (
927- < LoadingEllipses />
928935 ) }
929936 { moreInfoDialogOpen ? (
930937 < MoreInfoDialog
0 commit comments