Skip to content

Commit 01ac951

Browse files
committed
fix: fix dashboard data not displayng
1 parent 38041ff commit 01ac951

File tree

1 file changed

+59
-98
lines changed

1 file changed

+59
-98
lines changed

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

Lines changed: 59 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ 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
import Search from '../../../components/Search/Search'; // Import the Search component
17-
import Pagination from '../../../components/Pagination/Pagination'; // Import Pagination component
17+
import Pagination from '../../../components/Pagination/Pagination'; // Import Pagination component
1818

1919
export default function PushesTable(props) {
2020
const useStyles = makeStyles(styles);
@@ -30,102 +30,67 @@ export default function PushesTable(props) {
3030
const [searchTerm, setSearchTerm] = useState(''); // Define searchTerm state
3131
const openPush = (push) => navigate(`/admin/push/${push}`, { replace: true });
3232

33-
34-
35-
3633
useEffect(() => {
3734
const query = {};
38-
3935
for (const k in props) {
40-
if (!k) continue;
41-
query[k] = props[k];
36+
if (k) query[k] = props[k];
4237
}
4338
getPushes(setIsLoading, setData, setAuth, setIsError, query);
4439
}, [props]);
4540

46-
47-
4841
useEffect(() => {
49-
// Initialize filtered data with full data on load
50-
const filtered = filterByStatus(data);
51-
setFilteredData(filtered);
52-
}, [props]);
53-
54-
const filterByStatus = (data) => {
55-
if (props.authorised) {
56-
return data.filter(item => item.status === 'approved');
57-
}
58-
if (props.rejected) {
59-
return data.filter(item => item.status === 'rejected');
60-
}
61-
if (props.canceled) {
62-
return data.filter(item => item.status === 'canceled');
63-
}
64-
if (props.blocked) {
65-
return data.filter(item => item.status === 'pending');
66-
}
67-
return data;
68-
};
42+
setFilteredData(data);
43+
}, [data]);
6944

70-
71-
// Apply search to the filtered data
7245
useEffect(() => {
73-
const filtered = filterByStatus(data); // Apply status filter first
74-
if (searchTerm) {
75-
const lowerCaseTerm = searchTerm.toLowerCase();
76-
const searchFiltered = filtered.filter((item) =>
77-
item.repo.toLowerCase().includes(lowerCaseTerm) ||
78-
item.commitTo.toLowerCase().includes(lowerCaseTerm) ||
79-
80-
item.commitData[0].message.toLowerCase().includes(lowerCaseTerm)
81-
);
82-
setFilteredData(searchFiltered);
83-
} else {
84-
setFilteredData(filtered); // Reset to filtered data after clearing search
85-
}
86-
setCurrentPage(1); // Reset pagination on search
87-
}, [searchTerm, props]); // Trigger on search or tab change
46+
const lowerCaseTerm = searchTerm.toLowerCase();
47+
const filtered = searchTerm
48+
? data.filter(
49+
(item) =>
50+
item.repo.toLowerCase().includes(lowerCaseTerm) ||
51+
item.commitTo.toLowerCase().includes(lowerCaseTerm) ||
52+
item.commitData[0].message.toLowerCase().includes(lowerCaseTerm),
53+
)
54+
: data;
55+
setFilteredData(filtered);
56+
setCurrentPage(1);
57+
}, [searchTerm, data]);
8858

8959
// Handler function for search input
90-
const handleSearch = (searchTerm) => {
91-
setSearchTerm(searchTerm); // Update search term state
92-
};
93-
60+
const handleSearch = (term) => setSearchTerm(term.trim());
9461

9562
const handlePageChange = (page) => {
96-
setCurrentPage(page); // Update current page
63+
setCurrentPage(page); // Update current page
9764
};
9865

99-
// Logic for pagination (getting items for the current page)
100-
const indexOfLastItem = currentPage * itemsPerPage;
101-
const indexOfFirstItem = indexOfLastItem - itemsPerPage;
102-
const currentItems = filteredData.slice(indexOfFirstItem, indexOfLastItem);
103-
104-
// Change page
105-
const paginate = (pageNumber) => setCurrentPage(pageNumber);
66+
// Logic for pagination (getting items for the current page)
67+
const indexOfLastItem = currentPage * itemsPerPage;
68+
const indexOfFirstItem = indexOfLastItem - itemsPerPage;
69+
const currentItems = filteredData.slice(indexOfFirstItem, indexOfLastItem);
70+
71+
// Change page
72+
const paginate = (pageNumber) => setCurrentPage(pageNumber);
10673

10774
if (isLoading) return <div>Loading...</div>;
10875
if (isError) return <div>Something went wrong ...</div>;
10976

11077
return (
11178
<div>
11279
<Search onSearch={handleSearch} /> {/* Use the Search component */}
113-
114-
11580
<TableContainer component={Paper}>
116-
<Table className={classes.table} aria-label="simple table">
81+
<Table className={classes.table} aria-label='simple table'>
11782
<TableHead>
11883
<TableRow>
119-
<TableCell align="left">Timestamp</TableCell>
120-
<TableCell align="left">Repository</TableCell>
121-
<TableCell align="left">Branch</TableCell>
122-
<TableCell align="left">Commit SHA</TableCell>
123-
<TableCell align="left">Committer</TableCell>
124-
<TableCell align="left">Author</TableCell>
125-
<TableCell align="left">Author E-mail</TableCell>
126-
<TableCell align="left">Commit Message</TableCell>
127-
<TableCell align="left">No. of Commits</TableCell>
128-
<TableCell align="right"></TableCell>
84+
<TableCell align='left'>Timestamp</TableCell>
85+
<TableCell align='left'>Repository</TableCell>
86+
<TableCell align='left'>Branch</TableCell>
87+
<TableCell align='left'>Commit SHA</TableCell>
88+
<TableCell align='left'>Committer</TableCell>
89+
<TableCell align='left'>Author</TableCell>
90+
<TableCell align='left'>Author E-mail</TableCell>
91+
<TableCell align='left'>Commit Message</TableCell>
92+
<TableCell align='left'>No. of Commits</TableCell>
93+
<TableCell align='right'></TableCell>
12994
</TableRow>
13095
</TableHead>
13196
<TableBody>
@@ -135,53 +100,53 @@ export default function PushesTable(props) {
135100

136101
return (
137102
<TableRow key={row.id}>
138-
<TableCell align="left">
103+
<TableCell align='left'>
139104
{moment
140105
.unix(row.commitData[0].commitTs || row.commitData[0].commitTimestamp)
141106
.toString()}
142107
</TableCell>
143-
<TableCell align="left">
144-
<a href={`https://github.com/${row.repo}`} rel="noreferrer" target="_blank">
108+
<TableCell align='left'>
109+
<a href={`https://github.com/${row.repo}`} rel='noreferrer' target='_blank'>
145110
{repoFullName}
146111
</a>
147112
</TableCell>
148-
<TableCell align="left">
113+
<TableCell align='left'>
149114
<a
150115
href={`https://github.com/${repoFullName}/tree/${repoBranch}`}
151-
rel="noreferrer"
152-
target="_blank"
116+
rel='noreferrer'
117+
target='_blank'
153118
>
154119
{repoBranch}
155120
</a>
156121
</TableCell>
157-
<TableCell align="left">
122+
<TableCell align='left'>
158123
<a
159124
href={`https://github.com/${repoFullName}/commit/${row.commitTo}`}
160-
rel="noreferrer"
161-
target="_blank"
125+
rel='noreferrer'
126+
target='_blank'
162127
>
163128
{row.commitTo.substring(0, 8)}
164129
</a>
165130
</TableCell>
166-
<TableCell align="left">
131+
<TableCell align='left'>
167132
<a
168133
href={`https://github.com/${row.commitData[0].committer}`}
169-
rel="noreferrer"
170-
target="_blank"
134+
rel='noreferrer'
135+
target='_blank'
171136
>
172137
{row.commitData[0].committer}
173138
</a>
174139
</TableCell>
175-
<TableCell align="left">
140+
<TableCell align='left'>
176141
<a
177142
href={`https://github.com/${row.commitData[0].author}`}
178-
rel="noreferrer"
179-
target="_blank"
143+
rel='noreferrer'
144+
target='_blank'
180145
>
181146
{row.commitData[0].author}
182147
</a>
183148
</TableCell>
184-
<TableCell align="left">
149+
<TableCell align='left'>
185150
{row.commitData[0].authorEmail ? (
186151
<a href={`mailto:${row.commitData[0].authorEmail}`}>
187152
{row.commitData[0].authorEmail}
@@ -190,10 +155,10 @@ export default function PushesTable(props) {
190155
'No data...'
191156
)}
192157
</TableCell>
193-
<TableCell align="left">{row.commitData[0].message}</TableCell>
194-
<TableCell align="left">{row.commitData.length}</TableCell>
195-
<TableCell component="th" scope="row">
196-
<Button variant="contained" color="primary" onClick={() => openPush(row.id)}>
158+
<TableCell align='left'>{row.commitData[0].message}</TableCell>
159+
<TableCell align='left'>{row.commitData.length}</TableCell>
160+
<TableCell component='th' scope='row'>
161+
<Button variant='contained' color='primary' onClick={() => openPush(row.id)}>
197162
<KeyboardArrowRight />
198163
</Button>
199164
</TableCell>
@@ -203,18 +168,14 @@ export default function PushesTable(props) {
203168
</TableBody>
204169
</Table>
205170
</TableContainer>
206-
{/* Pagination Component */}
207-
<Pagination
171+
{/* Pagination Component */}
172+
<Pagination
208173
itemsPerPage={itemsPerPage}
209174
totalItems={filteredData.length}
210175
paginate={paginate}
211176
currentPage={currentPage}
212-
onPageChange={handlePageChange}
177+
onPageChange={handlePageChange}
213178
/>
214179
</div>
215180
);
216181
}
217-
218-
219-
220-

0 commit comments

Comments
 (0)