Skip to content

Commit

Permalink
Merge pull request #21 from a1icja/required-filter
Browse files Browse the repository at this point in the history
dashboard: Add filter for required tests
  • Loading branch information
sprt authored Nov 22, 2024
2 parents 1ab6ca8 + 80b5f12 commit 03c63b8
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default function Home() {
const [jobs, setJobs] = useState([]);
const [rows, setRows] = useState([]);
const [expandedRows, setExpandedRows] = useState([]);
const [requiredFilter, setRequiredFilter] = useState(false);

useEffect(() => {
const fetchData = async () => {
Expand Down Expand Up @@ -44,17 +45,34 @@ export default function Home() {
fetchData();
}, []);


// Filter based on required tag.
const filterRequired = (filteredJobs) => {
if (requiredFilter){
filteredJobs = filteredJobs.filter((job) => job.required);
}
return filteredJobs;
};

useEffect(() => {
setLoading(true);

// Create rows to set into table.
const rows = jobs.map((job) => ({
...job,
weather: getWeatherIndex(job),
}));
setRows(rows);
// Filter based on required tag.
let filteredJobs = filterRequired(jobs);

//Set the rows for the table.
setRows(
filteredJobs.map((job) => ({
name : job.name,
runs : job.runs,
fails : job.fails,
skips : job.skips,
required : job.required,
weather : getWeatherIndex(job),
}))
);
setLoading(false);
}, [jobs]);
}, [jobs, requiredFilter]);

const toggleRow = (rowData) => {
const isRowExpanded = expandedRows.includes(rowData);
Expand All @@ -69,6 +87,11 @@ export default function Home() {
setExpandedRows(updatedExpandedRows);
};

const buttonClass = (active) => `tab md:px-4 px-2 py-2 border-2
${active ? "border-blue-500 bg-blue-500 text-white"
: "border-gray-300 bg-white hover:bg-gray-100"}`;


// Template for rendering the Name column as a clickable item
const nameTemplate = (rowData) => {
return (
Expand Down Expand Up @@ -292,6 +315,11 @@ export default function Home() {
"m-0 h-full p-4 overflow-x-hidden overflow-y-auto bg-surface-ground font-normal text-text-color antialiased select-text"
}
>
<button
className={buttonClass(requiredFilter)}
onClick={() => setRequiredFilter(!requiredFilter)}>
Required Jobs Only
</button>
<div className="mt-4 text-lg">Total Rows: {rows.length}</div>
<div>{renderTable()}</div>
</main>
Expand Down

0 comments on commit 03c63b8

Please sign in to comment.