|
148 | 148 | ]; |
149 | 149 | } |
150 | 150 |
|
| 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 | +
|
151 | 197 | function getResource(resources: Array<Models.UsageResources> | undefined, resourceId: string) { |
152 | 198 | return resources?.find((resource) => resource.resourceId === resourceId); |
153 | 199 | } |
|
282 | 328 | const projects = (currentAggregation?.breakdown || []).map((projectData) => { |
283 | 329 | const resources = projectData.resources || []; |
284 | 330 | const bandwidth = getResource(resources, 'bandwidth'); |
| 331 | + const realtimeBandwidth = getResource(resources, 'realtimeBandwidth'); |
285 | 332 | const storage = getResource(resources, 'storage'); |
286 | 333 | const authPhone = getResource(resources, 'authPhone'); |
287 | 334 |
|
| 335 | + const bandwidthValue = bandwidth?.value || 0; |
| 336 | + const realtimeBandwidthValue = realtimeBandwidth?.value || 0; |
| 337 | +
|
288 | 338 | return { |
289 | 339 | id: `project-${projectData.$id}`, |
290 | 340 | expandable: true, |
|
309 | 359 | ), |
310 | 360 | priceFormatter: ({ amount }) => formatCurrency(amount), |
311 | 361 | progressFactory: ({ value, planLimit, hasLimit }) => |
312 | | - hasLimit ? createStorageProgressData(value, planLimit || 0) : [], |
| 362 | + hasLimit |
| 363 | + ? createBandwidthProgressData( |
| 364 | + value, |
| 365 | + realtimeBandwidthValue, |
| 366 | + planLimit || 0 |
| 367 | + ) |
| 368 | + : [], |
313 | 369 | maxFactory: ({ planLimit, hasLimit }) => |
314 | 370 | hasLimit ? (planLimit || 0) * 1000 * 1000 * 1000 : null |
315 | 371 | }), |
| 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 | + : []), |
316 | 387 | // standard resources (numeric) |
317 | 388 | createResourceRow( |
318 | 389 | 'users', |
|
383 | 454 | getResource(resources, 'realtimeMessages'), |
384 | 455 | currentPlan?.realtimeMessages |
385 | 456 | ), |
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 | | - }), |
395 | 457 | createRow({ |
396 | 458 | id: 'sms', |
397 | 459 | label: 'Phone OTP', |
|
0 commit comments