Skip to content

Commit 6a255a5

Browse files
committed
feat: search
1 parent b7feb5a commit 6a255a5

File tree

7 files changed

+174
-7
lines changed

7 files changed

+174
-7
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
.filtering-container {
2+
position: relative;
3+
display: inline-block;
4+
padding-bottom: 10px;
5+
}
6+
7+
.dropdown-toggle {
8+
padding: 10px 10px;
9+
padding-right: 10px;
10+
border: 1px solid #ccc;
11+
border-radius: 5px;
12+
background-color: #fff;
13+
color: #333;
14+
cursor: pointer;
15+
font-size: 14px;
16+
text-align: left;
17+
width: 130px;
18+
display: inline-flex;
19+
align-items: center;
20+
justify-content: space-between;
21+
}
22+
23+
.dropdown-toggle:hover {
24+
background-color: #f0f0f0;
25+
}
26+
27+
.dropdown-arrow {
28+
border: none;
29+
background: none;
30+
cursor: pointer;
31+
font-size: 15px;
32+
margin-left: 1px;
33+
margin-right: 10px;
34+
}
35+
36+
.dropdown-menu {
37+
position: absolute;
38+
background-color: #fff;
39+
border: 1px solid #ccc;
40+
border-radius: 5px;
41+
margin-top: 5px;
42+
z-index: 1000;
43+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
44+
}
45+
46+
.dropdown-item {
47+
padding: 10px 15px;
48+
cursor: pointer;
49+
font-size: 14px;
50+
color: #333;
51+
}
52+
53+
.dropdown-item:hover {
54+
background-color: #f0f0f0;
55+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import React, { useState } from 'react';
2+
import './Filtering.css';
3+
4+
const Filtering = ({ onFilterChange }) => {
5+
const [isOpen, setIsOpen] = useState(false); // State to toggle dropdown open/close
6+
const [selectedOption, setSelectedOption] = useState('Sort by'); // Initial state
7+
const [sortOrder, setSortOrder] = useState('asc'); // Track sort order (asc/desc)
8+
9+
const toggleDropdown = () => {
10+
setIsOpen(!isOpen); // Toggle dropdown open/close state
11+
};
12+
13+
const toggleSortOrder = () => {
14+
// Toggle sort order only if an option is selected
15+
if (selectedOption !== 'Sort by') {
16+
const newSortOrder = sortOrder === 'asc' ? 'desc' : 'asc';
17+
setSortOrder(newSortOrder);
18+
onFilterChange(selectedOption, newSortOrder); // Trigger filtering with new order
19+
}
20+
};
21+
22+
const handleOptionClick = (option) => {
23+
// Handle filter option selection
24+
setSelectedOption(option);
25+
onFilterChange(option, sortOrder); // Call the parent function with selected filter and order
26+
setIsOpen(false); // Collapse the dropdown after selection
27+
};
28+
29+
return (
30+
<div className="filtering-container">
31+
<div className="dropdown">
32+
{/* Make the entire button clickable for toggling dropdown */}
33+
<button onClick={toggleDropdown} className="dropdown-toggle">
34+
{selectedOption}
35+
{/* Render the up/down arrow next to selected option */}
36+
{selectedOption !== 'Sort by' && (
37+
<span onClick={(e) => { e.stopPropagation(); toggleSortOrder(); }}>
38+
{sortOrder === 'asc' ? ' ↑' : ' ↓'}
39+
</span>
40+
)}
41+
<span className="dropdown-arrow"></span>
42+
</button>
43+
44+
{isOpen && (
45+
<div className="dropdown-menu">
46+
<div onClick={() => handleOptionClick('Date Modified')} className="dropdown-item">
47+
Date Modified
48+
</div>
49+
<div onClick={() => handleOptionClick('Date Created')} className="dropdown-item">
50+
Date Created
51+
</div>
52+
<div onClick={() => handleOptionClick('Alphabetical')} className="dropdown-item">
53+
Alphabetical
54+
</div>
55+
</div>
56+
)}
57+
</div>
58+
</div>
59+
);
60+
};
61+
62+
export default Filtering;
63+
64+
65+

src/ui/components/Search/Search.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@ export default function Search({ onSearch }) {
3131
</div>
3232
);
3333
}
34+
35+
36+
37+

src/ui/views/OpenPushRequests/OpenPushRequests.jsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@ import GridContainer from '../../components/Grid/GridContainer';
44
import PushesTable from './components/PushesTable';
55
import CustomTabs from '../../components/CustomTabs/CustomTabs';
66

7+
78
import { Visibility, CheckCircle, Cancel, Block } from '@material-ui/icons';
89

910
export default function Dashboard() {
11+
12+
13+
1014
return (
1115
<div>
1216
<GridContainer>
1317
<GridItem xs={12} sm={12} md={12}>
18+
1419
<CustomTabs
1520
headerColor='primary'
1621
tabs={[
@@ -23,28 +28,32 @@ export default function Dashboard() {
2328
authorised={false}
2429
rejected={false}
2530
canceled={false}
31+
2632
/>
2733
),
2834
},
2935
{
3036
tabName: 'Approved',
3137
tabIcon: CheckCircle,
32-
tabContent: <PushesTable authorised={true} />,
38+
tabContent: <PushesTable
39+
authorised={true}
40+
41+
/>,
3342
},
3443
{
3544
tabName: 'Canceled',
3645
tabIcon: Cancel,
37-
tabContent: <PushesTable authorised={false} rejected={false} canceled={true} />,
46+
tabContent: <PushesTable authorised={false} rejected={false} canceled={true} />,
3847
},
3948
{
4049
tabName: 'Rejected',
4150
tabIcon: Block,
42-
tabContent: <PushesTable authorised={false} rejected={true} canceled={false} />,
51+
tabContent: <PushesTable authorised={false} rejected={true} canceled={false} />,
4352
},
4453
]}
4554
/>
4655
</GridItem>
4756
</GridContainer>
4857
</div>
4958
);
50-
}
59+
}

src/ui/views/OpenPushRequests/components/PushesTable.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import styles from '../../../assets/jss/material-dashboard-react/views/dashboard
1414
import { getPushes } from '../../../services/git-push';
1515
import { KeyboardArrowRight } from '@material-ui/icons';
1616

17+
18+
1719
export default function PushesTable(props) {
1820
const useStyles = makeStyles(styles);
1921
const classes = useStyles();
@@ -134,3 +136,7 @@ export default function PushesTable(props) {
134136
</div>
135137
);
136138
}
139+
140+
141+
142+

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

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import RepoOverview from './RepoOverview';
1313
import { UserContext } from '../../../../context';
1414
import PropTypes from 'prop-types';
1515
import Search from '../../../components/Search/Search';
16-
import Pagination from '../../../components/Pagination/Pagination';
16+
import Pagination from '../../../components/Pagination/Pagination';
17+
import Filtering from '../../../components/Filtering/Filtering';
1718

1819

1920
export default function Repositories(props) {
@@ -62,6 +63,32 @@ export default function Repositories(props) {
6263
);
6364
}
6465
};
66+
67+
// New function for handling filter changes
68+
const handleFilterChange = (filterOption, sortOrder) => {
69+
const sortedData = [...data];
70+
switch (filterOption) {
71+
case 'dateModified':
72+
sortedData.sort((a, b) => new Date(a.lastModified) - new Date(b.lastModified));
73+
break;
74+
case 'dateCreated':
75+
sortedData.sort((a, b) => new Date(a.dateCreated) - new Date(b.dateCreated));
76+
break;
77+
case 'alphabetical':
78+
sortedData.sort((a, b) => a.name.localeCompare(b.name));
79+
break;
80+
default:
81+
break;
82+
}
83+
84+
if (sortOrder === 'desc') {
85+
sortedData.reverse();
86+
}
87+
88+
setFilteredData(sortedData);
89+
};
90+
91+
6592
const handlePageChange = (page) => setCurrentPage(page);
6693
const startIdx = (currentPage - 1) * itemsPerPage;
6794
const paginatedData = filteredData.slice(startIdx, startIdx + itemsPerPage);
@@ -89,6 +116,7 @@ export default function Repositories(props) {
89116
totalItems={filteredData.length}
90117
itemsPerPage={itemsPerPage}
91118
onPageChange={handlePageChange}
119+
onFilterChange={handleFilterChange} // Pass handleFilterChange as prop
92120
/>
93121
);
94122
}
@@ -112,7 +140,7 @@ function GetGridContainerLayOut(props) {
112140
<GridItem xs={12} sm={12} md={12}>
113141

114142
<Search onSearch={props.onSearch} />
115-
143+
<Filtering onFilterChange={props.onFilterChange} /> {/* Include the Filtering component */}
116144
<TableContainer
117145
style={{ background: 'transparent', borderRadius: '5px', border: '1px solid #d0d7de' }}
118146
>
@@ -139,3 +167,4 @@ function GetGridContainerLayOut(props) {
139167
);
140168
}
141169

170+

src/ui/views/User/User.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import Button from '../../components/CustomButtons/Button';
88
import FormLabel from '@material-ui/core/FormLabel';
99
import { getUser, updateUser, getUserLoggedIn } from '../../services/user';
1010
import { makeStyles } from '@material-ui/core/styles';
11-
1211
import { LogoGithubIcon } from '@primer/octicons-react';
1312
import CloseRounded from '@material-ui/icons/CloseRounded';
1413
import { Check, Save } from '@material-ui/icons';

0 commit comments

Comments
 (0)