Refine device traffic display and sorting
This commit is contained in:
@@ -34,7 +34,7 @@ export function formatByteString(value) {
|
||||
export function sortDevicesByTraffic(devices, direction = 'desc') {
|
||||
const factor = direction === 'asc' ? 1 : -1;
|
||||
return (Array.isArray(devices) ? devices : [])
|
||||
.map((device, index) => ({ device, index }))
|
||||
.map((device) => ({ device }))
|
||||
.sort((left, right) => {
|
||||
const pinned = Number(right.device.pinned === true) - Number(left.device.pinned === true);
|
||||
if (pinned) return pinned;
|
||||
@@ -42,7 +42,9 @@ export function sortDevicesByTraffic(devices, direction = 'desc') {
|
||||
+ byteString(left.device.proxyUploadBytes) + byteString(left.device.proxyDownloadBytes);
|
||||
const rightTotal = byteString(right.device.uploadBytes) + byteString(right.device.downloadBytes)
|
||||
+ byteString(right.device.proxyUploadBytes) + byteString(right.device.proxyDownloadBytes);
|
||||
if (leftTotal === rightTotal) return left.index - right.index;
|
||||
if (leftTotal === rightTotal) {
|
||||
return String(left.device.id || '').localeCompare(String(right.device.id || ''));
|
||||
}
|
||||
return (leftTotal < rightTotal ? -1 : 1) * factor;
|
||||
})
|
||||
.map(({ device }) => device);
|
||||
|
||||
Reference in New Issue
Block a user