Skip to content

Commit 8e9b709

Browse files
committed
dashboard: Add search box and link to URL
Adds an input form for searching job names. Searches are appended to the URL. Fixes #4 Signed-off-by: Anna Finn <[email protected]>
1 parent e8f2314 commit 8e9b709

File tree

2 files changed

+64
-14
lines changed

2 files changed

+64
-14
lines changed

components/searchForm.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export const SearchForm = ({ handleSearch }) => {
2+
return (
3+
<div className="flex flex-col items-center md:text-base text-xs">
4+
<div className="flex min-[1126px]:justify-end justify-center w-full">
5+
<form className="p-2 bg-gray-700 rounded-md flex flex-row" onSubmit={(e) => handleSearch(e)}>
6+
<div className="mx-2">
7+
<label className="block text-white">Search Text:</label>
8+
<input type="text" name="value" required></input>
9+
</div>
10+
</form>
11+
</div>
12+
</div>
13+
);
14+
};

pages/index.js

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { weatherTemplate, getWeatherIndex } from "../components/weatherTemplate"
66
import { OverlayPanel } from 'primereact/overlaypanel';
77
import MaintainerMapping from "../maintainers.yml";
88
import { basePath } from "../next.config.js";
9+
import { SearchForm } from "../components/searchForm";
910

1011

1112
export 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

Comments
 (0)