fix: send order line_id instead of item type id when cancelling a sponsor order line - #312
Conversation
…nsor order line
mapOrderData() built each SponsorOrderGrid row's id from it.type?.id,
so onCancelForm/onUndoCancelForm handed consumers the item type id
instead of the order line's real identifier (it.line_id). Consumers
that forward row.id straight into a cancel API call (e.g.
summit-admin's cancelSponsorForm/undoCancelSponsorForm) ended up
cancelling by the wrong id.
Use it.line_id as the row identity, falling back to `${form.id}-${i}`
only when line_id is absent. This also fixes a latent collision: two
rows sharing the same item type across different forms previously
produced duplicate React keys and duplicate #item-<id> DOM anchors.
📝 WalkthroughWalkthrough
ChangesSponsorOrderGrid order-line identity
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Pull request overview
Fixes SponsorOrderGrid row identity so cancel/undo actions send the order line’s line_id (instead of the item type id), preventing incorrect cancellations and eliminating duplicate React keys / DOM anchors when multiple forms contain the same item type.
Changes:
- Update
mapOrderData()to set each rowidfromit.line_id(with a safe fallback when missing). - Extend
SponsorOrderGridtests to assertonCancelForm/onUndoCancelFormreceive the correctline_id. - Add a regression test ensuring rows across different forms with the same item type produce distinct DOM anchors.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/components/mui/SponsorOrderGrid/index.js | Switch row identity to line_id so callbacks and DOM anchors use the correct per-line identifier. |
| src/components/mui/SponsorOrderGrid/tests/SponsorOrderGrid.test.js | Add regression tests validating cancel/undo payload id and uniqueness across forms. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
ref: https://app.clickup.com/t/9014802374/86bbb0y4r
Bug
Cancelling (or undoing a cancel of) a line item in
SponsorOrderGrid's action column sends the wrong identifier to the consumer's cancel API call. For order 49, clicking Delete on theSJC-EL02row triggered a cancel request for id146instead of841—146is the item type id,841is the order line's realline_id.Root cause
src/components/mui/SponsorOrderGrid/index.js:48—mapOrderData()built each row's identity asit.type?.id || \${form.id}-${i}`and assigned it toid. The order line's real identifier,it.line_id, was never read. The row object (including thisid) is what gets passed toonCancelForm/onUndoCancelForm, so any consumer forwardingrow.idinto a cancel call (e.g. summit-admin'scancelSponsorForm/undoCancelSponsorForm`) ends up acting on the wrong line.Fix
One-line change: use
it.line_id, falling back to\${form.id}-${i}`only whenline_idis absent.idkeeps its existing three roles (React key,#item-` anchor, callback payload) — only its source changes.This also fixes a latent second defect: two rows sharing the same item type across different forms of one order previously produced duplicate React keys and duplicate
#item-<id>DOM anchors.line_idis unique per order line, so the collision is gone too.Matches the existing precedent in
src/components/order-invoice-pdf/helpers.js:93, which already treatsline_idas the row identity.Blast radius
Checked every
SponsorOrderGridconsumer across thefntechrepos. Onlysummit-admin's sponsor purchases order-detail page passesonCancelForm/onUndoCancelFormand is affected by the bug. The four other consumers (summit-admin's sponsor cart tab, and three sponsor-services cart/order views) render the grid read-only and never observerow.id; none of them will change behavior. No consumer deep-links to#item-<id>from outside the grid.Downstream, summit-admin needs no code change — bumping this package once released is enough to fix the ticket. Verified the fixed
mapOrderDatalogic against the real order-49 payload from the bug report:SJC-EL02now yields id841.Testing
SponsorOrderGrid.test.js(no new test file): assertsonCancelForm/onUndoCancelFormreceiveline_id, and that two rows sharing an item type across forms get distinct ids.id: 146, expected841).yarn test— 879/879 passing.yarn build— succeeds.🤖 Generated with Claude Code
Summary by CodeRabbit