Fix incident history pager window navigation#4604
Fix incident history pager window navigation#4604Misrilal-Sah wants to merge 1 commit intocachethq:developfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes timeline pagination on the status page so “previous”/“next” navigation moves by full, non-overlapping date windows, addressing the confusing overlap described in issue #4435.
Changes:
- Introduces a
windowSpan(daysToShow + 1) to page by full windows rather than overlapping ranges. - Extracts and reuses
oldestDateInWindowfor clearer window boundary calculations. - Updates the backward paging availability check to align with the window boundary.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ->withCanPageBackward(Incident::notScheduled()->where('created_at', '<', $startDate->format('Y-m-d'))->count() > 0) | ||
| ->withPreviousDate($startDate->copy()->subDays($daysToShow)->toDateString()) | ||
| ->withNextDate($startDate->copy()->addDays($daysToShow)->toDateString()); | ||
| ->withCanPageBackward(Incident::notScheduled()->where('created_at', '<', $oldestDateInWindow->format('Y-m-d').' 00:00:00')->count() > 0) |
There was a problem hiding this comment.
withCanPageBackward(...) ignores the same visibility constraint used for $allIncidents (visible >= $incidentVisibility). For unauthenticated users this can surface a "previous" link even when only non-visible incidents exist before the current window, leading to navigation into empty/hidden pages. Consider reusing the same base query conditions (including visibility) and using ->exists() instead of ->count() > 0 to avoid a full COUNT scan.
| ->withCanPageBackward(Incident::notScheduled()->where('created_at', '<', $oldestDateInWindow->format('Y-m-d').' 00:00:00')->count() > 0) | |
| ->withCanPageBackward(Incident::notScheduled()->where('visible', '>=', $incidentVisibility)->where('created_at', '<', $oldestDateInWindow->format('Y-m-d').' 00:00:00')->exists()) |
Issue link id: #4435
Description:
This adjusts timeline pagination to move by full non-overlapping windows.
Previously, previous and next links could overlap date ranges and produce confusing navigation.
The fix updates window boundaries and backward availability checks so navigation behaves predictably.