Skip to content

Commit 4075bcd

Browse files
Merge pull request #3017 from appwrite/claude/bandwidth-progress-bar-breakdown-D4fej
feat: combine bandwidth and realtime bandwidth into a single row with breakdown
2 parents 59e7ff6 + 3d6844b commit 4075bcd

1 file changed

Lines changed: 72 additions & 10 deletions

File tree

src/routes/(console)/organization-[organization]/billing/planSummary.svelte

Lines changed: 72 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,52 @@
148148
];
149149
}
150150
151+
function createBandwidthProgressData(
152+
totalBytes: number,
153+
realtimeBytes: number,
154+
maxGB: number
155+
): Array<{ size: number; color: string; tooltip?: { title: string; label: string } }> {
156+
if (maxGB <= 0) return [];
157+
158+
const maxBytes = maxGB * 1000 * 1000 * 1000;
159+
const percentage = Math.min((totalBytes / maxBytes) * 100, 100);
160+
const showRealtimeSegment = realtimeBytes > 0 && realtimeBytes <= totalBytes;
161+
const realtimePortion = showRealtimeSegment ? realtimeBytes : 0;
162+
const regularPortion = Math.max(0, totalBytes - realtimePortion);
163+
const regularSize = humanFileSize(regularPortion);
164+
const realtimeSize = humanFileSize(realtimePortion);
165+
166+
const segments: Array<{
167+
size: number;
168+
color: string;
169+
tooltip?: { title: string; label: string };
170+
}> = [];
171+
172+
if (regularPortion > 0) {
173+
segments.push({
174+
size: regularPortion,
175+
color: 'var(--bgcolor-neutral-invert)',
176+
tooltip: {
177+
title: `${percentage.toFixed(0)}% used`,
178+
label: `Bandwidth: ${regularSize.value} ${regularSize.unit}`
179+
}
180+
});
181+
}
182+
183+
if (realtimePortion > 0) {
184+
segments.push({
185+
size: realtimePortion,
186+
color: 'var(--bgcolor-neutral-invert-weak)',
187+
tooltip: {
188+
title: 'Realtime bandwidth',
189+
label: `${realtimeSize.value} ${realtimeSize.unit}`
190+
}
191+
});
192+
}
193+
194+
return segments;
195+
}
196+
151197
function getResource(resources: Array<Models.UsageResources> | undefined, resourceId: string) {
152198
return resources?.find((resource) => resource.resourceId === resourceId);
153199
}
@@ -282,9 +328,13 @@
282328
const projects = (currentAggregation?.breakdown || []).map((projectData) => {
283329
const resources = projectData.resources || [];
284330
const bandwidth = getResource(resources, 'bandwidth');
331+
const realtimeBandwidth = getResource(resources, 'realtimeBandwidth');
285332
const storage = getResource(resources, 'storage');
286333
const authPhone = getResource(resources, 'authPhone');
287334
335+
const bandwidthValue = bandwidth?.value || 0;
336+
const realtimeBandwidthValue = realtimeBandwidth?.value || 0;
337+
288338
return {
289339
id: `project-${projectData.$id}`,
290340
expandable: true,
@@ -309,10 +359,31 @@
309359
),
310360
priceFormatter: ({ amount }) => formatCurrency(amount),
311361
progressFactory: ({ value, planLimit, hasLimit }) =>
312-
hasLimit ? createStorageProgressData(value, planLimit || 0) : [],
362+
hasLimit
363+
? createBandwidthProgressData(
364+
value,
365+
realtimeBandwidthValue,
366+
planLimit || 0
367+
)
368+
: [],
313369
maxFactory: ({ planLimit, hasLimit }) =>
314370
hasLimit ? (planLimit || 0) * 1000 * 1000 * 1000 : null
315371
}),
372+
...(realtimeBandwidthValue > bandwidthValue
373+
? [
374+
createRow({
375+
id: 'realtime-bandwidth',
376+
label: 'Realtime bandwidth',
377+
resource: realtimeBandwidth,
378+
usageFormatter: ({ value }) => {
379+
const size = humanFileSize(value);
380+
return `${size.value} ${size.unit}`;
381+
},
382+
priceFormatter: ({ amount }) => formatCurrency(amount),
383+
includeProgress: false
384+
})
385+
]
386+
: []),
316387
// standard resources (numeric)
317388
createResourceRow(
318389
'users',
@@ -383,15 +454,6 @@
383454
getResource(resources, 'realtimeMessages'),
384455
currentPlan?.realtimeMessages
385456
),
386-
createRow({
387-
id: 'realtime-bandwidth',
388-
label: 'Realtime bandwidth',
389-
resource: getResource(resources, 'realtimeBandwidth'),
390-
usageFormatter: ({ value }) =>
391-
humanFileSize(value).value + humanFileSize(value).unit,
392-
priceFormatter: ({ amount }) => formatCurrency(amount),
393-
includeProgress: false
394-
}),
395457
createRow({
396458
id: 'sms',
397459
label: 'Phone OTP',

0 commit comments

Comments
 (0)