Skip to content

fix(content-drive): fix totalItems calculation and type paginate event#34890

Merged
zJaaal merged 5 commits intomainfrom
34354-defect-content-drive-search-leaks-info-with-limited-user-frontend
Mar 6, 2026
Merged

fix(content-drive): fix totalItems calculation and type paginate event#34890
zJaaal merged 5 commits intomainfrom
34354-defect-content-drive-search-leaks-info-with-limited-user-frontend

Conversation

@zJaaal
Copy link
Copy Markdown
Member

@zJaaal zJaaal commented Mar 6, 2026

Summary

  • Fix off-by-one in $totalItems: pagination.page is already 1-indexed — removed the erroneous + 1 (and the trailing - 1) that inflated the total by a full page on every page
  • Correct hasMoreContent = true formula: changed from items.length * currentPage to limit * (currentPage + 1) so PrimeNG's next-page button is reliably enabled regardless of partial page sizes
  • Extract DotContentDrivePaginateEvent type: moved LazyLoadEvent & { page: number } into @dotcms/dotcms-models and used it across the paginate output in DotFolderListViewComponent and the onPaginate handler in the shell component
  • Add ES2022 lib to portlet tsconfig: scoped to dot-content-drive portlet only to enable Array.prototype.at() without a workspace-wide change

Test plan

  • Navigate to Content Drive, verify pagination numbers are correct on each page
  • Verify "next page" button is enabled when hasMoreContent = true
  • Verify "next page" button is disabled on the last page (hasMoreContent = false)
  • Verify page resets to 1 when changing path, filters, or rows-per-page
  • Verify no TypeScript errors on paginate output / onPaginate handler

🤖 Generated with Claude Code

This PR fixes: #34354

This PR fixes: #34354

- Fix off-by-one bug in \$totalItems: pagination.page is already 1-indexed,
  removing the erroneous +1 and the trailing -1 from the formula
- When hasMoreContent is true, use limit*(page+1) to reliably enable PrimeNG
  next-page button regardless of partial page sizes
- Extract LazyLoadEvent & { page: number } into DotContentDrivePaginateEvent
  in @dotcms/dotcms-models and use it across the paginate output and handler
- Add ES2022 lib to dot-content-drive portlet tsconfig to allow Array.at()

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@zJaaal zJaaal linked an issue Mar 6, 2026 that may be closed by this pull request
@github-actions github-actions Bot added the Area : Frontend PR changes Angular/TypeScript frontend code label Mar 6, 2026
- Shell spec: replace totalItems mock with pages mock, update onPaginate
  assertions to include page field, add $totalItems computed test suite
  covering hasMoreContent true/false and multi-page scenarios
- Store spec: update all setPagination calls to include required page
  field, fix $request assertions to use contentCursor/folderCursor instead
  of offset, remove obsolete totalItems assertion
- List view spec: update onPage emit assertions to include resolved page
  number, add onPage page number calculation test suite, update paginator
  visibility test to reflect always-on paginator

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@dario-daza dario-daza left a comment

Choose a reason for hiding this comment

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

Plus a couple of questions:

  • How are you handling previous pages navigation?
  • Could you add a test for a user with restricted content access?

@zJaaal zJaaal requested a review from dario-daza March 6, 2026 18:39
@zJaaal zJaaal enabled auto-merge March 6, 2026 18:50
@zJaaal zJaaal added this pull request to the merge queue Mar 6, 2026
Merged via the queue into main with commit 4c8dbfe Mar 6, 2026
24 checks passed
@zJaaal zJaaal deleted the 34354-defect-content-drive-search-leaks-info-with-limited-user-frontend branch March 6, 2026 21:15
spbolton pushed a commit that referenced this pull request Mar 24, 2026
#34890)

## Summary

- **Fix off-by-one in `$totalItems`**: `pagination.page` is already
1-indexed — removed the erroneous `+ 1` (and the trailing `- 1`) that
inflated the total by a full page on every page
- **Correct `hasMoreContent = true` formula**: changed from
`items.length * currentPage` to `limit * (currentPage + 1)` so PrimeNG's
next-page button is reliably enabled regardless of partial page sizes
- **Extract `DotContentDrivePaginateEvent` type**: moved `LazyLoadEvent
& { page: number }` into `@dotcms/dotcms-models` and used it across the
`paginate` output in `DotFolderListViewComponent` and the `onPaginate`
handler in the shell component
- **Add ES2022 lib to portlet tsconfig**: scoped to `dot-content-drive`
portlet only to enable `Array.prototype.at()` without a workspace-wide
change

## Test plan

- [ ] Navigate to Content Drive, verify pagination numbers are correct
on each page
- [ ] Verify "next page" button is enabled when `hasMoreContent = true`
- [ ] Verify "next page" button is disabled on the last page
(`hasMoreContent = false`)
- [ ] Verify page resets to 1 when changing path, filters, or
rows-per-page
- [ ] Verify no TypeScript errors on `paginate` output / `onPaginate`
handler

🤖 Generated with [Claude Code](https://claude.com/claude-code)

This PR fixes: #34354

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area : Frontend PR changes Angular/TypeScript frontend code

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[DEFECT] Content Drive Search leaks info with limited user

3 participants