Skip to content

fix(planned-purchases): Edit button uses plan_id, not purchase id - #780

Merged
cristim merged 2 commits into
feat/multicloud-web-frontendfrom
fix/773-edit-plan-details-load
May 28, 2026
Merged

cristim merged 2 commits into
feat/multicloud-web-frontendfrom
fix/773-edit-plan-details-load

Conversation

@cristim

@cristim cristim commented May 27, 2026 •

Copy link
Copy Markdown
Member

Summary

QA Planned 6.2: clicking "Edit" next to a scheduled purchase immediately showed "Failed to load plan details".

Root cause

In renderPlannedPurchaseRow, the Edit button was rendered with data-id="${purchase.id}" -- the purchase's own primary key. The listener called handlePlannedPurchaseAction(action, btn.dataset['id']), which passed it to editPlan(purchaseId). editPlan then called GET /plans/<id> with a purchase ID instead of a plan ID, getting a 404 every time.

Fix

  • Added data-plan-id="${purchase.plan_id}" to the Edit button.
  • Listener now passes btn.dataset['planId'] as a third argument.
  • handlePlannedPurchaseAction(action, purchaseId, planId) -- edit case calls editPlan(planId).

Files changed

  • frontend/src/plans.ts
  • frontend/src/__tests__/plans.test.ts

Test plan

  • New regression test: 'edit action calls getPlan with plan_id, not the purchase id (#773)'.
  • 2085 tests pass (64 suites).
  • Manual: click Edit on a scheduled purchase, confirm modal opens with the parent plan loaded.

Note on design ambiguity

Edit currently scopes to the whole plan (not just this execution). The original QA note flagged this as worth deciding -- documented but not changed here. Will follow up separately.

Closes #773.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed the "Edit Plan" action on planned purchase rows to correctly load parent plan details, resolving previous failures.
  • Tests

    • Added test case for the "Edit Plan" action to verify correct plan details are retrieved without errors.

Review Change Stack

The Edit button on a scheduled-purchase row surfaced "Failed to load
plan details" because handlePlannedPurchaseAction passed the purchase's
own id to editPlan, which then called GET /plans/<purchase-id> and got
a 404. Fixed by adding a data-plan-id attribute to the Edit button and
passing it as a third argument through the handler to editPlan, so the
correct GET /plans/<plan-id> call is made.

Closes #773.
@cristim cristim added triaged Item has been triaged priority/p2 Backlog-worthy severity/medium Moderate harm urgency/this-sprint Within the current sprint impact/many Affects most users effort/s Hours type/bug Defect labels May 27, 2026
@coderabbitai

coderabbitai Bot commented May 27, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@cristim, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 13 minutes and 12 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: eb72de1b-4890-4e7b-bd32-9b37505c3869

📥 Commits

Reviewing files that changed from the base of the PR and between eb70c29 and 4a44f1e.

📒 Files selected for processing (2)
  • frontend/src/__tests__/plans.test.ts
  • frontend/src/plans.ts
📝 Walkthrough

Walkthrough

The PR fixes a bug where editing a planned purchase failed with "Failed to load plan details." The fix updates the Edit Plan button to capture and pass the parent plan's ID through the action handler instead of using the purchase row's ID, then calls editPlan() with the correct plan ID.

Changes

Planned Purchase Edit Action

Layer / File(s) Summary
Edit button markup and action wiring
frontend/src/plans.ts
The Edit Plan button now includes data-plan-id from purchase.plan_id. The click handler extracts this attribute and passes it to handlePlannedPurchaseAction as a third argument.
Edit action handler implementation
frontend/src/plans.ts
handlePlannedPurchaseAction signature is updated to accept optional planId parameter. The edit action branch now calls editPlan(planId) with the parent plan ID instead of the purchase row ID.
Edit action regression test
frontend/src/__tests__/plans.test.ts
New test verifies the edit action calls api.getPlan with plan_id (not purchase ID) and asserts the "Failed to load plan details" error does not occur.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A button's data-plan-id now tells the tale,
Threading parent plans where purchases fail,
No more "load" errors—the fix is so neat,
Edit the right plan, the journey's complete!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR addresses the bug fix requirement from #773 by changing the Edit button to use plan_id instead of purchase id and updating the handler accordingly. However, no backend test was added as required by #773 acceptance criteria. Add a backend test for the failing endpoint case as specified in issue #773 acceptance criteria (V1).
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main fix: using plan_id instead of purchase id for the Edit button in planned purchases.
Out of Scope Changes check ✅ Passed All changes in the PR are directly related to fixing the planned purchase Edit button bug identified in #773. No out-of-scope changes detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/773-edit-plan-details-load

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

@cristim

cristim commented May 27, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@cristim

cristim commented May 28, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Full review triggered.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
frontend/src/plans.ts (1)

225-225: ⚡ Quick win

Consider validating planId is non-empty in the edit action.

The default value planId = '' could lead to a malformed API call if the data-plan-id attribute is missing or empty. Although the current markup at line 201 always sets it, adding a guard in the edit case (lines 240-244) would make the code more defensive.

🛡️ Proposed validation guard
 case 'edit':
+  if (!planId) {
+    showToast({ message: 'Failed to load plan: missing plan ID', kind: 'error' });
+    return;
+  }
   // Open edit modal for the parent plan using plan_id, not the purchase id.
   // The purchase row's data-plan-id attribute carries the plan FK (`#773`).
   await editPlan(planId);
   return;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/src/plans.ts` at line 225, The edit branch in
handlePlannedPurchaseAction currently assumes planId (parameter planId) is
present which can produce malformed API calls if data-plan-id is missing; add a
defensive guard in the edit branch (where action === 'edit') that checks if
planId is truthy and, if not, aborts early and surfaces an error (e.g., show a
user toast/console.error and return) before performing any API call using
purchaseId/planId so callers cannot send empty plan IDs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@frontend/src/plans.ts`:
- Line 225: The edit branch in handlePlannedPurchaseAction currently assumes
planId (parameter planId) is present which can produce malformed API calls if
data-plan-id is missing; add a defensive guard in the edit branch (where action
=== 'edit') that checks if planId is truthy and, if not, aborts early and
surfaces an error (e.g., show a user toast/console.error and return) before
performing any API call using purchaseId/planId so callers cannot send empty
plan IDs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 947c95ba-0631-4dab-bf21-2f0e84732278

📥 Commits

Reviewing files that changed from the base of the PR and between d986b4d and eb70c29.

📒 Files selected for processing (2)
  • frontend/src/__tests__/plans.test.ts
  • frontend/src/plans.ts

Add an early-return guard in the edit case of handlePlannedPurchaseAction
so that a missing or empty data-plan-id attribute produces a console.warn
and a no-op instead of forwarding an empty string to editPlan / the API.

Covers the defensive path with a focused unit test.
@cristim

cristim commented May 28, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/s Hours impact/many Affects most users priority/p2 Backlog-worthy severity/medium Moderate harm triaged Item has been triaged type/bug Defect urgency/this-sprint Within the current sprint

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant