feat(credits-admin): render daily-refills and 30-day usage panels#368
Conversation
The account view already fetched dailyRefills (daily_refill ledger rows) and usageDaily (30-day bucketed consumption) and shipped them in the JSON, but the client rendered neither — two dead queries per page load. Wire them up: a Daily refills table and an inline bar sparkline for usage (CSP-safe, CSS-only, no external lib), each with an empty state. Pin both with page tests.
|
Warning Review limit reached
Next review available in: 59 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
Claude finished @fbac's task —— View job PR Review: Daily Refills & Usage Panels
SummaryThis PR successfully wires up UI rendering for ✅ Strengths
Code QualityPositive observationsadmin-page.ts:267-273 — Daily refills rendering: var refills = j.dailyRefills || [];
var ft = document.querySelector("#refills-table tbody");
ft.innerHTML = refills.length
? refills.map(function (r) {
return "<tr><td>" + fmtDate(r.createdAt) + "</td><td>" + esc(r.delta) + "</td><td>" + esc(r.note || "") + "</td></tr>";
}).join("")
: '<tr><td colspan="3" class="hint">No daily refills.</td></tr>';✅ Proper empty state, safe HTML escaping, good fallback for admin-page.ts:275-290 — Usage sparkline: var maxUsage = usage.reduce(function (m, u) {
var c = Number(u.consumed);
return c > m ? c : m;
}, 0);
// ... then normalizes heights as percentages✅ Auto-scales bars relative to max usage, ensures minimum 2% height for visibility 🔍 Issues & SuggestionsMinor: Potential rendering bug with zero usageadmin-page.ts:286 var h = maxUsage > 0 ? Math.max(2, Math.round((c / maxUsage) * 100)) : 2;Issue: When Suggestion: If all buckets are zero, fall back to the empty state: if (!usage.length || maxUsage === 0) {
spark.innerHTML = '<span class="hint">No usage in the last 30 days.</span>';
return; // or use else
}Minor: Data type consistencyadmin-page.ts:281 var c = Number(u.consumed);The backend serializes Suggestion: Add a comment explaining why the string→number coercion is needed: // Backend sends BigInt as string; convert for math
var c = Number(u.consumed);Nit: Magic number for bar heightadmin-page.ts:286 Math.max(2, Math.round((c / maxUsage) * 100))The minimum Optional: Extract to a const for clarity: var MIN_BAR_HEIGHT_PCT = 2;
var h = maxUsage > 0 ? Math.max(MIN_BAR_HEIGHT_PCT, ...) : MIN_BAR_HEIGHT_PCT;Test Coveragetests/credits-admin/admin-page.test.ts:32-42 ✅ Both new UI elements are tested:
Suggestion: Consider adding a future integration test (out of scope for this PR) that actually loads account data and verifies the panels populate correctly. Current tests only check the HTML shell contains the elements. Performance✅ No concerns
Security✅ No concerns
CLAUDE.md Compliance✅ Passes all checklist items
This PR is display-only — it consumes data already fetched by account-view-get.ts without touching ledger operations or request contracts. Final Recommendation✅ Approve with optional minor refinements The PR is production-ready as-is. The zero-usage edge case is cosmetic and may never occur in practice (accounts with 30 days of history likely have some usage). If you want to harden it, apply the Merge order note: Author mentions merging after "collapse-balance PR". Ensure that dependency is satisfied before merging to avoid conflicts in admin-page.ts. |
ApprovabilityVerdict: Needs human review These changes add display panels for daily refills and usage data in the credits admin page. While the changes are purely UI rendering with no backend impact, they touch files in a credits-related directory and are owned by xmtplabs/engineering, warranting review by the designated owners. You can customize Macroscope's approvability policy. Learn more. |
Summary
The account view already fetched
dailyRefills(daily_refill ledger rows) andusageDaily(30-day bucketed consumption) and shipped them in the JSON, but the client rendered neither — two dead queries per page load.Part of a 5-PR credits-admin audit sweep. Touches
admin-page.ts— merge after the collapse-balance PR (or rebase).Test Plan
pnpm vitest run tests/credits-admin/→ 53/53 (TDD red→green)node --checktypecheck/eslint/prettier --checkcleanNeed help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.Note
Add daily refills table and 30-day usage sparkline to credits admin page
j.dailyRefillsinto a#refills-tablein admin-page.ts, with an empty-state hint row when no data is present.j.usageDailyas a bar sparkline in#usage-spark, scaling bar heights relative to max usage (minimum 2%) with tooltips showing bucket start and credit amounts.Macroscope summarized 272e60c.