Skip to content

fix: reload table after archive/unarchive rows#938

Open
tomrndom wants to merge 2 commits into
masterfrom
fix/reload-table-on-archive
Open

fix: reload table after archive/unarchive rows#938
tomrndom wants to merge 2 commits into
masterfrom
fix/reload-table-on-archive

Conversation

@tomrndom
Copy link
Copy Markdown

@tomrndom tomrndom commented May 14, 2026

ref: https://app.clickup.com/t/86b7v230m

Signed-off-by: Tomás Castillo tcastilloboireau@gmail.com

Summary by CodeRabbit

  • Bug Fixes
    • Improved pagination handling when archiving or unarchiving items across forms, templates, pages, and inventory lists. The system now correctly adjusts to a valid page instead of potentially displaying empty pages after removing items.

Review Change Stack

tomrndom added 2 commits May 14, 2026 16:44
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5f13da35-55b8-4bd1-82de-20264e720c89

📥 Commits

Reviewing files that changed from the base of the PR and between 81351ea and 9484135.

📒 Files selected for processing (11)
  • src/pages/sponsors-global/form-templates/form-template-item-list-page.js
  • src/pages/sponsors-global/form-templates/form-template-list-page.js
  • src/pages/sponsors-global/inventory/inventory-list-page.js
  • src/pages/sponsors-global/page-templates/page-template-list-page.js
  • src/pages/sponsors/show-pages-list-page/index.js
  • src/pages/sponsors/sponsor-form-item-list-page/index.js
  • src/pages/sponsors/sponsor-forms-list-page/index.js
  • src/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/components/manage-items/sponsor-forms-manage-items.js
  • src/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/index.js
  • src/pages/sponsors/sponsor-page/tabs/sponsor-pages-tab/index.js
  • src/utils/methods.js

📝 Walkthrough

Walkthrough

This PR introduces a utility function to safely recalculate pagination page numbers after archiving or unarchiving list items, then applies it consistently across nine different page and tab components. The change prevents users from being left on invalid empty pages after removing items from the current view.

Changes

Safe Pagination After Archive/Unarchive

Layer / File(s) Summary
Safe page calculation utility
src/utils/methods.js
getSafePageAfterRemove(totalCount, perPage, currentPage) computes the maximum valid page after removing one item using Math.ceil((totalCount - 1) / perPage), enforces a minimum of page 1, and returns the smaller of the current page or that computed maximum.
Global sponsors archive handlers
src/pages/sponsors-global/form-templates/form-template-item-list-page.js, src/pages/sponsors-global/form-templates/form-template-list-page.js, src/pages/sponsors-global/inventory/inventory-list-page.js, src/pages/sponsors-global/page-templates/page-template-list-page.js
Each archive/unarchive handler now imports getSafePageAfterRemove, computes a safe page after the mutation resolves, and reloads the list using that adjusted page instead of the current page.
Individual sponsor pages archive handlers
src/pages/sponsors/show-pages-list-page/index.js, src/pages/sponsors/sponsor-forms-list-page/index.js, src/pages/sponsors/sponsor-form-item-list-page/index.js, src/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/index.js, src/pages/sponsors/sponsor-page/tabs/sponsor-pages-tab/index.js, src/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/components/manage-items/sponsor-forms-manage-items.js
Each archive/unarchive handler imports getSafePageAfterRemove, chains a .then() or wraps the reload logic to compute the safe page from total items, per-page count, and current page, then reloads with the adjusted page.

Sequence Diagram

sequenceDiagram
  participant User
  participant ListComponent
  participant ArchiveAPI
  participant getSafePageAfterRemove
  participant ReloadAPI
  
  User->>ListComponent: Click archive/unarchive item
  ListComponent->>ArchiveAPI: archiveItem() or unarchiveItem()
  ArchiveAPI-->>ListComponent: Promise resolves
  ListComponent->>getSafePageAfterRemove: Calculate safe page from (totalCount-1, perPage, currentPage)
  getSafePageAfterRemove-->>ListComponent: safePage (clamped to valid range)
  ListComponent->>ReloadAPI: fetchItems(page = safePage)
  ReloadAPI-->>ListComponent: Updated list
  ListComponent-->>User: Display updated list on valid page
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • fntechgit/summit-admin#778: Both PRs change src/pages/sponsors/sponsor-forms-tab/index.js to re-fetch the customized forms list after a mutation (main PR via getSafePageAfterRemove after archive/unarchive; retrieved PR by reloading after delete with pagination reset).
  • fntechgit/summit-admin#809: Both PRs change the sponsor pages tab's archive/unarchive flow and subsequent re-fetching of customized pages in src/pages/sponsors/sponsor-pages-tab/index.js (one adds the archive/unarchive Redux actions and dispatch, the other adjusts the page number after the mutation via getSafePageAfterRemove).
  • fntechgit/summit-admin#932: Both PRs modify the sponsor pages tab's post-archive/remove refresh of customized pages—main PR changes the pagination page via getSafePageAfterRemove, while the retrieved PR fixes the archived-filter argument passed.

Suggested reviewers

  • smarcet
  • martinquiroga-exo

Poem

🐰 When lists grow short and pages break,
A rabbit's math can always make
Safe bounds for pagination's stride—
No empty screens where items hide!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: reload table after archive/unarchive rows' accurately describes the main change: adding a utility function to compute safe pagination and applying it across multiple files when archiving/unarchiving items to prevent empty pages.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/reload-table-on-archive

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

@tomrndom tomrndom requested a review from smarcet May 14, 2026 20:49
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.

1 participant