@@ -6,6 +6,7 @@ import { weatherTemplate, getWeatherIndex } from "../components/weatherTemplate"
66import  {  OverlayPanel  }  from  'primereact/overlaypanel' ; 
77import  MaintainerMapping  from  "../maintainers.yml" ; 
88import  {  basePath  }  from  "../next.config.js" ; 
9+ import  {  SearchForm  }  from  "../components/searchForm" ; 
910
1011
1112export  default  function  Home ( )  { 
@@ -60,28 +61,35 @@ export default function Home() {
6061  useEffect ( ( )  =>  { 
6162    const  initialDisplay  =  new  URLSearchParams ( window . location . search ) . get ( "display" ) ; 
6263    if  ( initialDisplay )  { 
63-       if ( initialDisplay  ===  "prsingle" ) { 
64+       if   ( initialDisplay  ===  "prsingle" ) { 
6465        const  initialPR  =  new  URLSearchParams ( window . location . search ) . get ( "pr" ) ; 
65-         if ( initialPR ) { 
66+         if   ( initialPR ) { 
6667          setSelectedPR ( initialPR ) ; 
6768        } 
6869      } 
6970      setDisplay ( initialDisplay ) ; 
7071    } 
7172  } ,  [ ] ) ; 
7273
73-   // Filter based on required tag. 
74-   const  filterRequired  =  ( filteredJobs )  =>  { 
74+   // Filter the checks/jobs. 
75+   const  applyFilters  =  ( filteredJobs )  =>  { 
76+     // Filter based on the required tag. 
7577    if  ( requiredFilter ) { 
7678      filteredJobs  =  filteredJobs . filter ( ( job )  =>  job . required ) ; 
7779    } 
80+     // Filter based on the URL. 
81+     const  val  =  new  URLSearchParams ( window . location . search ) . get ( "value" ) ; 
82+     if  ( val ) { 
83+       filteredJobs =  filteredJobs . filter ( ( job )  =>  job . name . includes ( decodeURIComponent ( val ) ) ) ; 
84+     } 
7885    return  filteredJobs ; 
7986  } ; 
8087
8188  // Filter and set the rows for Nightly view. 
8289  useEffect ( ( )  =>  { 
8390    setLoading ( true ) ; 
84-     let  filteredJobs  =  filterRequired ( jobs ) ; 
91+     let  filteredJobs  =  applyFilters ( jobs ) ; 
92+ 
8593    //Set the rows for the table. 
8694    setRowsNightly ( 
8795      filteredJobs . map ( ( job )  =>  ( { 
@@ -101,7 +109,7 @@ export default function Home() {
101109  // Filter and set the rows for PR Checks view. 
102110  useEffect ( ( )  =>  { 
103111    setLoading ( true ) ; 
104-     let  filteredChecks  =  filterRequired ( checks ) 
112+     let  filteredChecks  =  applyFilters ( checks ) 
105113
106114    //Set the rows for the table. 
107115    setRowsPR ( 
@@ -122,8 +130,7 @@ export default function Home() {
122130  // Filter and set the rows for Single PR view.  
123131  useEffect ( ( )  =>  { 
124132    setLoading ( true ) ; 
125- 
126-     let  filteredData  =  filterRequired ( checks ) ; 
133+     let  filteredData  =  applyFilters ( checks ) ; 
127134
128135    filteredData  =  filteredData . map ( ( check )  =>  { 
129136      // Only if the check include the run number, add it to the data.  
@@ -156,10 +163,35 @@ export default function Home() {
156163    if  ( view  ===  "prsingle"  &&  pr )  { 
157164      path . append ( "pr" ,  pr ) ; 
158165    } 
166+     if ( window . location . href . includes ( "value" ) ) { 
167+       const  urlParams  =  new  URLSearchParams ( window . location . search ) ; 
168+       path . append ( "value" ,  urlParams . get ( "value" ) ) ; 
169+     } 
170+ 
159171    // Update the URL without reloading 
160172    window . history . pushState ( { } ,  '' ,  `${ basePath } ${ path . toString ( ) }  ) ; 
161173  } ; 
162174
175+   // Apply search terms to the URL and reload the page. 
176+   const  handleSearch =  ( e )  =>  { 
177+     // Prevent the default behavior so that we can keep search terms. 
178+     e . preventDefault ( ) ; 
179+     // Trim value here if desired (not trimmed now) 
180+     const  value  =  e . target . value . value ; 
181+     if  ( value )  { 
182+       // Add the display type to the URL. 
183+       const  path  =  new  URLSearchParams ( ) ; 
184+       path . append ( "display" ,  display ) ; 
185+       if ( display  ===  "prsingle"  &&  selectedPR ) { 
186+         path . append ( "pr" ,  selectedPR ) ; 
187+       } 
188+ 
189+       // Add the search term from the form and redirect. 
190+       path . append ( "value" ,  value ) ; 
191+       window . location . assign ( `${ basePath } ${ path . toString ( ) }  ) ; 
192+     } 
193+   } ; 
194+ 
163195  const  toggleRow  =  ( rowData )  =>  { 
164196    const  isRowExpanded  =  expandedRows . includes ( rowData ) ; 
165197
@@ -418,8 +450,8 @@ export default function Home() {
418450      onRowToggle = { ( e )  =>  setExpandedRows ( e . data ) } 
419451      loading = { loading } 
420452      emptyMessage = "No results found." 
421-       sortField = "fails"      
422-       sortOrder = { - 1 }         
453+       sortField = "fails" 
454+       sortOrder = { - 1 } 
423455    > 
424456      < Column  expander /> 
425457      < Column 
@@ -593,14 +625,18 @@ export default function Home() {
593625        </ div > 
594626      </ div > 
595627
596-       
597-       < div  className = { "m-0 h-full px-4 overflow-x-hidden overflow-y-auto \ 
598-                         bg-surface-ground antialiased select-text" } > 
599-         < button  
628+       < div  className = "flex flex-row justify-end mx-4 space-x-4" > 
629+       < button  
600630          className = { buttonClass ( requiredFilter ) }  
601631          onClick = { ( )  =>  setRequiredFilter ( ! requiredFilter ) } > 
602632          Required Jobs Only
603633        </ button > 
634+         < SearchForm  handleSearch = { handleSearch }  /> 
635+       </ div > 
636+ 
637+       
638+       < div  className = { "m-0 h-full px-4 overflow-x-hidden overflow-y-auto \ 
639+                         bg-surface-ground antialiased select-text" } > 
604640        < div  className = "mt-4 text-center md:text-lg text-base" > 
605641        Total Rows: { display  ===  "prsingle"  ? rowsSingle . length  : display  ===  "prchecks"  ? rowsPR . length  : rowsNightly . length } 
606642        </ div > 
0 commit comments