From 9694f0decab28f5d1474aa08f5ada063eb2737b7 Mon Sep 17 00:00:00 2001 From: Roland Date: Wed, 26 Oct 2022 11:19:50 -0600 Subject: [PATCH] Lowering prominence of progress bars on Status page when they are 0. --- app/src/components/Common.js | 28 ++++++++++++++++------------ app/src/components/admin/Status.js | 13 ++++++++++--- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/app/src/components/Common.js b/app/src/components/Common.js index e59542fd..63247630 100644 --- a/app/src/components/Common.js +++ b/app/src/components/Common.js @@ -342,19 +342,23 @@ export function humanFileSize(bytes, dp = 1) { } export function humanBandwidth(bytes) { - // Convert bytes to Mbps and return a string. - bytes /= 125; - let size = 'Kbps'; - if (bytes > 1000) { - bytes /= 125_000; - size = 'Mbps'; + // Convert bytes to MBps and return a string. + const thresh = 1024; + + if (Math.abs(bytes) < thresh) { + return bytes + ' Bps'; } - if (bytes > 1000) { - bytes /= 1000; - size = 'Gbps'; - } - bytes = Math.round(bytes); - return `${bytes} ${size}`; + + const units = ['KBps', 'MBps', 'GBps', 'TBps', 'PBps', 'EBps', 'ZBps', 'YBps']; + let u = -1; + const r = 10; + + do { + bytes /= thresh; + ++u; + } while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1); + + return bytes.toFixed(0) + ' ' + units[u]; } export function humanNumber(num, dp = 1) { diff --git a/app/src/components/admin/Status.js b/app/src/components/admin/Status.js index 30fae4cc..5f2b4edc 100644 --- a/app/src/components/admin/Status.js +++ b/app/src/components/admin/Status.js @@ -21,7 +21,7 @@ function DriveInfo({used, size, percent, mount}) { /> } -function DiskBandwidthProgress({bytes_ps, total, label}) { +function DiskBandwidthProgress({bytes_ps, total, label, ...props}) { let percent = bytes_ps / total; percent = percent || 0; let color = null; @@ -33,7 +33,7 @@ function DiskBandwidthProgress({bytes_ps, total, label}) { color = 'yellow'; } label = `${label} ${humanBandwidth(bytes_ps)}`; - return ; + return ; } function DiskBandwidth({name, bytes_read_ps, bytes_write_ps}) { @@ -43,11 +43,15 @@ function DiskBandwidth({name, bytes_read_ps, bytes_write_ps}) { bytes_ps={bytes_read_ps} total={total} label={`${name} read`} + size='tiny' + disabled={bytes_read_ps === 0} />; const write = ; return @@ -85,7 +89,8 @@ export function BandwidthProgress({label = '', bytes, maxBytes, ...props}) { } else if (percent > 90) { props['color'] = 'red'; } - return + const disabled = percent === 0; + return } export function BandwidthProgressGroup({bandwidth, ...props}) { @@ -96,6 +101,7 @@ export function BandwidthProgressGroup({bandwidth, ...props}) { bytes={bandwidth['bytes_recv']} label={`${bandwidth['name']} In`} maxBytes={maxBytes} + size='small' {...props} />; @@ -103,6 +109,7 @@ export function BandwidthProgressGroup({bandwidth, ...props}) { bytes={bandwidth['bytes_sent']} label={`${bandwidth['name']} Out`} maxBytes={maxBytes} + size='small' {...props} />;