Skip to content

fix(approvals): populate Account/Payment/MonthlyCost on Approval queue rows (closes #733) - #734

Merged
cristim merged 1 commit into
feat/multicloud-web-frontendfrom
fix/issue-713-approval-queue-empty-columns
May 27, 2026
Merged

cristim merged 1 commit into
feat/multicloud-web-frontendfrom
fix/issue-713-approval-queue-empty-columns

Conversation

@cristim

@cristim cristim commented May 26, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #733. PR #713 added the Account, Term, Payment, and Monthly Cost columns to the Approval queue card, but every row rendered "-" because the backend never copied those fields onto synthesised pending rows. This patches the data-plumbing gap in handler_history.go and pins the contract with regression tests on both sides.

Backend fix (internal/api/handler_history.go)

Field Gap Fix
Account executionToHistoryRow read exec.CloudAccountID, but the web bulk-purchase flow's buildPendingExecution only populates the per-rec CloudAccountID and leaves the exec-level field nil. Fall back to a new collapseRecommendationAccount helper — returns the shared rec value, or "" (renders as "-") for a basket genuinely spanning accounts.
Payment projectRecommendationFields never set row.Payment in either branch. Single-rec: row.Payment = r.Payment. Multi-rec: collapseRecommendationPayment(recs) — same shape as the existing Provider/Service/Term collapsers; returns "" on disagreement so the dash fallback stays honest.
MonthlyCost (multi-rec) Only the single-rec branch mapped it. sumRecommendationMonthlyCost(recs) — nil entries contribute 0, matching the single-rec treatment of nil MonthlyCost.

Regression coverage

  • TestHandler_getHistory_ApprovalQueueColumnsPopulated (new) pins all three shapes: single-rec passes Account/Payment/MonthlyCost from rec; multi-rec uniform collapses Account+Payment and sums MonthlyCost; multi-rec heterogeneous Payment collapses to "" so the UI honestly shows "-".
  • TestHandler_getHistory_InProgressRowMapsRecFields extended with a Payment assertion.
  • history-approval-queue.test.ts adds an end-to-end frontend test that mocks the populated API shape and asserts the cells render real values (no -).

Test plan

  • go build ./... clean
  • go test ./internal/api/... -count=1 — 1277 passed
  • go test -run TestHandler_getHistory_ApprovalQueueColumnsPopulated -v — 3/3 sub-tests pass
  • npm test -- --testPathPattern=history-approval-queue — 14/14 pass (new test included)
  • Manual smoke once deployed: trigger a bulk purchase from the web UI, confirm the Approval queue row shows the real Account ID, Payment, and Monthly Cost (not "-").

Summary by CodeRabbit

  • Bug Fixes
    • Fixed Approval Queue to display actual account information, payment terms, and monthly costs instead of placeholder dashes.
    • Improved data handling for approval queue rows across different execution scenarios.

Review Change Stack

…e rows (closes #733)

PR #713 added the Account, Term, Payment, and Monthly Cost columns to
the Approval queue card; the columns render but every row showed "-"
because the backend never copied those fields onto the synthesised
PurchaseHistoryRecord:

- Account: executionToHistoryRow read exec.CloudAccountID, but the
  web-initiated bulk-purchase flow (buildPendingExecution) only
  populates the per-recommendation CloudAccountID and leaves the
  execution-level field nil. Fall back to a new
  collapseRecommendationAccount helper that returns the shared rec
  CloudAccountID, or "" (rendered as "-") for a basket genuinely
  spanning accounts.
- Payment: projectRecommendationFields populated Service, ResourceType,
  Region, Term, UpfrontCost, EstimatedSavings, and (single-rec only)
  MonthlyCost from the rec, but never set row.Payment. Single-rec now
  copies r.Payment; multi-rec collapses via collapseRecommendationPayment
  (same pattern as the existing Provider/Service/Term collapsers),
  returning "" when recs disagree so the dash fallback stays honest.
- MonthlyCost (multi-rec): only the single-rec branch mapped it; the
  multi-rec branch now sums per-rec MonthlyCost via
  sumRecommendationMonthlyCost (nil contributes 0, matching the
  single-rec treatment of nil MonthlyCost).

Regression tests:
- TestHandler_getHistory_ApprovalQueueColumnsPopulated pins all three
  shapes (single-rec, multi-rec uniform, multi-rec heterogeneous
  Payment) so a future refactor cannot silently re-empty the cells.
- TestHandler_getHistory_InProgressRowMapsRecFields extended with a
  Payment assertion.
- history-approval-queue.test.ts adds a frontend test that mocks the
  populated API shape and asserts the cells show real values, not "-".
@coderabbitai

coderabbitai Bot commented May 26, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f0a30bbc-84c2-4ea9-8588-dc6ccf94d0d1

📥 Commits

Reviewing files that changed from the base of the PR and between 1200e08 and b2b9328.

📒 Files selected for processing (3)
  • frontend/src/__tests__/history-approval-queue.test.ts
  • internal/api/handler_history.go
  • internal/api/handler_history_test.go

📝 Walkthrough

Walkthrough

This PR resolves issue #733 by implementing backend field population and regression tests. The backend now copies AccountID (falling back to per-recommendation values), Payment, and MonthlyCost from recommendation records onto synthesized approval-queue history rows. Backend tests validate single-rec and multi-rec field mapping and collapse behavior. A frontend regression test confirms the Approval Queue displays real backend values instead of dash fallbacks.

Changes

Approval Queue field population

Layer / File(s) Summary
Backend field population logic
internal/api/handler_history.go
executionToHistoryRow computes AccountID from per-rec CloudAccountID when exec.CloudAccountID is nil, collapsing to "" on disagreement. projectRecommendationFields populates Payment (single-rec copy or multi-rec collapse) and MonthlyCost (per-rec or summed) alongside existing fields. New helpers collapse Payment/CloudAccountID across recommendations and sum MonthlyCost.
Backend test coverage
internal/api/handler_history_test.go
Extended in-progress row test asserts Payment field mapping; new TestHandler_getHistory_ApprovalQueueColumnsPopulated validates single-rec field copy, multi-rec uniform collapse, and heterogeneous Payment collapse-to-empty behavior.
Frontend Approval Queue regression test
frontend/src/__tests__/history-approval-queue.test.ts
Jest test mocks getHistory with populated fields (account_id, term, payment, monthly_cost) and asserts Approval Queue table cells display real values instead of dash fallbacks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • #704: Touches executionToHistoryRow and the same history/approval field group (account_id, payment, monthly_cost), suggesting related field-population or data-plumbing work.

Possibly related PRs

  • LeanerCloud/CUDly#387: Both PRs modify the approval-queue test suite in frontend/src/__tests__/history-approval-queue.test.ts to cover Approval Queue data rendering; PR #387 introduced the initial test structure while this PR adds regression coverage for real backend-provided field values.

Suggested labels

priority/p2, urgency/this-quarter, impact/all-users, effort/m

Poem

🐰 The Approval Queue hops with glee,
No more dashes, real data to see!
AccountID, Payment, and Cost align,
Per-rec collapsed, or single-line fine—
The basket's transparent, authentic, and true!

🚥 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 summarizes the main change: populating Account/Payment/MonthlyCost on Approval queue rows and clearly references the linked issue #733.
Linked Issues check ✅ Passed All objectives from #733 are met: Account/Payment/MonthlyCost fields are populated for single and multi-rec rows with collapse helpers, honest UI behavior preserved, and regression tests added.
Out of Scope Changes check ✅ Passed All changes directly address the backend data gap in #733: new helper functions, field mapping in executionToHistoryRow/projectRecommendationFields, and regression tests align with stated objectives.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/issue-713-approval-queue-empty-columns

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

@cristim cristim added triaged Item has been triaged priority/p1 Next up; this sprint severity/medium Moderate harm urgency/this-sprint Within the current sprint impact/many Affects most users effort/s Hours type/bug Defect labels May 26, 2026
@cristim

cristim commented May 26, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 26, 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/p1 Next up; this sprint 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