Skip to content

Commit e528600

Browse files
Fix tech report pagination: Hide next/prev links based on actual data, reset to page 1 on filter changes (#1094)
* Initial plan * Fix tech report pagination: Hide next/prev links based on actual data, reset to page 1 on filter changes Co-authored-by: max-ostapenko <1611259+max-ostapenko@users.noreply.github.com> * Fix linting errors: Remove whitespace from blank lines in test file Co-authored-by: max-ostapenko <1611259+max-ostapenko@users.noreply.github.com> * fix positioning * cleanup --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: max-ostapenko <1611259+max-ostapenko@users.noreply.github.com>
1 parent 0fe4a0e commit e528600

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

src/js/components/filters.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ class Filters {
7171
url.searchParams.append('category', categories);
7272
}
7373

74+
// Reset to page 1 when filters change
75+
url.searchParams.delete('page');
76+
url.searchParams.append('page', '1');
77+
7478
// /* Scroll to the report content */
7579
// url.hash = '#report-content';
7680

src/js/techreport/utils/data.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,27 @@ const fetchCategoryData = (rows, filters, callback) => {
239239
/* Update the pagination info */
240240
const current = document.querySelectorAll('[data-page="current"]');
241241
const total = document.querySelectorAll('[data-page="total"]');
242+
const totalPages = Math.ceil(category?.technologies?.length / rows);
242243
current.forEach(c => c.textContent = pageNr);
243-
total.forEach(t => t.textContent = Math.ceil(category?.technologies?.length / rows));
244+
total.forEach(t => t.textContent = totalPages);
245+
246+
/* Update pagination links visibility */
247+
const nextPageLink = document.querySelector('[data-pagination="next"]');
248+
const prevPageLink = document.querySelector('[data-pagination="previous"]');
249+
if (prevPageLink) {
250+
if (pageNr <= 1) {
251+
prevPageLink.style.display = 'none';
252+
} else {
253+
prevPageLink.style.display = 'block';
254+
}
255+
}
256+
if (nextPageLink) {
257+
if (pageNr >= totalPages) {
258+
nextPageLink.style.display = 'none';
259+
} else {
260+
nextPageLink.style.display = 'block';
261+
}
262+
}
244263

245264
/* Update components */
246265
callback(category);

static/css/techreport/techreport.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,6 +1458,11 @@ select {
14581458
border-top: 1px solid var(--color-separator);
14591459
}
14601460

1461+
.table-page-info {
1462+
margin-left: auto;
1463+
margin-right: auto;
1464+
}
1465+
14611466
.table-page-info p {
14621467
text-align: center;
14631468
}

templates/techreport/category.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ <h2><a href="#comparison-summary" class="anchor">Technologies</a></h2>
135135

136136
<div class="table-pagination">
137137
{% set filters = tech_report_page.filters %}
138-
<p data-pagination="previous">
138+
<p data-pagination="previous" style="display: none;">
139139
{% if filters.page and filters.page > 1 %}
140140
<a href="/reports/techreport/category?geo={{ filters.geo }}&rank={{ filters.rank }}&category={{ filters.category }}&page={{ filters.page - 1 }}{%if filters.selected %}&selected={{ filters.selected }}{% endif %}{%if filters.rows %}&rows={{ filters.rows }}{% endif %}">Previous page </a>
141141
{% endif %}
@@ -170,8 +170,8 @@ <h2><a href="#comparison-summary" class="anchor">Technologies</a></h2>
170170
<span id="rows-announcement"></span>
171171
</p>
172172
</div>
173-
<p data-pagination="next">
174-
{% if not filters.last_page and filters.last_page == False %}
173+
<p data-pagination="next" style="display: none;">
174+
{% if not filters.last_page %}
175175
<a href="/reports/techreport/category?geo={{ filters.geo }}&rank={{ filters.rank }}&category={{ filters.category }}&page={{ filters.page + 1 }}{%if filters.selected %}&selected={{ filters.selected }}{% endif %}{%if filters.rows %}&rows={{ filters.rows }}{% endif %}">Next page</a>
176176
{% endif %}
177177
</p>

0 commit comments

Comments
 (0)