99 Tab ,
1010 Tabs ,
1111 Table ,
12+ Form
1213} from "react-bootstrap" ;
1314import { DropdownSubmenu , NavDropdownMenu } from "react-bootstrap-submenu" ;
1415import { FaToggleOn , FaToggleOff , FaInfoCircle } from "react-icons/fa" ;
@@ -41,6 +42,9 @@ function ToolBar({
4142 const [ hasExtra , setHasExtra ] = useState ( false ) ;
4243 const [ hasMain , setHasMain ] = useState ( false ) ;
4344
45+ const [ filteredParams , setFilteredParams ] = useState ( [ ] ) ; // used for param search
46+ const [ searchQuery , setSearchQuery ] = useState ( "" ) ; // used for param search
47+
4448 const [ sequences , setSequences ] = useState ( [ ] ) ;
4549
4650 const handleClose = ( ) => {
@@ -59,13 +63,24 @@ function ToolBar({
5963 // eslint-disable-next-line
6064 } , [ ] ) ;
6165
66+ useEffect ( ( ) => {
67+ var inputSearch = document . getElementById ( "search-param" ) ;
68+ if ( inputSearch != null ) {
69+ inputSearch . value = searchQuery ;
70+ inputSearch . focus ( ) ;
71+ }
72+
73+ } , [ filteredParams , searchQuery ] ) ;
74+
6275 const getAdditionalInfo = async ( ) => {
6376 var response = await fetch ( `http://localhost:${ PORT } /additional_info` ) . then (
6477 ( res ) => res . json ( )
6578 ) ;
66- setAdditionalInfo ( response . info ) ;
6779 setHasExtra ( response . hasExtra ) ;
6880 setHasMain ( response . hasMain ) ;
81+
82+ setAdditionalInfo ( response . info ) ;
83+ response . info . forEach ( ( item ) => { if ( item . name === "Initial Parameters" ) { setFilteredParams ( item . info ) ; } } )
6984 } ;
7085
7186 const getCurrentFile = async ( ) => {
@@ -76,11 +91,11 @@ function ToolBar({
7691 else
7792 setCurrentFile (
7893 "Current File: " +
79- response . file [ 0 ] +
80- " \nFile Size: " +
81- formatFileSize ( response . file [ 1 ] ) +
82- " \nLast Modified: " +
83- response . file [ 2 ]
94+ response . file [ 0 ] +
95+ " \nFile Size: " +
96+ formatFileSize ( response . file [ 1 ] ) +
97+ " \nLast Modified: " +
98+ response . file [ 2 ]
8499 ) ;
85100
86101 setAppVersion ( response . appVersion ) ;
@@ -224,28 +239,31 @@ function ToolBar({
224239 ) ;
225240 }
226241
227- const InfoTable = ( { data } ) => {
228- const headers = Object . keys ( data . info [ 0 ] ) ;
229- return (
230- < Table striped bordered hover >
231- < thead >
232- < tr >
233- { headers . map ( ( header ) => (
234- < th key = { header } > { header } </ th >
235- ) ) }
236- </ tr >
237- </ thead >
238- < tbody >
239- { data . info . map ( ( item ) => (
240- < tr key = { generateUUID ( ) } >
242+ const InfoTable = ( { list } ) => {
243+ if ( list . length > 0 ) {
244+ const headers = Object . keys ( list [ 0 ] ) ;
245+ return (
246+ < Table striped bordered hover >
247+ < thead >
248+ < tr >
241249 { headers . map ( ( header ) => (
242- < td key = { ` ${ generateUUID ( ) } - ${ header } ` } > { item [ header ] } </ td >
250+ < th key = { header } > { header } </ th >
243251 ) ) }
244252 </ tr >
245- ) ) }
246- </ tbody >
247- </ Table >
248- ) ;
253+ </ thead >
254+ < tbody >
255+ { list . map ( ( item ) => (
256+ < tr key = { generateUUID ( ) } >
257+ { headers . map ( ( header ) => (
258+ < td key = { `${ generateUUID ( ) } -${ header } ` } > { item [ header ] } </ td >
259+ ) ) }
260+ </ tr >
261+ ) ) }
262+ </ tbody >
263+ </ Table >
264+ ) ;
265+ }
266+
249267 } ;
250268
251269 const runSequence = async ( sequenceName ) => {
@@ -305,6 +323,15 @@ function ToolBar({
305323 setShowCreateMessage ( false ) ;
306324 } ;
307325
326+ const paramSearch = ( query , dict ) => {
327+ const value = query . target . value ;
328+ setSearchQuery ( value ) ;
329+ const keyword = value . toLowerCase ( ) ;
330+ const paramList = dict . info ;
331+ const foundParams = paramList . filter ( obj => obj . name . toLowerCase ( ) . includes ( keyword ) ) ;
332+ setFilteredParams ( foundParams ) ;
333+ } ;
334+
308335 return (
309336 < >
310337 < ToastContainer />
@@ -393,11 +420,20 @@ function ToolBar({
393420 } ) }
394421 </ Container >
395422 </ Tab >
396- { additionalInfo . map ( ( info ) => (
397- < Tab key = { generateUUID ( ) } eventKey = { info . name } title = { info . name } >
423+ { additionalInfo . map ( ( tabContent ) => (
424+ < Tab key = { generateUUID ( ) } eventKey = { tabContent . name } title = { tabContent . name } >
398425 < br className = "break" />
399426 < Container >
400- < InfoTable data = { info } />
427+ { tabContent . search &&
428+ < >
429+ < Form . Control id = "search-param" size = "lg" type = "text" placeholder = "Param Name" onChange = { ( value ) => paramSearch ( value , tabContent ) } />
430+ < br />
431+ < InfoTable list = { filteredParams } />
432+ </ >
433+ }
434+ { ! tabContent . search &&
435+ < InfoTable list = { tabContent . info } />
436+ }
401437 </ Container >
402438 </ Tab >
403439 ) ) }
0 commit comments