Skip to content

fix: send order line_id instead of item type id when cancelling a sponsor order line - #312

Merged
smarcet merged 1 commit into
mainfrom
hotfix/sponsor-order-grid-cancel-item
Aug 10, 2026
Merged

fix: send order line_id instead of item type id when cancelling a sponsor order line#312
smarcet merged 1 commit into
mainfrom
hotfix/sponsor-order-grid-cancel-item

Conversation

@smarcet

@smarcet smarcet commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

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 the SJC-EL02 row triggered a cancel request for id 146 instead of 841146 is the item type id, 841 is the order line's real line_id.

Root cause

src/components/mui/SponsorOrderGrid/index.js:48mapOrderData() built each row's identity as it.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 this id) is what gets passed to onCancelForm/onUndoCancelForm, so any consumer forwarding row.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_id is 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 treats line_id as the row identity.

Blast radius

Checked every SponsorOrderGrid consumer across the fntech repos. Only summit-admin's sponsor purchases order-detail page passes onCancelForm/onUndoCancelForm and 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 observe row.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 mapOrderData logic against the real order-49 payload from the bug report: SJC-EL02 now yields id 841.

Testing

  • Added 3 tests to the existing SponsorOrderGrid.test.js (no new test file): asserts onCancelForm/onUndoCancelForm receive line_id, and that two rows sharing an item type across forms get distinct ids.
  • Confirmed the new tests are a genuine RED: reverted the one-line fix and reran — failed with the exact documented symptom (received id: 146, expected 841).
  • Full suite: yarn test — 879/879 passing.
  • Production build: yarn build — succeeds.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Order items are now uniquely identified by their specific order line, preventing collisions when the same item type appears across different forms.
    • Cancellation and undo actions now target the correct order line, improving reliability when managing orders.
    • Added fallback identification to maintain stable behavior for items without an order-line identifier.

…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.
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

SponsorOrderGrid now uses each order item's line_id for row identity. Tests verify line IDs in cancellation and undo callbacks and distinct DOM IDs for repeated item types across forms.

Changes

SponsorOrderGrid order-line identity

Layer / File(s) Summary
Use order-line IDs for grid rows and callbacks
src/components/mui/SponsorOrderGrid/index.js, src/components/mui/SponsorOrderGrid/__tests__/SponsorOrderGrid.test.js
mapOrderData now prefers line_id and retains the form/index fallback. Tests verify cancellation and undo callbacks receive the line ID, and rows with the same type across forms have distinct DOM IDs.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: santipalenque

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main fix: sending the order line ID instead of the item type ID during sponsor order line cancellation.
✨ 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 hotfix/sponsor-order-grid-cancel-item

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.

❤️ Share

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 row id from it.line_id (with a safe fallback when missing).
  • Extend SponsorOrderGrid tests to assert onCancelForm / onUndoCancelForm receive the correct line_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.

@smarcet
smarcet merged commit ee4e294 into main Aug 10, 2026
6 checks passed
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.

2 participants