@@ -6,6 +6,7 @@ import { weatherTemplate, getWeatherIndex } from "../components/weatherTemplate"
6
6
import { OverlayPanel } from 'primereact/overlaypanel' ;
7
7
import MaintainerMapping from "../maintainers.yml" ;
8
8
import { basePath } from "../next.config.js" ;
9
+ import { SearchForm } from "../components/searchForm" ;
9
10
10
11
11
12
export default function Home ( ) {
@@ -60,28 +61,35 @@ export default function Home() {
60
61
useEffect ( ( ) => {
61
62
const initialDisplay = new URLSearchParams ( window . location . search ) . get ( "display" ) ;
62
63
if ( initialDisplay ) {
63
- if ( initialDisplay === "prsingle" ) {
64
+ if ( initialDisplay === "prsingle" ) {
64
65
const initialPR = new URLSearchParams ( window . location . search ) . get ( "pr" ) ;
65
- if ( initialPR ) {
66
+ if ( initialPR ) {
66
67
setSelectedPR ( initialPR ) ;
67
68
}
68
69
}
69
70
setDisplay ( initialDisplay ) ;
70
71
}
71
72
} , [ ] ) ;
72
73
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.
75
77
if ( requiredFilter ) {
76
78
filteredJobs = filteredJobs . filter ( ( job ) => job . required ) ;
77
79
}
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
+ }
78
85
return filteredJobs ;
79
86
} ;
80
87
81
88
// Filter and set the rows for Nightly view.
82
89
useEffect ( ( ) => {
83
90
setLoading ( true ) ;
84
- let filteredJobs = filterRequired ( jobs ) ;
91
+ let filteredJobs = applyFilters ( jobs ) ;
92
+
85
93
//Set the rows for the table.
86
94
setRowsNightly (
87
95
filteredJobs . map ( ( job ) => ( {
@@ -101,7 +109,7 @@ export default function Home() {
101
109
// Filter and set the rows for PR Checks view.
102
110
useEffect ( ( ) => {
103
111
setLoading ( true ) ;
104
- let filteredChecks = filterRequired ( checks )
112
+ let filteredChecks = applyFilters ( checks )
105
113
106
114
//Set the rows for the table.
107
115
setRowsPR (
@@ -122,8 +130,7 @@ export default function Home() {
122
130
// Filter and set the rows for Single PR view.
123
131
useEffect ( ( ) => {
124
132
setLoading ( true ) ;
125
-
126
- let filteredData = filterRequired ( checks ) ;
133
+ let filteredData = applyFilters ( checks ) ;
127
134
128
135
filteredData = filteredData . map ( ( check ) => {
129
136
// Only if the check include the run number, add it to the data.
@@ -156,10 +163,35 @@ export default function Home() {
156
163
if ( view === "prsingle" && pr ) {
157
164
path . append ( "pr" , pr ) ;
158
165
}
166
+ if ( window . location . href . includes ( "value" ) ) {
167
+ const urlParams = new URLSearchParams ( window . location . search ) ;
168
+ path . append ( "value" , urlParams . get ( "value" ) ) ;
169
+ }
170
+
159
171
// Update the URL without reloading
160
172
window . history . pushState ( { } , '' , `${ basePath } /?${ path . toString ( ) } ` ) ;
161
173
} ;
162
174
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
+
163
195
const toggleRow = ( rowData ) => {
164
196
const isRowExpanded = expandedRows . includes ( rowData ) ;
165
197
@@ -418,8 +450,8 @@ export default function Home() {
418
450
onRowToggle = { ( e ) => setExpandedRows ( e . data ) }
419
451
loading = { loading }
420
452
emptyMessage = "No results found."
421
- sortField = "fails"
422
- sortOrder = { - 1 }
453
+ sortField = "fails"
454
+ sortOrder = { - 1 }
423
455
>
424
456
< Column expander />
425
457
< Column
@@ -593,14 +625,18 @@ export default function Home() {
593
625
</ div >
594
626
</ div >
595
627
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
600
630
className = { buttonClass ( requiredFilter ) }
601
631
onClick = { ( ) => setRequiredFilter ( ! requiredFilter ) } >
602
632
Required Jobs Only
603
633
</ 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" } >
604
640
< div className = "mt-4 text-center md:text-lg text-base" >
605
641
Total Rows: { display === "prsingle" ? rowsSingle . length : display === "prchecks" ? rowsPR . length : rowsNightly . length }
606
642
</ div >
0 commit comments