Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Update frontend/src/pages/ReportsHistory.jsx
Browse files
frontend/src/pages/ReportsHistory.jsx
CHANGED
|
@@ -28,6 +28,13 @@ export const ReportsHistory = () => {
|
|
| 28 |
const [sortColumn, setSortColumn] = useState('Date');
|
| 29 |
const [sortDirection, setSortDirection] = useState('desc');
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
const { token } = useAuth();
|
| 32 |
const navigate = useNavigate();
|
| 33 |
|
|
@@ -177,6 +184,14 @@ export const ReportsHistory = () => {
|
|
| 177 |
});
|
| 178 |
};
|
| 179 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
return (
|
| 181 |
<div className="flex flex-col gap-lg text-left w-full">
|
| 182 |
|
|
@@ -291,12 +306,12 @@ export const ReportsHistory = () => {
|
|
| 291 |
|
| 292 |
{/* List Items */}
|
| 293 |
<div className="flex flex-col divide-y divide-outline-variant">
|
| 294 |
-
{
|
| 295 |
<div className="text-center py-2xl text-on-surface-variant font-body-sm">
|
| 296 |
No historical security audits match your search query.
|
| 297 |
</div>
|
| 298 |
) : (
|
| 299 |
-
|
| 300 |
const hasCritical = s.vulnerabilities_count?.critical > 0;
|
| 301 |
const hasHigh = s.vulnerabilities_count?.high > 0;
|
| 302 |
|
|
@@ -404,15 +419,31 @@ export const ReportsHistory = () => {
|
|
| 404 |
</div>
|
| 405 |
|
| 406 |
{/* Pagination footer */}
|
| 407 |
-
<div className="px-lg py-md border-t border-outline-variant bg-surface-container-low flex justify-between items-center">
|
| 408 |
<span className="font-body-sm text-body-sm text-on-surface-variant">
|
| 409 |
-
|
|
|
|
|
|
|
|
|
|
| 410 |
</span>
|
| 411 |
<div className="flex items-center gap-sm">
|
| 412 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 413 |
<span className="material-symbols-outlined">chevron_left</span>
|
| 414 |
</button>
|
| 415 |
-
<button
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 416 |
<span className="material-symbols-outlined">chevron_right</span>
|
| 417 |
</button>
|
| 418 |
</div>
|
|
|
|
| 28 |
const [sortColumn, setSortColumn] = useState('Date');
|
| 29 |
const [sortDirection, setSortDirection] = useState('desc');
|
| 30 |
|
| 31 |
+
const [currentPage, setCurrentPage] = useState(1);
|
| 32 |
+
const itemsPerPage = 15;
|
| 33 |
+
|
| 34 |
+
useEffect(() => {
|
| 35 |
+
setCurrentPage(1);
|
| 36 |
+
}, [searchQuery, scanTypeFilter, dateFilter, statusFilter]);
|
| 37 |
+
|
| 38 |
const { token } = useAuth();
|
| 39 |
const navigate = useNavigate();
|
| 40 |
|
|
|
|
| 184 |
});
|
| 185 |
};
|
| 186 |
|
| 187 |
+
// Calculate Pagination (15 items per page)
|
| 188 |
+
const sortedScans = getSortedScans();
|
| 189 |
+
const totalItems = sortedScans.length;
|
| 190 |
+
const totalPages = Math.ceil(totalItems / itemsPerPage) || 1;
|
| 191 |
+
const startIndex = (currentPage - 1) * itemsPerPage;
|
| 192 |
+
const endIndex = Math.min(startIndex + itemsPerPage, totalItems);
|
| 193 |
+
const paginatedScans = sortedScans.slice(startIndex, endIndex);
|
| 194 |
+
|
| 195 |
return (
|
| 196 |
<div className="flex flex-col gap-lg text-left w-full">
|
| 197 |
|
|
|
|
| 306 |
|
| 307 |
{/* List Items */}
|
| 308 |
<div className="flex flex-col divide-y divide-outline-variant">
|
| 309 |
+
{paginatedScans.length === 0 ? (
|
| 310 |
<div className="text-center py-2xl text-on-surface-variant font-body-sm">
|
| 311 |
No historical security audits match your search query.
|
| 312 |
</div>
|
| 313 |
) : (
|
| 314 |
+
paginatedScans.map((s) => {
|
| 315 |
const hasCritical = s.vulnerabilities_count?.critical > 0;
|
| 316 |
const hasHigh = s.vulnerabilities_count?.high > 0;
|
| 317 |
|
|
|
|
| 419 |
</div>
|
| 420 |
|
| 421 |
{/* Pagination footer */}
|
| 422 |
+
<div className="px-lg py-md border-t border-outline-variant bg-surface-container-low flex flex-col sm:flex-row justify-between items-center gap-sm">
|
| 423 |
<span className="font-body-sm text-body-sm text-on-surface-variant">
|
| 424 |
+
{totalItems > 0
|
| 425 |
+
? `Showing ${startIndex + 1}-${endIndex} of ${totalItems} completed logs`
|
| 426 |
+
: `Showing 0 of 0 completed logs`
|
| 427 |
+
}
|
| 428 |
</span>
|
| 429 |
<div className="flex items-center gap-sm">
|
| 430 |
+
<span className="font-body-sm text-body-sm text-on-surface-variant mr-xs">
|
| 431 |
+
Page {currentPage} of {totalPages}
|
| 432 |
+
</span>
|
| 433 |
+
<button
|
| 434 |
+
onClick={() => setCurrentPage(prev => Math.max(prev - 1, 1))}
|
| 435 |
+
disabled={currentPage === 1}
|
| 436 |
+
className="p-[4px] rounded hover:bg-surface-variant text-on-surface-variant transition-colors disabled:opacity-30 border-0 bg-transparent cursor-pointer flex items-center justify-center disabled:cursor-not-allowed"
|
| 437 |
+
title="Previous Page"
|
| 438 |
+
>
|
| 439 |
<span className="material-symbols-outlined">chevron_left</span>
|
| 440 |
</button>
|
| 441 |
+
<button
|
| 442 |
+
onClick={() => setCurrentPage(prev => Math.min(prev + 1, totalPages))}
|
| 443 |
+
disabled={currentPage >= totalPages}
|
| 444 |
+
className="p-[4px] rounded hover:bg-surface-variant text-on-surface-variant transition-colors disabled:opacity-30 border-0 bg-transparent cursor-pointer flex items-center justify-center disabled:cursor-not-allowed"
|
| 445 |
+
title="Next Page"
|
| 446 |
+
>
|
| 447 |
<span className="material-symbols-outlined">chevron_right</span>
|
| 448 |
</button>
|
| 449 |
</div>
|