Skip to content

fix(can-funding): serialize pending actions to preserve history ordering#5631

Draft
johndeange wants to merge 6 commits intomainfrom
OPS-5571/history-ordering-ui-fixes
Draft

fix(can-funding): serialize pending actions to preserve history ordering#5631
johndeange wants to merge 6 commits intomainfrom
OPS-5571/history-ordering-ui-fixes

Conversation

@johndeange
Copy link
Copy Markdown
Contributor

@johndeange johndeange commented May 5, 2026

What changed

Replaces the parallel Promise.allSettled save strategy in CanFunding.hooks.js with a sequential pendingActions queue that dispatches mutations in the exact order the user took them in the UI. This fixes issue #5571, where budget and funding-received mutations raced on the client, causing the backend to record history events in non-deterministic order.

frontend/src/pages/cans/detail/CanFunding.hooks.js

  • Added PendingAction type and exported mergePendingAction utility that collapses redundant queue entries (e.g., repeated budget edits, edit-then-delete of a staged row)
  • Added pendingActions state; handleAddBudget, handleAddFundingReceived, and deleteFundingReceived now enqueue typed actions
  • Rewrote saveChanges to iterate the queue sequentially with a for...of / switch dispatch, preserving user-intended ordering

frontend/src/pages/cans/detail/CanFunding.hooks.test.js

  • Fixed mock setup to use .unwrap() pattern matching the new sequential calls
  • Added tests: mutation call ordering, queue collapsing for repeated edits, and staged add+delete cancellation

frontend/cypress/e2e/canFundingHistoryOrdering.cy.js (new)

  • E2E regression test: enters FY Budget then Funding Received, saves, and asserts the history panel shows them in correct newest-first order

frontend/cypress.config.js / cypress.config.ci.js

  • Registered the new E2E spec in the ordered spec lists

Issue

#5571

How to test

Unit tests:

cd frontend && bun run test -- --watch=false src/pages/cans/detail/CanFunding.hooks.test.js

E2E test (requires Docker stack running):

cd frontend && bun run test:e2e -- --spec cypress/e2e/canFundingHistoryOrdering.cy.js

Manual verification:

  1. Log in as a budget-team user
  2. Navigate to a CAN's Funding tab for the current fiscal year
  3. Click Edit, enter an FY Budget amount, click "Add FY Budget"
  4. Enter a Funding Received amount + notes, click "Add Funding Received"
  5. Click Save — observe network tab shows budget request completing before received request fires
  6. Navigate to the CAN's history panel — "Funding Received Added" should appear above the FY Budget entry

A11y impact

  • No accessibility-impacting changes in this PR

Screenshots

N/A — no visual changes; behavior fix only affects mutation ordering and history display sequence.

Definition of Done Checklist

  • OESA: Code refactored for clarity
  • Automated unit tests updated and passed
  • Automated integration tests updated and passed
  • Automated quality tests updated and passed
  • Automated load tests updated and passed
  • Automated a11y tests updated and passed
  • Automated security tests updated and passed
  • 90%+ Code coverage achieved
  • Form validations updated

Links

N/A

@johndeange johndeange self-assigned this May 5, 2026
johndeange and others added 2 commits May 5, 2026 19:44
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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