Skip to content

fix(opportunities): prefill Create Purchase Plan modal from selected commitment - #778

Merged
cristim merged 2 commits into
feat/multicloud-web-frontendfrom
fix/770-prefill-plan-modal
May 28, 2026
Merged

cristim merged 2 commits into
feat/multicloud-web-frontendfrom
fix/770-prefill-plan-modal

Conversation

@cristim

@cristim cristim commented May 27, 2026 •

Copy link
Copy Markdown
Member

Summary

QA 6.5: Selecting one commitment in the Opportunities table and clicking "Plan from 1 selected" opened the Create Purchase Plan modal with default values. Now the modal's Purchase Configuration section is prefilled from the selected commitment.

Fix

Added prefillPurchaseConfigFromCommitment and prefillAccountChipFromId helpers. openCreatePlanModal calls both when snapshot.length === 1. Prefill is skipped for multi-commitment snapshots; all fields remain editable after prefill.

Fields prefilled

  • Provider (aws / azure / gcp) -- set on the provider select.
  • Service (ec2 / rds / compute / etc.) -- set on the service select.
  • Term (1 / 3) -- populateTermSelect called first, then value set.
  • Payment (e.g. partial-upfront) -- normalizePaymentValue applied, populatePaymentSelect called first.
  • Account -- looked up via api.getAccount(cloud_account_id) and added as a chip; silently skipped on failure or missing ID.

Files changed

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

Test plan

  • 7 new regression tests under prefill from single selected commitment (#770).
  • 105 tests pass.

Closes #770.

Summary by CodeRabbit

  • New Features
    • Create Purchase Plan modal now automatically prefills purchase configuration details (provider, service, term, payment) when a single commitment is selected.
    • Account information is automatically fetched and populated based on the selected commitment, reducing manual data entry.

Review Change Stack

…commitment (closes #770)

When exactly 1 commitment is selected and "Plan from 1 selected" is clicked,
openCreatePlanModal now calls prefillPurchaseConfigFromCommitment to set the
provider, service, term, and payment selects from the commitment record.
If the commitment carries a cloud_account_id, prefillAccountChipFromId fetches
the account via api.getAccount and adds it as a pre-selected chip so the Target
Accounts field is also prefilled. All prefilled fields remain editable.

Missing/null fields are handled gracefully (field is left at its reset default).
Prefill is skipped when snapshot.length != 1 (multi-commitment plans require
manual configuration). Account lookup failure silently no-ops so the user can
still search and add the account manually.
@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 11 minutes and 53 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: dbbbe449-10b6-4e0b-a148-88a8b001077a

📥 Commits

Reviewing files that changed from the base of the PR and between c4e834b and 220f53e.

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

Walkthrough

This PR implements prefilling of the "Create Purchase Plan" modal's purchase configuration and account fields when exactly one commitment is selected. Two new helper functions populate provider/service/term/payment dropdowns synchronously and fetch and add account chips asynchronously. openCreatePlanModal conditionally invokes these helpers only when a single recommendation is present, with comprehensive test coverage validating form population and error handling.

Changes

Create Purchase Plan Modal Prefill

Layer / File(s) Summary
Prefill helper functions
frontend/src/plans.ts
prefillPurchaseConfigFromCommitment extracts provider, service, term, and payment values from a single recommendation and applies them to the modal's dropdown fields using term/payment option populators and payment value normalization. prefillAccountChipFromId asynchronously fetches an account by internal UUID and appends it to the pre-selected accounts list, deduplicating and silently ignoring lookup failures.
Modal prefill integration
frontend/src/plans.ts
openCreatePlanModal now checks whether exactly one recommendation is in the pending snapshot: if true, it synchronously prefills the purchase configuration via prefillPurchaseConfigFromCommitment, and if the recommendation includes a cloud_account_id, it asynchronously calls prefillAccountChipFromId to populate the account chip. The form and account section are reset before prefill as before.
Test mocks and validation
frontend/src/__tests__/plans.test.ts
Jest mock of ../api extended with listAccounts and getAccount stubs. New test suite validates prefill behavior for the single-commitment path: DOM selects receive prepopulated values, term/payment option populators are called, account lookup populates the chip, failures are handled gracefully, and prefill is skipped for multi-commitment snapshots.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

impact/few, effort/m

🐰 When one commitment's chosen with care,
The form fills itself—answers already there!
Provider, service, term, and payment too,
Account chip added—no work left to do.
hops contentedly ✨

🚥 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 accurately and concisely describes the main change: prefilling the Create Purchase Plan modal from a selected commitment, which is the primary objective of this PR.
Linked Issues check ✅ Passed The PR implements all coding requirements from #770: prefills provider/service/account/term/payment from the selected commitment, allows user editing, and adds regression tests.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing prefill functionality for the Create Purchase Plan modal as specified in #770; no unrelated modifications 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/770-prefill-plan-modal

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: 1

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

1356-1366: ⚡ Quick win

Strengthen the multi-commitment no-prefill regression assertion.

Line 1356 currently verifies only that getAccount is not called. It doesn’t assert that provider/service/term/payment were left unchanged. Add explicit field assertions so this test actually guards “no prefill” behavior.

🤖 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/__tests__/plans.test.ts` around lines 1356 - 1366, The test
'does not prefill when snapshot has more than one commitment' currently only
asserts api.getAccount was not called; update it to explicitly assert that
provider, service, term and payment fields were left unchanged after
openCreatePlanModal([fixture, second]) — i.e., verify the provider/service
select value is still the initial/default (not forced to fixture.service 'ec2'),
the term select was not changed by prefillPurchaseConfigFromCommitment, and the
payment/method field remains the original/default; locate the test and add
assertions referencing openCreatePlanModal,
populateTermSelect/updateCommitmentOptions/prefillPurchaseConfigFromCommitment
flow and the fixture/second recommendations to confirm no fields were
overwritten.
🤖 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.

Inline comments:
In `@frontend/src/plans.ts`:
- Around line 862-871: The async prefillAccountChipFromId function can mutate
planSelectedAccounts after a modal has been closed and reopened, so add a
session check to ignore stale responses: introduce a short-lived session
token/counter checked both when starting the async fetch and before mutating
state, or accept a sessionId parameter from the callers that open the modal (the
callers that launch the prefill should pass the current modal/session id); in
prefillAccountChipFromId verify the returned account's sessionId matches the
current session before pushing to planSelectedAccounts and calling
renderPlanAccountChips() and updatePlanAccountIdsField() so stale promises
cannot affect a new modal session.

---

Nitpick comments:
In `@frontend/src/__tests__/plans.test.ts`:
- Around line 1356-1366: The test 'does not prefill when snapshot has more than
one commitment' currently only asserts api.getAccount was not called; update it
to explicitly assert that provider, service, term and payment fields were left
unchanged after openCreatePlanModal([fixture, second]) — i.e., verify the
provider/service select value is still the initial/default (not forced to
fixture.service 'ec2'), the term select was not changed by
prefillPurchaseConfigFromCommitment, and the payment/method field remains the
original/default; locate the test and add assertions referencing
openCreatePlanModal,
populateTermSelect/updateCommitmentOptions/prefillPurchaseConfigFromCommitment
flow and the fixture/second recommendations to confirm no fields were
overwritten.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 424523bc-ac9a-4021-96b6-f262dc219287

📥 Commits

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

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

Comment thread frontend/src/plans.ts Outdated
…e resolution

Introduce a module-level planModalSession counter that is incremented each
time openCreatePlanModal opens (stamping a new session). prefillAccountChipFromId
now accepts the session value captured at call time and silently discards the
api.getAccount result if the counter has advanced (i.e. the modal was closed
and reopened while the promise was in-flight), preventing wrong-modal pollution
of planSelectedAccounts. Addresses #770 CR Major finding.

Add a focused regression test: open modal, issue slow getAccount, close, reopen,
resolve the stale promise, assert no chip was added to the new session.
@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.

@cristim
cristim merged commit 5f3923d into feat/multicloud-web-frontend May 28, 2026
5 checks passed
@cristim
cristim deleted the fix/770-prefill-plan-modal branch May 28, 2026 12:54
cristim added a commit that referenced this pull request Jun 1, 2026
…homogeneous commitments (closes #898) (#899)

When 2+ commitments sharing the same provider/service/term/payment are
selected and the user clicks "Plan from N selected", the Create Purchase
Plan modal now prefills the Purchase Configuration from the shared values
instead of showing defaults. The "Plan from N selected" button only
enables on a homogeneous selection, so the first commitment is a valid
representative.

The account chip is prefilled only when every selected commitment carries
the same cloud_account_id; a multi-account selection leaves it empty for
the user to fill, since provider/service/term/payment homogeneity does not
imply a single account.

Extends the single-selection prefill from #770/#778 (QA finding 6.7).
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