feat(frontend/recs): default-seed payment/term from GlobalConfig (closes #223)#243
Conversation
#223) Three surfaces previously hardcoded `'all-upfront'` as the payment default regardless of operator configuration. All three now seed from the resolved `GlobalConfig.DefaultTerm + DefaultPayment`: 1. `loadRecommendations` adds `api.getConfig()` as a siloed third leg of the bootstrap `Promise.all` (failure is `.catch(() => null)` so a missing config endpoint cannot block rec load). Resolved values populate module-level `cachedGlobalDefaultTerm / Payment` vars. 2. `defaultBulkPurchaseState.payment` is mutated post-fetch so the bulk-toolbar first-visit fallback reflects the operator's setting. `loadBulkPurchaseState()` localStorage fallback also switched from the literal `'all-upfront'` to `cachedGlobalDefaultPayment`. 3. `resolvePerRecPaymentSeed` fallback now prefers `cachedGlobalDefaultPayment` when it is supported for the rec's (provider, service, term), falling back to `paymentOptionsFor[0]` only if the configured payment is unavailable for that combination. 4. `pickBestVariantPerCell` (select-all tiebreaker, added by #224) is replaced: it now prefers the variant matching `(cachedGlobalDefaultTerm, cachedGlobalDefaultPayment)` and falls back to highest-effective-savings only when no variant matches. Function is now exported for direct unit testing. `seedGlobalDefaults(term, payment)` exported for test injection. Four new unit tests cover the config-match tiebreaker and fallback.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR implements default-variant selection for recommendations based on GlobalConfig settings. The change fetches GlobalConfig on page load, caches the default term and payment, and uses those values to pre-select matching variants across the recommendation list, bulk purchase toolbar, and purchase modal, with fallback to the highest-effective variant when no config-matching option exists. ChangesGlobalConfig-Driven Default Variant Selection
Sequence DiagramsequenceDiagram
participant App as Page Load
participant API as API Layer
participant Cache as GlobalConfig Cache
participant Selector as Variant Selector
participant UI as UI Components
App->>API: loadRecommendations()
par
API->>API: getRecommendations()
API->>API: listAccounts()
API->>API: getConfig()
end
API->>Cache: Update cached defaults<br/>(term, payment)
API->>Selector: pickBestVariantPerCell(recs)
Selector->>Cache: Read cachedGlobalDefaultTerm<br/>cachedGlobalDefaultPayment
Selector->>Selector: Match variant per cell
alt Variant match found
Selector->>Selector: Select config-matching variant
else No match
Selector->>Selector: Fall back to highest-effective
end
Selector->>UI: Return pre-selected variants
par
API->>Cache: loadBulkPurchaseState() reads<br/>cachedGlobalDefaultPayment
API->>Cache: resolvePerRecPaymentSeed() reads<br/>cachedGlobalDefaultPayment
end
UI->>UI: Render with consistent defaults
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Review rate limit: 1/5 review remaining, refill in 42 minutes and 14 seconds. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Summary
Closes #223. After PR #231 merged `pickBestVariantPerCell`, this PR replaces its effective-savings tiebreaker with config-match, and fixes the two adjacent surfaces that hardcoded `'all-upfront'`.
Three surfaces changed:
Bootstrap approach: `loadRecommendations()` adds `api.getConfig()` as a siloed third leg of its `Promise.all` (`.catch(() => null)` — a missing config endpoint cannot block rec load). Resolved values populate module-level `cachedGlobalDefaultTerm / Payment`.
Exported for testing: `pickBestVariantPerCell` (pure function, no DOM side effects) and `seedGlobalDefaults(term, payment)` (test injection hook).
Test plan
Summary by CodeRabbit