diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-07-06 20:53:42 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-07-06 20:53:42 -0500 |
| commit | 0ff48cabb1464f171b246225c58d15e8ecdb1e57 (patch) | |
| tree | e8e7a3f1fec24bc5028cc47e5d683ef5b782b3e0 | |
| parent | ffd47b2287f8d8e8dbf47079e5f746f71671805a (diff) | |
| download | slskd-0ff48cabb1464f171b246225c58d15e8ecdb1e57.tar.gz | |
move utility functions to util
| -rw-r--r-- | src/web/src/components/Dashboard/HistoricalStatistics.jsx | 21 | ||||
| -rw-r--r-- | src/web/src/components/Dashboard/Leaderboard.jsx | 13 | ||||
| -rw-r--r-- | src/web/src/components/Dashboard/TransferErrors.jsx | 38 | ||||
| -rw-r--r-- | src/web/src/lib/util.js | 11 |
4 files changed, 23 insertions, 60 deletions
diff --git a/src/web/src/components/Dashboard/HistoricalStatistics.jsx b/src/web/src/components/Dashboard/HistoricalStatistics.jsx index b0963082..c14649c4 100644 --- a/src/web/src/components/Dashboard/HistoricalStatistics.jsx +++ b/src/web/src/components/Dashboard/HistoricalStatistics.jsx @@ -1,3 +1,4 @@ +import { formatBytes, formatSpeed } from '../../lib/util'; import { Graph, LoaderSegment } from '../Shared'; import Leaderboard from './Leaderboard'; import TopDirectories from './TopDirectories'; @@ -6,7 +7,6 @@ import React, { useMemo } from 'react'; import { Button, ButtonGroup, - Divider, Header, Icon, Segment, @@ -14,18 +14,6 @@ import { Tab, } from 'semantic-ui-react'; -const formatBytes = (bytes) => { - if (!bytes || bytes === 0) return '0 B'; - const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']; - const index = Math.floor(Math.log(bytes) / Math.log(1_024)); - return `${(bytes / 1_024 ** index).toFixed(1)} ${units[index]}`; -}; - -const formatSpeed = (bytesPerSecond) => { - if (!bytesPerSecond || bytesPerSecond === 0) return '0 B/s'; - return `${formatBytes(bytesPerSecond)}/s`; -}; - const formatBytesParts = (bytes) => { if (!bytes || bytes === 0) return { unit: 'B', value: '0' }; const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']; @@ -82,14 +70,14 @@ const buildChartData = (histogram) => const HISTORY_SERIES = [ { color: '#21ba45', - format: formatBytes, + format: (v) => formatBytes(v, 1), key: 'uploadBytes', name: 'Upload Size', unit: 'bytes', }, { color: '#2185d0', - format: formatBytes, + format: (v) => formatBytes(v, 1), key: 'downloadBytes', name: 'Download Size', unit: 'bytes', @@ -226,6 +214,8 @@ const HistoricalStatistics = ({ <TransferErrors chartData={chartData} download={exceptions.download} + end={historyEnd} + start={historyStart} upload={exceptions.upload} /> </Tab.Pane> @@ -336,7 +326,6 @@ const HistoricalStatistics = ({ series={HISTORY_SERIES} /> </div> - <Divider /> <Tab activeIndex={activeTab} onTabChange={(_, { activeIndex }) => onTabChange(activeIndex)} diff --git a/src/web/src/components/Dashboard/Leaderboard.jsx b/src/web/src/components/Dashboard/Leaderboard.jsx index b983dc5a..a7fa6662 100644 --- a/src/web/src/components/Dashboard/Leaderboard.jsx +++ b/src/web/src/components/Dashboard/Leaderboard.jsx @@ -1,19 +1,8 @@ import * as reports from '../../lib/reports'; +import { formatBytes, formatSpeed } from '../../lib/util'; import React, { useEffect, useState } from 'react'; import { Divider, Grid, Header, Icon, Loader, Table } from 'semantic-ui-react'; -const formatBytes = (bytes) => { - if (!bytes || bytes === 0) return '0 B'; - const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']; - const index = Math.floor(Math.log(bytes) / Math.log(1_024)); - return `${(bytes / 1_024 ** index).toFixed(1)} ${units[index]}`; -}; - -const formatSpeed = (bytesPerSecond) => { - if (!bytesPerSecond || bytesPerSecond === 0) return '0 B/s'; - return `${formatBytes(bytesPerSecond)}/s`; -}; - const SORT_FIELDS = [ { label: 'Count', sort: 'Count' }, { label: 'Total Size', sort: 'TotalBytes' }, diff --git a/src/web/src/components/Dashboard/TransferErrors.jsx b/src/web/src/components/Dashboard/TransferErrors.jsx index 5fa0408c..54dc9a20 100644 --- a/src/web/src/components/Dashboard/TransferErrors.jsx +++ b/src/web/src/components/Dashboard/TransferErrors.jsx @@ -1,35 +1,9 @@ -import { Graph, useDarkMode } from '../Shared'; -import React, { useMemo } from 'react'; -import { Divider, Header, Table } from 'semantic-ui-react'; - -const truncate = (text, maxLength) => { - if (!text) { - return ''; - } - - if (text.length <= maxLength) { - return text; - } - - return `${text.slice(0, maxLength)}…`; -}; - -const getFilename = (path) => { - if (!path) { - return ''; - } - - const parts = path.replaceAll('\\', '/').split('/'); - return parts[parts.length - 1] || path; -}; - -const formatDateTime = (isoString) => { - if (!isoString) { - return ''; - } - - return new Date(isoString).toLocaleString(); -}; +import * as reports from '../../lib/reports'; +import { Graph } from '../Shared'; +import ExceptionList from './ExceptionList'; +import ExceptionPareto from './ExceptionPareto'; +import React, { useEffect, useMemo, useState } from 'react'; +import { Header, Icon } from 'semantic-ui-react'; const mergePareto = (uploadRows, downloadRows) => { const combined = {}; diff --git a/src/web/src/lib/util.js b/src/web/src/lib/util.js index 091a8207..b499f81e 100644 --- a/src/web/src/lib/util.js +++ b/src/web/src/lib/util.js @@ -39,10 +39,21 @@ export const formatBytes = ( return padded + ' ' + sizes[index]; }; +export const formatSpeed = (bytesPerSecond, decimals = 1) => { + if (!bytesPerSecond || bytesPerSecond === 0) return '0 B/s'; + return `${formatBytes(bytesPerSecond, decimals)}/s`; +}; + export const formatDate = (date) => { return new Date(date).toLocaleString(); }; +export const truncate = (text, maxLength) => { + if (!text) return ''; + if (text.length <= maxLength) return text; + return `${text.slice(0, maxLength)}...`; +}; + export const getFileName = (fullPath) => { return fullPath.split('\\').pop().split('/').pop(); }; |
