Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 31, 2025

This PR fixes the tech report pagination issue where the "Next page" link was displayed even when there were no more technologies to show, leading to 400 errors when users clicked on it.

Problem

The pagination logic had two main issues:

  1. Incorrect "Next page" visibility: The template showed the "Next page" link based on the last_page parameter, which defaulted to False, meaning the link was always shown regardless of actual data availability
  2. Filter changes not resetting page: When users changed filters (geo, rank, category), they could land on invalid page numbers that had no data

Solution

The fix involves three key changes:

1. Dynamic Pagination Control in Frontend

Modified src/js/techreport/utils/data.js to calculate the actual total pages based on API data and dynamically show/hide pagination links:

const totalPages = Math.ceil(category?.technologies?.length / rows);

// Hide "Next page" if on last page
if (pageNr >= totalPages) {
  nextPageLink.style.display = 'none';
} else {
  nextPageLink.style.display = 'block';
}

2. Template Updates for JavaScript Control

Updated templates/techreport/category.html to initially hide pagination links with style="display: none;" and let JavaScript control their visibility based on actual data rather than server-side logic.

3. Filter Reset to Page 1

Modified src/js/components/filters.js to automatically reset to page 1 when any filter changes:

// Reset to page 1 when filters change
url.searchParams.delete('page');
url.searchParams.append('page', '1');

Testing

  • ✅ All existing tech report tests pass
  • ✅ Added new tests to verify pagination links are initially hidden and controlled by JavaScript
  • ✅ Manual testing confirms pagination works correctly
  • ✅ Build process completed successfully

Before/After Behavior

  • Before: "Next page" always visible → clicking leads to empty pages with 400 errors
  • After: "Next page" only visible when there are actually more pages → smooth navigation experience

Category Page Screenshot

This ensures users have a better experience when browsing tech reports and eliminates the confusing 400 errors from invalid pagination requests.

Fixes #1088.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…, reset to page 1 on filter changes

Co-authored-by: max-ostapenko <[email protected]>
Copilot AI changed the title [WIP] Tech Report: Next page available on categories report even when there is no more technologies Fix tech report pagination: Hide next/prev links based on actual data, reset to page 1 on filter changes Jul 31, 2025
Copilot AI requested a review from max-ostapenko July 31, 2025 17:57
@max-ostapenko
Copy link
Contributor

@copilot fix errors detected in the linting checks

Copy link
Contributor Author

Copilot AI commented Jul 31, 2025

@copilot fix errors detected in the linting checks

Fixed the linting errors in commit 8188f5a. The issues were whitespace on blank lines in the Python test file (flake8 W293 violations). All linting checks now pass:

  • ✅ Python: flake8, black, pylint
  • ✅ HTML: htmlhint
  • ✅ JavaScript: eslint (basic checks)

Tests continue to pass after the fix.

@max-ostapenko max-ostapenko marked this pull request as ready for review July 31, 2025 20:31
@max-ostapenko max-ostapenko requested a review from tunetheweb July 31, 2025 20:33
@max-ostapenko
Copy link
Contributor

@tunetheweb wanted to get rid of the errors, so asked a friend for help.
WDYT?

Copy link
Member

@tunetheweb tunetheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@max-ostapenko max-ostapenko merged commit e528600 into main Jul 31, 2025
9 checks passed
@max-ostapenko max-ostapenko deleted the copilot/fix-1088 branch July 31, 2025 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tech Report: Next page available on categories report even when there is no more technologies

3 participants