fix(billing): skip realtime segment when bandwidth < realtimeBandwidth

A handful of legacy orgs have realtime bandwidth tracked separately
(not yet billed and not added into the bandwidth resource). For them
realtimeBytes > totalBytes, which would otherwise overflow the bar or
collapse the regular segment to zero. Detect that case and render
bandwidth as a single segment instead, preserving today's behaviour
for those orgs.
This commit is contained in:
Damodar Lohani
2026-05-03 07:04:34 +00:00
parent b7e558545e
commit 0de30dad10
@@ -157,9 +157,12 @@
const maxBytes = maxGB * 1000 * 1000 * 1000;
const percentage = Math.min((totalBytes / maxBytes) * 100, 100);
// Backend already rolls realtimeBytes into totalBytes; carve the realtime
// slice out of the total instead of summing them. Clamp in case of dirty data.
const realtimePortion = Math.max(0, Math.min(realtimeBytes, totalBytes));
// Backend rolls realtimeBytes into totalBytes for billed orgs, so realtime
// is a slice of the total. A handful of legacy orgs still have realtime
// tracked separately (not billed yet) — for them realtime > total. In that
// case skip the breakdown and render the bandwidth as a single segment.
const showRealtimeSegment = realtimeBytes > 0 && realtimeBytes <= totalBytes;
const realtimePortion = showRealtimeSegment ? realtimeBytes : 0;
const regularPortion = Math.max(0, totalBytes - realtimePortion);
const regularSize = humanFileSize(regularPortion);
const realtimeSize = humanFileSize(realtimePortion);