Skip to content

Commit 2781867

Browse files
Merge pull request #1 from darkhorse-420/Search
Search
2 parents dc620f7 + 8d12a5a commit 2781867

File tree

7 files changed

+245
-29
lines changed

7 files changed

+245
-29
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.paginationContainer {
2+
display: flex;
3+
justify-content: center;
4+
padding: 1rem;
5+
margin-top: 20px;
6+
gap: 10px;
7+
}
8+
9+
.pageButton {
10+
padding: 8px 12px;
11+
font-size: 14px;
12+
color: #333;
13+
border: 1px solid #ccc;
14+
background-color: #f9f9f9;
15+
cursor: pointer;
16+
border-radius: 5px;
17+
transition: background-color 0.3s ease;
18+
}
19+
20+
.pageButton:hover {
21+
background-color: #e2e6ea;
22+
}
23+
24+
.activeButton {
25+
background-color: #007bff;
26+
color: #fff;
27+
border-color: #007bff;
28+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from 'react';
2+
import './Pagination.css';
3+
4+
export default function Pagination({ currentPage, totalItems = 0, itemsPerPage, onPageChange }) {
5+
6+
const totalPages = Math.ceil(totalItems / itemsPerPage);
7+
8+
const handlePageClick = (page) => {
9+
if (page >= 1 && page <= totalPages) {
10+
onPageChange(page);
11+
}
12+
};
13+
14+
return (
15+
<div className='paginationContainer'>
16+
<button
17+
className='pageButton'
18+
onClick={() => handlePageClick(currentPage - 1)}
19+
disabled={currentPage === 1}
20+
>
21+
Previous
22+
</button>
23+
24+
<span>
25+
Page {currentPage} of {totalPages}
26+
</span>
27+
28+
<button
29+
className='pageButton'
30+
onClick={() => handlePageClick(currentPage + 1)}
31+
disabled={currentPage === totalPages}
32+
>
33+
Next
34+
</button>
35+
</div>
36+
);
37+
}

src/ui/components/Search/Search.css

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* Search.css */
2+
3+
.search-container {
4+
display: flex;
5+
align-items: center;
6+
margin-bottom: 10px;
7+
margin-top: 10px;
8+
margin-right: 10 px;
9+
}
10+
11+
.search-input {
12+
padding: 10px;
13+
margin-right: 8px;
14+
border: 1px solid #ccc;
15+
border-radius: 10px;
16+
width: 200px; /* Adjust width as needed */
17+
font-size: 14px;
18+
transition: border-color 0.3s;
19+
}
20+
21+
.search-input:focus {
22+
border-color: #007bff; /* Change to your desired focus color */
23+
outline: none; /* Remove default outline */
24+
}
25+
26+
.search-button {
27+
padding: 10px 16px;
28+
border: none;
29+
border-radius: 10px;
30+
background-color: #007bff; /* Change to your desired button color */
31+
color: white;
32+
cursor: pointer;
33+
font-size: 14px;
34+
transition: background-color 0.3s;
35+
}
36+
37+
.search-button:hover {
38+
background-color: #0056b3; /* Darker shade for hover effect */
39+
}

src/ui/components/Search/Search.jsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React, { useState } from 'react';
2+
import PropTypes from 'prop-types';
3+
import './Search.css';
4+
5+
export default function Search({ placeholder = 'Search...', onSearch }) {
6+
const [query, setQuery] = useState('');
7+
8+
const handleInputChange = (e) => {
9+
setQuery(e.target.value);
10+
};
11+
12+
const handleSearch = () => {
13+
onSearch(query);
14+
};
15+
16+
const handleKeyDown = (event) => {
17+
if (event.key === 'Enter') {
18+
handleSearch();
19+
}
20+
};
21+
22+
return (
23+
<div className="search-container">
24+
<input
25+
type="text"
26+
placeholder={placeholder}
27+
value={query}
28+
onChange={handleInputChange}
29+
onKeyDown={handleKeyDown}
30+
className="search-input"
31+
/>
32+
<button onClick={handleSearch} className="search-button">
33+
Search
34+
</button>
35+
</div>
36+
);
37+
}
38+
39+
Search.propTypes = {
40+
placeholder: PropTypes.string,
41+
onSearch: PropTypes.func.isRequired,
42+
};

src/ui/views/RepoList/Components/RepoOverview.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import GridContainer from '../../../components/Grid/GridContainer';
55
import GridItem from '../../../components/Grid/GridItem';
66
import { CodeReviewIcon, LawIcon, PeopleIcon } from '@primer/octicons-react';
77

8+
89
const colors = {
910
'1C Enterprise': '#814CCC',
1011
'2-Dimensional Array': '#38761D',
@@ -671,4 +672,4 @@ export default function Repositories(props) {
671672
</TableCell>
672673
</TableRow>
673674
);
674-
}
675+
}

src/ui/views/RepoList/Components/Repositories.jsx

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,59 @@ import NewRepo from './NewRepo';
1212
import RepoOverview from './RepoOverview';
1313
import { UserContext } from '../../../../context';
1414
import PropTypes from 'prop-types';
15+
import Search from '../../../components/Search/Search';
16+
import Pagination from '../../../components/Pagination/Pagination';
17+
1518

1619
export default function Repositories(props) {
1720
const useStyles = makeStyles(styles);
1821
const classes = useStyles();
1922
const [data, setData] = useState([]);
23+
const [filteredData, setFilteredData] = useState([]);
2024
const [, setAuth] = useState(true);
2125
const [isLoading, setIsLoading] = useState(false);
2226
const [isError, setIsError] = useState(false);
27+
const [currentPage, setCurrentPage] = useState(1);
28+
const itemsPerPage = 5;
2329
const navigate = useNavigate();
24-
const openRepo = (repo) => navigate(`/admin/repo/${repo}`, { replace: true });
2530
const { user } = useContext(UserContext);
31+
const openRepo = (repo) => navigate(`/admin/repo/${repo}`, { replace: true });
2632

2733
useEffect(() => {
2834
const query = {};
2935
for (const k in props) {
3036
if (!k) continue;
3137
query[k] = props[k];
3238
}
33-
getRepos(setIsLoading, setData, setAuth, setIsError, query);
39+
getRepos(setIsLoading, (data) => {
40+
setData(data);
41+
setFilteredData(data);
42+
}, setAuth, setIsError, query);
3443
}, [props]);
3544

3645
const refresh = async (repo) => {
37-
console.log('refresh:', repo);
38-
setData([...data, repo]);
46+
const updatedData = [...data, repo];
47+
setData(updatedData);
48+
setFilteredData(updatedData);
49+
};
50+
51+
const handleSearch = (query) => {
52+
setCurrentPage(1);
53+
if (!query) {
54+
setFilteredData(data);
55+
} else {
56+
const lowercasedQuery = query.toLowerCase();
57+
setFilteredData(
58+
data.filter(repo =>
59+
repo.name.toLowerCase().includes(lowercasedQuery) ||
60+
repo.project.toLowerCase().includes(lowercasedQuery)
61+
)
62+
);
63+
}
3964
};
65+
const handlePageChange = (page) => setCurrentPage(page);
66+
const startIdx = (currentPage - 1) * itemsPerPage;
67+
const paginatedData = filteredData.slice(startIdx, startIdx + itemsPerPage);
4068

4169
if (isLoading) return <div>Loading...</div>;
4270
if (isError) return <div>Something went wrong ...</div>;
@@ -54,8 +82,13 @@ export default function Repositories(props) {
5482
key='x'
5583
classes={classes}
5684
openRepo={openRepo}
57-
data={data}
85+
data={paginatedData}
5886
repoButton={addrepoButton}
87+
onSearch={handleSearch}
88+
currentPage={currentPage}
89+
totalItems={filteredData.length}
90+
itemsPerPage={itemsPerPage}
91+
onPageChange={handlePageChange}
5992
/>
6093
);
6194
}
@@ -65,13 +98,21 @@ GetGridContainerLayOut.propTypes = {
6598
openRepo: PropTypes.func.isRequired,
6699
data: PropTypes.array,
67100
repoButton: PropTypes.object,
101+
onSearch: PropTypes.func.isRequired,
102+
currentPage: PropTypes.number.isRequired,
103+
totalItems: PropTypes.number.isRequired,
104+
itemsPerPage: PropTypes.number.isRequired,
105+
onPageChange: PropTypes.func.isRequired,
68106
};
69107

70108
function GetGridContainerLayOut(props) {
71109
return (
72110
<GridContainer>
73111
{props.repoButton}
74112
<GridItem xs={12} sm={12} md={12}>
113+
114+
<Search onSearch={props.onSearch} />
115+
75116
<TableContainer
76117
style={{ background: 'transparent', borderRadius: '5px', border: '1px solid #d0d7de' }}
77118
>
@@ -86,6 +127,15 @@ function GetGridContainerLayOut(props) {
86127
</Table>
87128
</TableContainer>
88129
</GridItem>
130+
<GridItem xs={12} sm={12} md={12}>
131+
<Pagination
132+
currentPage={props.currentPage}
133+
totalItems={props.totalItems}
134+
itemsPerPage={props.itemsPerPage}
135+
onPageChange={props.onPageChange}
136+
/>
137+
</GridItem>
89138
</GridContainer>
90139
);
91140
}
141+

0 commit comments

Comments
 (0)