Skip to content

fix: search & filter mismatch with pagination on Tracker pageagination#362

Open
rathan2511 wants to merge 1 commit into
GitMetricsLab:mainfrom
rathan2511:fix/tracker-search-pagination
Open

fix: search & filter mismatch with pagination on Tracker pageagination#362
rathan2511 wants to merge 1 commit into
GitMetricsLab:mainfrom
rathan2511:fix/tracker-search-pagination

Conversation

@rathan2511
Copy link
Copy Markdown

@rathan2511 rathan2511 commented May 21, 2026

🛠️ Related Issue

Closes: #360

📌 Description

This PR fixes a critical data-flow bug in the Tracker page (/track) where search filters, repository scopes, and date ranges were being applied client-side on a paginated subset of only 10 items. This was causing a pagination count mismatch and prevented users from searching their complete GitHub history.

This PR also fixes a pre-existing TypeScript type-checking build error in the hook destructuring block of Tracker.tsx.

✨ Changes Made

  • Server-Side Filtering: Updated the useEffect and handleSubmit routines in Tracker.tsx to pass the state-driven search/filter inputs directly to the fetchData call. The GitHub Search API now handles all filtering server-side.
  • Redundancy Cleanup: Removed the redundant filterData client-side helper function completely since the API returns already-filtered data.
  • TypeScript Compiler Fix: Fixed a pre-existing upstream compile error by removing the destructured non-existent authError parameter from the useGitHubAuth hook and updating the error Alert rendering logic to only read dataError.
  • Unified Form submission: Extended the main <form> container to wrap both authentication and filter blocks so users can apply filters by pressing "Enter" inside any filter text field.
  • Resets Pagination Index: Configured the state dropdown filter's onChange event to call setPage(0) so pagination resets back to the first page when changing status filters.

📷 Screenshots

image image

🧪 Type of Change

  • Bug fix
  • UI/UX improvement
  • New feature
  • Documentation update

✔️ Checklist

  • My code follows project style guidelines
  • I have tested my changes (built successfully via npm run build)
  • I have linked the related issue
  • No unnecessary files are included

Summary by CodeRabbit

  • Improvements
    • Reorganized filter form layout for better user experience
    • Updated action button label to "Fetch Data / Apply Filters" for clarity
    • Simplified error message display in the UI

Review Change Stack

@netlify
Copy link
Copy Markdown

netlify Bot commented May 21, 2026

Deploy Preview for github-spy ready!

Name Link
🔨 Latest commit 27fa081
🔍 Latest deploy log https://app.netlify.com/projects/github-spy/deploys/6a0f11dee3282400080c5ee3
😎 Deploy Preview https://deploy-preview-362--github-spy.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 21, 2026

📝 Walkthrough

Walkthrough

Tracker.tsx refactored to move search and filter logic server-side. Filter parameters (search, repo, date range, state) are now passed to fetchData calls instead of filtering paginated results locally. The filterData helper is removed, form controls reorganized into a single submission, and error handling simplified.

Changes

Server-Side Filtering Refactor

Layer / File(s) Summary
Fetch Configuration with Filter Parameters
src/pages/Tracker/Tracker.tsx
useEffect and handleSubmit now pass filter state (search, repo, startDate, endDate, state) as parameters to fetchData, with issueFilter and prFilter added to the effect dependency array. authError is removed from useGitHubAuth destructuring.
Client-Side Filter Removal and Data Selection
src/pages/Tracker/Tracker.tsx
Local filterData(...) function and its client-side filtering logic are removed. currentFilteredData now derives directly from issues/prs without additional local filtering, since results are pre-filtered server-side.
Form UI and State Filter Handler
src/pages/Tracker/Tracker.tsx
Filter inputs (search title, repository, start/end dates) are moved inside the main form element to submit via handleSubmit. State Select onChange handler now resets pagination and updates the correct per-tab filter state.
Error Display Simplification
src/pages/Tracker/Tracker.tsx
Error Alert displays only dataError, removing authError from the error rendering path.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • GitMetricsLab/github_tracker#255: Implements server-side filtering changes in useGitHubData and corresponding Tracker rework to pass search/repo/date/state filters directly to the API.
  • GitMetricsLab/github_tracker#298: Updates useGitHubData's error handling to generate user-facing dataError messages that align with this PR's shift to displaying only dataError in the UI.
  • GitMetricsLab/github_tracker#200: Fixes the underlying closed/merged PR classification logic in useGitHubData, which relates to how the state filter parameter is now passed server-side.

Suggested labels

gssoc25, gssoc:approved, level:advanced, quality:clean

Poem

🐰 From client-side dreams to server-side schemes,
Your filters now fetch what they gleam,
No more false pagination's charade,
The API returns exactly what's made,
Clean data flow, a filtering arcade!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title relates to the main fix (search/filter with pagination), but contains a typo: 'pageagination' appears to be duplicated/malformed text. Correct the title to 'fix: search & filter mismatch with pagination on Tracker page' by removing the duplicated/unclear 'pageagination' suffix.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description is comprehensive and matches the template with all key sections completed including related issue, detailed changes, screenshots, and type of change checkboxes.
Linked Issues check ✅ Passed All requirements from #360 are addressed: server-side filtering implemented, fetchData calls pass filter parameters, client-side filterData removed, pagination resets on filter changes, and TypeScript build error fixed.
Out of Scope Changes check ✅ Passed All changes are directly scoped to #360 objectives: moving filtering server-side, removing filterData helper, fixing TypeScript errors, and improving form UX. No out-of-scope modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

🎉 Thank you @rathan2511 for your contribution. Please make sure your PR follows https://github.com/GitMetricsLab/github_tracker/blob/main/CONTRIBUTING.md#-pull-request-guidelines

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/pages/Tracker/Tracker.tsx`:
- Around line 94-104: handleSubmit currently calls setPage(0) and then
fetchData(...) directly, causing a duplicate fetch because the effect that
depends on page will run after the state update; remove the synchronous
fetchData call from handleSubmit and let the existing useEffect that watches
page (and the filter/search state) own fetching when page changes. Ensure the
effect's dependency array includes searchTitle, selectedRepo, startDate,
endDate, tab, issueFilter, prFilter and page so setting page to 0 triggers the
single, correct fetch.
- Around line 82-92: handleSubmit currently sets page to 0 and then calls
fetchData directly which causes duplicate requests because the useEffect (which
depends on page) will also call fetchData; remove the direct fetchData call from
handleSubmit and rely on setting page to 0 to trigger the existing useEffect
that calls fetchData (keep fetchData memoized via useCallback). In the useEffect
that calls fetchData, explicitly omit username and fetchData from the dependency
array by adding a brief eslint-disable comment for react-hooks/exhaustive-deps
and a comment explaining we only want manual/authed submits to trigger fetches;
do not add authError (it doesn’t exist) and continue to use dataError from
useGitHubData, and note that merged handling is already done inside
useGitHubData so no change is needed there.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cd85765a-853e-4443-9a9c-b2f98651079d

📥 Commits

Reviewing files that changed from the base of the PR and between 9d34c19 and 27fa081.

📒 Files selected for processing (1)
  • src/pages/Tracker/Tracker.tsx

Comment on lines 82 to +92
useEffect(() => {
if (username) {
fetchData(username, page + 1, ROWS_PER_PAGE);
fetchData(username, page + 1, ROWS_PER_PAGE, tab === 0 ? "issue" : "pr", {
search: searchTitle,
repo: selectedRepo,
startDate,
endDate,
state: tab === 0 ? issueFilter : prFilter,
});
}
}, [tab, page]);
}, [tab, page, issueFilter, prFilter]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
fd -t f 'useGitHubData' src/hooks
rg -nP -C5 '\b(fetchData|useGitHubData)\b' src/hooks

Repository: GitMetricsLab/github_tracker

Length of output: 1662


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Show relevant parts of Tracker.tsx around the reported lines and nearby logic.
sed -n '1,220p' src/pages/Tracker/Tracker.tsx | nl -ba | sed -n '60,130p'
sed -n '220,380p' src/pages/Tracker/Tracker.tsx | nl -ba

# Inspect hooks for error shapes and "merged" handling.
sed -n '1,240p' src/hooks/useGitHubData.ts | nl -ba | sed -n '1,220p'
sed -n '220,340p' src/hooks/useGitHubData.ts | nl -ba

sed -n '1,240p' src/hooks/useGitHubAuth.ts | nl -ba

# Search for how "merged" is used/translated across the repo.
rg -n --hidden --no-ignore-vcs '\bmerged\b' src

Repository: GitMetricsLab/github_tracker

Length of output: 115


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Tracker.tsx: print with line numbers using cat -n (nl missing in this sandbox)
cat -n src/pages/Tracker/Tracker.tsx | sed -n '60,170p'
cat -n src/pages/Tracker/Tracker.tsx | sed -n '170,340p'

# Hooks
cat -n src/hooks/useGitHubData.ts | sed -n '1,220p'
cat -n src/hooks/useGitHubData.ts | sed -n '220,310p'
cat -n src/hooks/useGitHubAuth.ts | sed -n '1,260p'

# Search for "merged" translation
rg -n --hidden --no-ignore-vcs '\bmerged\b' src

Repository: GitMetricsLab/github_tracker

Length of output: 19844


🏁 Script executed:

#!/bin/bash
set -euo pipefail
rg -n '\bauthError\b' src/pages/Tracker/Tracker.tsx
rg -n '\buseGitHubAuth\b' src/pages/Tracker/Tracker.tsx

Repository: GitMetricsLab/github_tracker

Length of output: 54


Avoid duplicate network requests when applying filters + fix deps lint intent

  • handleSubmit sets page to 0 and also calls fetchData directly; when the current page is not 0, the useEffect (which depends on page) fires and triggers the same fetch again → duplicate requests.
  • useEffect uses username (and fetchData) but they’re intentionally not in deps; since fetchData is already memoized via useCallback, keep the current “auth changes require Submit” behavior by suppressing react-hooks/exhaustive-deps with a brief comment (or include them only if you want auto-fetch on auth changes).
  • The merged state is already handled in useGitHubData by translating filters.state === 'merged' to is:merged for PR searches—no change needed there.
  • No authError exists in useGitHubAuth; dataError from useGitHubData is what’s displayed.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/pages/Tracker/Tracker.tsx` around lines 82 - 92, handleSubmit currently
sets page to 0 and then calls fetchData directly which causes duplicate requests
because the useEffect (which depends on page) will also call fetchData; remove
the direct fetchData call from handleSubmit and rely on setting page to 0 to
trigger the existing useEffect that calls fetchData (keep fetchData memoized via
useCallback). In the useEffect that calls fetchData, explicitly omit username
and fetchData from the dependency array by adding a brief eslint-disable comment
for react-hooks/exhaustive-deps and a comment explaining we only want
manual/authed submits to trigger fetches; do not add authError (it doesn’t
exist) and continue to use dataError from useGitHubData, and note that merged
handling is already done inside useGitHubData so no change is needed there.

Comment on lines 94 to 104
const handleSubmit = (e: React.FormEvent<HTMLFormElement>): void => {
e.preventDefault();
setPage(0);
fetchData(username, 1, ROWS_PER_PAGE);
fetchData(username, 1, ROWS_PER_PAGE, tab === 0 ? "issue" : "pr", {
search: searchTitle,
repo: selectedRepo,
startDate,
endDate,
state: tab === 0 ? issueFilter : prFilter,
});
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Potential double fetch when submitting from a non-first page.

setPage(0) schedules a state update, then fetchData(...) is invoked synchronously. When the current page is not 0, the subsequent re-render will trigger the useEffect (because page is in its dep array), firing a second fetchData call with the same arguments. On page 0 only the direct call runs. The result is an inconsistent number of network requests depending on the user's pagination state.

♻️ Suggested fix — let the effect own the fetch
   const handleSubmit = (e: React.FormEvent<HTMLFormElement>): void => {
     e.preventDefault();
-    setPage(0);
-    fetchData(username, 1, ROWS_PER_PAGE, tab === 0 ? "issue" : "pr", {
-      search: searchTitle,
-      repo: selectedRepo,
-      startDate,
-      endDate,
-      state: tab === 0 ? issueFilter : prFilter,
-    });
+    if (page !== 0) {
+      setPage(0); // effect will refetch with page=0
+    } else {
+      fetchData(username, 1, ROWS_PER_PAGE, tab === 0 ? "issue" : "pr", {
+        search: searchTitle,
+        repo: selectedRepo,
+        startDate,
+        endDate,
+        state: tab === 0 ? issueFilter : prFilter,
+      });
+    }
   };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/pages/Tracker/Tracker.tsx` around lines 94 - 104, handleSubmit currently
calls setPage(0) and then fetchData(...) directly, causing a duplicate fetch
because the effect that depends on page will run after the state update; remove
the synchronous fetchData call from handleSubmit and let the existing useEffect
that watches page (and the filter/search state) own fetching when page changes.
Ensure the effect's dependency array includes searchTitle, selectedRepo,
startDate, endDate, tab, issueFilter, prFilter and page so setting page to 0
triggers the single, correct fetch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug Report: Search & Filters are Broken due to Client-Side Filtering on Paginated Data

1 participant