Skip to content

Commit

Permalink
added list of os and configured the search bar and related checkbox
Browse files Browse the repository at this point in the history
Signed-off-by: Apurv Sonawane <[email protected]>
  • Loading branch information
Apurv428 committed Jul 9, 2024
1 parent 1879b7b commit 1dc18dc
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 152 deletions.
109 changes: 0 additions & 109 deletions react-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions react-frontend/src/components/Filter/DistroFilter.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.distro-filter-wrapper {
align-items: center;
display: flex;
flex: 0 0 auto;
gap: 15px;
justify-content: center;
position: relative;
width: 1181px;
}

.input_group {
font-size: 16px;
font-weight: bold;
}

.input_group label {
padding-left: 10px;
font-weight: normal;
vertical-align: middle;
}

.input_group input[type="checkbox"] {
margin-right: 3px;
}

#chkAll {
margin-right: 2px;
}

.distro-filter-wrapper .input_group {
margin-bottom: 15px;
}

.distro-filter-wrapper input[type="text"] {
width: 100%;
padding: 8px;
margin-top: 5px;
border: 1px solid #ccc;
border-radius: 4px;
}
93 changes: 93 additions & 0 deletions react-frontend/src/components/Filter/DistroFilter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import React, { useState, useEffect } from 'react';
import './DistroFilter.css';

const DistroFilters = () => {
const [osList, setOsList] = useState([]);
const [selectedOS, setSelectedOS] = useState([]);
const [searchTerm, setSearchTerm] = useState('');
const [searchDescription, setSearchDescription] = useState(false);
const [loading, setLoading] = useState(true); // New loading state

useEffect(() => {
const fetchOsList = async () => {
try {
const response = await fetch('https://sdt.openmainframeproject.org/sdt/getSupportedDistros');
if (!response.ok) {
throw new Error('Failed to fetch OS list');
}
const data = await response.json();
const formattedOsList = Object.entries(data).map(([osName, versions]) => ({
type: osName,
description: Object.keys(versions).join(', ')
}));
setOsList(formattedOsList);
setLoading(false);
} catch (error) {
console.error('Error fetching OS list:', error);
setLoading(false);
}
};

fetchOsList();
}, []);

const toggleOS = (osName) => {
const index = selectedOS.indexOf(osName);
if (index === -1) {
setSelectedOS([...selectedOS, osName]);
} else {
setSelectedOS(selectedOS.filter(os => os !== osName));
}
};

const toggleAll = (event) => {
if (event.target.checked) {
const allOS = osList.map(os => os.type);
setSelectedOS(allOS);
} else {
setSelectedOS([]);
}
};

// Show loading indicator while fetching data
if (loading) {
return <div className="loading"><br/><br/></div>;
}

// Render component after data is loaded
return (
<div className="container distro-filter-wrapper">
<div className="row">
<div className="col-md-12">
<div className="input_group">
<div>Select Operating System:</div>
<div>
<label>
<input
type="checkbox"
onChange={toggleAll}
checked={selectedOS.length === osList.length}
id="chkAll"
/>
All
</label>

{osList.map((os, index) => (
<label key={index}>
<input
type="checkbox"
onChange={() => toggleOS(os.type)}
checked={selectedOS.includes(os.type)}
/>
{os.type}
</label>
))}
</div>
</div>
</div>
</div>
</div>
);
};

export default DistroFilters;
Loading

0 comments on commit 1dc18dc

Please sign in to comment.