diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-07-06 21:19:52 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-07-06 21:19:52 -0500 |
| commit | e86882aa36e403e32f1789ed47dc698a51eba0d8 (patch) | |
| tree | b892bb3f520cfc057139ad769b16885260efc82c /src | |
| parent | 0ff48cabb1464f171b246225c58d15e8ecdb1e57 (diff) | |
| download | slskd-e86882aa36e403e32f1789ed47dc698a51eba0d8.tar.gz | |
tweak componensts for consistency
Diffstat (limited to 'src')
| -rw-r--r-- | src/web/src/components/Dashboard/ExceptionList.jsx | 96 | ||||
| -rw-r--r-- | src/web/src/components/Dashboard/ExceptionPareto.jsx | 110 | ||||
| -rw-r--r-- | src/web/src/components/Dashboard/Leaderboard.jsx | 35 | ||||
| -rw-r--r-- | src/web/src/components/Dashboard/TopDirectories.jsx | 93 | ||||
| -rw-r--r-- | src/web/src/components/Dashboard/TransferErrors.jsx | 248 |
5 files changed, 374 insertions, 208 deletions
diff --git a/src/web/src/components/Dashboard/ExceptionList.jsx b/src/web/src/components/Dashboard/ExceptionList.jsx new file mode 100644 index 00000000..d0412006 --- /dev/null +++ b/src/web/src/components/Dashboard/ExceptionList.jsx @@ -0,0 +1,96 @@ +import { formatDate, getFileName, truncate } from '../../lib/util'; +import React from 'react'; +import { + Button, + ButtonGroup, + Header, + Icon, + Loader, + Table, +} from 'semantic-ui-react'; + +const DIRECTIONS = ['Upload', 'Download', 'All']; + +const ExceptionList = ({ direction, loading, onDirectionChange, rows }) => ( + <> + <Header + size="small" + style={{ alignItems: 'center', display: 'flex' }} + > + <Icon name="clipboard outline" /> + <Header.Content>Recent Errors</Header.Content> + <ButtonGroup + size="mini" + style={{ marginLeft: 'auto' }} + > + {DIRECTIONS.map((d) => ( + <Button + active={direction === d} + key={d} + onClick={() => onDirectionChange(d)} + > + {d} + </Button> + ))} + </ButtonGroup> + </Header> + <Table + className="unstackable" + compact="very" + > + <Table.Header> + <Table.Row> + <Table.HeaderCell>Time</Table.HeaderCell> + <Table.HeaderCell>Direction</Table.HeaderCell> + <Table.HeaderCell>Username</Table.HeaderCell> + <Table.HeaderCell>Filename</Table.HeaderCell> + <Table.HeaderCell>Exception</Table.HeaderCell> + </Table.Row> + </Table.Header> + <Table.Body> + {loading && ( + <Table.Row> + <Table.Cell + colSpan={5} + textAlign="center" + > + <Loader + active + inline="centered" + size="small" + /> + </Table.Cell> + </Table.Row> + )} + {rows.length === 0 && !loading && ( + <Table.Row> + <Table.Cell + colSpan={5} + style={{ opacity: 0.5, textAlign: 'center' }} + > + No data to display + </Table.Cell> + </Table.Row> + )} + {!loading && + rows.map((row) => ( + <Table.Row key={`${row.direction}-${row.endedAt}-${row.filename}`}> + <Table.Cell style={{ whiteSpace: 'nowrap' }}> + {row.endedAt ? formatDate(row.endedAt) : ''} + </Table.Cell> + <Table.Cell>{row.direction}</Table.Cell> + <Table.Cell>{row.username}</Table.Cell> + <Table.Cell title={row.filename}> + {row.filename ? getFileName(row.filename) : ''} + </Table.Cell> + <Table.Cell title={row.exception}> + {truncate(row.exception, 80)} + </Table.Cell> + </Table.Row> + ))} + </Table.Body> + </Table> + </> +); + +export default ExceptionList; diff --git a/src/web/src/components/Dashboard/ExceptionPareto.jsx b/src/web/src/components/Dashboard/ExceptionPareto.jsx new file mode 100644 index 00000000..13fafb5a --- /dev/null +++ b/src/web/src/components/Dashboard/ExceptionPareto.jsx @@ -0,0 +1,110 @@ +import { truncate } from '../../lib/util'; +import React from 'react'; +import { + Button, + ButtonGroup, + Header, + Icon, + Loader, + Progress, + Table, +} from 'semantic-ui-react'; + +const DIRECTIONS = ['Upload', 'Download', 'All']; + +const ExceptionPareto = ({ direction, loading, onDirectionChange, rows }) => { + const maxCount = rows.length > 0 ? rows[0].count : 1; + + return ( + <> + <Header + size="small" + style={{ alignItems: 'center', display: 'flex' }} + > + <Icon name="sort amount down" /> + <Header.Content>Error Count By Type</Header.Content> + <ButtonGroup + size="mini" + style={{ marginLeft: 'auto' }} + > + {DIRECTIONS.map((d) => ( + <Button + active={direction === d} + key={d} + onClick={() => onDirectionChange(d)} + > + {d} + </Button> + ))} + </ButtonGroup> + </Header> + <Table + className="unstackable" + compact="very" + > + <Table.Header> + <Table.Row> + <Table.HeaderCell>Direction</Table.HeaderCell> + <Table.HeaderCell>Exception</Table.HeaderCell> + <Table.HeaderCell style={{ width: '120px' }} /> + <Table.HeaderCell textAlign="right">Count</Table.HeaderCell> + <Table.HeaderCell textAlign="right"> + Distinct Users + </Table.HeaderCell> + </Table.Row> + </Table.Header> + <Table.Body> + {loading && ( + <Table.Row> + <Table.Cell + colSpan={5} + textAlign="center" + > + <Loader + active + inline="centered" + size="small" + /> + </Table.Cell> + </Table.Row> + )} + {!loading && rows.length === 0 && ( + <Table.Row> + <Table.Cell + colSpan={5} + style={{ opacity: 0.5, textAlign: 'center' }} + > + No data to display + </Table.Cell> + </Table.Row> + )} + {!loading && + rows.map((row) => ( + <Table.Row key={`${row.direction}-${row.exception ?? ''}`}> + <Table.Cell>{row.direction}</Table.Cell> + <Table.Cell title={row.exception}> + {truncate(row.exception, 80)} + </Table.Cell> + <Table.Cell> + <Progress + color="red" + percent={Math.round((row.count / maxCount) * 100)} + size="tiny" + style={{ margin: 0 }} + /> + </Table.Cell> + <Table.Cell textAlign="right"> + <strong>{row.count.toLocaleString()}</strong> + </Table.Cell> + <Table.Cell textAlign="right"> + {row.distinctUsers.toLocaleString()} + </Table.Cell> + </Table.Row> + ))} + </Table.Body> + </Table> + </> + ); +}; + +export default ExceptionPareto; diff --git a/src/web/src/components/Dashboard/Leaderboard.jsx b/src/web/src/components/Dashboard/Leaderboard.jsx index a7fa6662..4a37870c 100644 --- a/src/web/src/components/Dashboard/Leaderboard.jsx +++ b/src/web/src/components/Dashboard/Leaderboard.jsx @@ -129,30 +129,27 @@ const Leaderboard = ({ downloads, end, start, uploads }) => { const startDate = start ? new Date(start) : undefined; const endDate = end ? new Date(end) : new Date(); - const [newUploads, newDownloads] = await Promise.all([ - reports - .getLeaderboard({ + let newUploads = state.rows.upload; + let newDownloads = state.rows.download; + + try { + [newUploads, newDownloads] = await Promise.all([ + reports.getLeaderboard({ direction: 'Upload', end: endDate, sortBy: sort, start: startDate, - }) - .catch((error) => { - console.error(error); - return state.rows.upload; }), - reports - .getLeaderboard({ + reports.getLeaderboard({ direction: 'Download', end: endDate, sortBy: sort, start: startDate, - }) - .catch((error) => { - console.error(error); - return state.rows.download; }), - ]); + ]); + } catch (error) { + console.error(error); + } setState((previous) => ({ ...previous, @@ -167,10 +164,7 @@ const Leaderboard = ({ downloads, end, start, uploads }) => { stackable > <Grid.Column> - <Header - className="leaderboard-header" - size="tiny" - > + <Header size="small"> <Icon name="download" /> Downloads </Header> <LeaderboardTable @@ -182,10 +176,7 @@ const Leaderboard = ({ downloads, end, start, uploads }) => { </Grid.Column> <Divider vertical /> <Grid.Column> - <Header - className="leaderboard-header" - size="tiny" - > + <Header size="small"> <Icon name="upload" /> Uploads </Header> <LeaderboardTable diff --git a/src/web/src/components/Dashboard/TopDirectories.jsx b/src/web/src/components/Dashboard/TopDirectories.jsx index e9d4aba5..cadb3e80 100644 --- a/src/web/src/components/Dashboard/TopDirectories.jsx +++ b/src/web/src/components/Dashboard/TopDirectories.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import { Table } from 'semantic-ui-react'; +import { Header, Icon, Table } from 'semantic-ui-react'; const getLastTwoSegments = (path) => { if (!path) { @@ -16,56 +16,61 @@ const getLastTwoSegments = (path) => { }; const TopDirectories = ({ rows }) => ( - <Table - className="unstackable" - compact="very" - > - <Table.Header> - <Table.Row> - <Table.HeaderCell - style={{ color: '#999', width: '2em' }} - textAlign="right" - > - # - </Table.HeaderCell> - <Table.HeaderCell>Directory</Table.HeaderCell> - <Table.HeaderCell textAlign="right">Downloads</Table.HeaderCell> - <Table.HeaderCell textAlign="right">Distinct Users</Table.HeaderCell> - </Table.Row> - </Table.Header> - <Table.Body> - {(!rows || rows.length === 0) && ( + <> + <Header size="small"> + <Icon name="folder open" /> Directories + </Header> + <Table + className="unstackable" + compact="very" + > + <Table.Header> <Table.Row> - <Table.Cell - colSpan={4} - style={{ opacity: 0.5, textAlign: 'center' }} + <Table.HeaderCell + style={{ color: '#999', width: '2em' }} + textAlign="right" > - No data to display - </Table.Cell> + # + </Table.HeaderCell> + <Table.HeaderCell>Directory</Table.HeaderCell> + <Table.HeaderCell textAlign="right">Downloads</Table.HeaderCell> + <Table.HeaderCell textAlign="right">Distinct Users</Table.HeaderCell> </Table.Row> - )} - {rows && - rows.map((row, index) => ( - <Table.Row key={row.directory}> + </Table.Header> + <Table.Body> + {(!rows || rows.length === 0) && ( + <Table.Row> <Table.Cell - style={{ color: '#999' }} - textAlign="right" + colSpan={4} + style={{ opacity: 0.5, textAlign: 'center' }} > - {index + 1} - </Table.Cell> - <Table.Cell title={row.directory}> - {getLastTwoSegments(row.directory)} - </Table.Cell> - <Table.Cell textAlign="right"> - {row.count.toLocaleString()} - </Table.Cell> - <Table.Cell textAlign="right"> - {row.distinctUsers.toLocaleString()} + No data to display </Table.Cell> </Table.Row> - ))} - </Table.Body> - </Table> + )} + {rows && + rows.map((row, index) => ( + <Table.Row key={row.directory}> + <Table.Cell + style={{ color: '#999' }} + textAlign="right" + > + {index + 1} + </Table.Cell> + <Table.Cell title={row.directory}> + {getLastTwoSegments(row.directory)} + </Table.Cell> + <Table.Cell textAlign="right"> + {row.count.toLocaleString()} + </Table.Cell> + <Table.Cell textAlign="right"> + {row.distinctUsers.toLocaleString()} + </Table.Cell> + </Table.Row> + ))} + </Table.Body> + </Table> + </> ); export default TopDirectories; diff --git a/src/web/src/components/Dashboard/TransferErrors.jsx b/src/web/src/components/Dashboard/TransferErrors.jsx index 54dc9a20..7def5ca6 100644 --- a/src/web/src/components/Dashboard/TransferErrors.jsx +++ b/src/web/src/components/Dashboard/TransferErrors.jsx @@ -5,23 +5,13 @@ import ExceptionPareto from './ExceptionPareto'; import React, { useEffect, useMemo, useState } from 'react'; import { Header, Icon } from 'semantic-ui-react'; -const mergePareto = (uploadRows, downloadRows) => { - const combined = {}; - for (const row of [...(uploadRows || []), ...(downloadRows || [])]) { - const key = row.exception ?? ''; - combined[key] = combined[key] - ? { - exception: key, - count: combined[key].count + row.count, - distinctUsers: combined[key].distinctUsers + row.distinctUsers, - } - : { ...row }; - } - - return Object.values(combined) +const buildParetoRows = (uploadRows, downloadRows) => + [ + ...(uploadRows || []).map((r) => ({ ...r, direction: 'Upload' })), + ...(downloadRows || []).map((r) => ({ ...r, direction: 'Download' })), + ] .sort((a, b) => b.count - a.count) .slice(0, 10); -}; const mergeRecent = (uploadRows, downloadRows) => [ @@ -50,148 +40,122 @@ const ERRORS_SERIES = [ const DEFAULT_ERRORS_SERIES = new Set(['uploadErrors', 'downloadErrors']); -const TransferErrors = ({ chartData, download, upload }) => { - const isDark = useDarkMode(); +const RECENT_PAGE_SIZE = 10; + +const TransferErrors = ({ chartData, download, end, start, upload }) => { + const [paretoDirection, setParetoDirection] = useState('All'); + const [paretoRows, setParetoRows] = useState(null); + const [paretoLoading, setParetoLoading] = useState(false); - const paretoRows = useMemo( - () => mergePareto(upload.pareto, download.pareto), + const [recentDirection, setRecentDirection] = useState('All'); + const [recentRows, setRecentRows] = useState(null); + const [recentLoading, setRecentLoading] = useState(false); + + useEffect(() => { + setParetoDirection('All'); + setParetoRows(null); + setRecentDirection('All'); + setRecentRows(null); + }, [end, start]); + + const initialParetoRows = useMemo( + () => buildParetoRows(upload.pareto, download.pareto), [upload.pareto, download.pareto], ); - const recentRows = useMemo( + + const initialRecentRows = useMemo( () => mergeRecent(upload.recent, download.recent), [upload.recent, download.recent], ); - const maxParetoCount = - paretoRows && paretoRows.length > 0 ? paretoRows[0].count : 1; + const displayedParetoRows = paretoRows ?? initialParetoRows; + const displayedRecentRows = recentRows ?? initialRecentRows; + + const fetchPareto = async (direction) => { + try { + return await reports.getExceptionPareto({ + direction, + end: new Date(end), + start: start ? new Date(start) : undefined, + }); + } catch (error) { + console.error(error); + return []; + } + }; + + const fetchRecent = async (direction) => { + try { + return await reports.getExceptions({ + direction, + end: new Date(end), + limit: RECENT_PAGE_SIZE, + start: start ? new Date(start) : undefined, + }); + } catch (error) { + console.error(error); + return []; + } + }; + + const onParetoDirectionChange = async (d) => { + setParetoDirection(d); + setParetoLoading(true); + + if (d === 'All') { + const [uploadRows, downloadRows] = await Promise.all([ + fetchPareto('Upload'), + fetchPareto('Download'), + ]); + setParetoRows(buildParetoRows(uploadRows, downloadRows)); + } else { + const rows = await fetchPareto(d); + setParetoRows(rows.map((r) => ({ ...r, direction: d }))); + } + + setParetoLoading(false); + }; + + const onRecentDirectionChange = async (d) => { + setRecentDirection(d); + setRecentLoading(true); + + if (d === 'All') { + const [uploadRows, downloadRows] = await Promise.all([ + fetchRecent('Upload'), + fetchRecent('Download'), + ]); + setRecentRows(mergeRecent(uploadRows, downloadRows)); + } else { + const rows = await fetchRecent(d); + setRecentRows(rows.map((r) => ({ ...r, direction: d }))); + } + + setRecentLoading(false); + }; return ( <div> - <Header as="h5">Error Count Over Time</Header> + <Header size="small"> + <Icon name="history" /> Errors + </Header> <Graph data={chartData ?? []} defaultSeries={DEFAULT_ERRORS_SERIES} series={ERRORS_SERIES} /> - <Divider /> - <Header as="h5"> - Top Fault Types - <span - style={{ - color: '#999', - float: 'right', - fontSize: '0.8em', - fontWeight: 'normal', - }} - > - pareto - </span> - </Header> - <Table - className="unstackable" - compact="very" - > - <Table.Header> - <Table.Row> - <Table.HeaderCell>Exception</Table.HeaderCell> - <Table.HeaderCell style={{ width: '120px' }} /> - <Table.HeaderCell textAlign="right">Count</Table.HeaderCell> - <Table.HeaderCell textAlign="right"> - Distinct Users - </Table.HeaderCell> - </Table.Row> - </Table.Header> - <Table.Body> - {(!paretoRows || paretoRows.length === 0) && ( - <Table.Row> - <Table.Cell - colSpan={4} - style={{ opacity: 0.5, textAlign: 'center' }} - > - No data to display - </Table.Cell> - </Table.Row> - )} - {paretoRows && - paretoRows.map((row) => ( - <Table.Row key={row.exception ?? ''}> - <Table.Cell title={row.exception}> - {truncate(row.exception, 80)} - </Table.Cell> - <Table.Cell> - <div - style={{ - background: isDark ? 'rgba(255,255,255,0.08)' : '#f0f0f0', - borderRadius: '2px', - height: '7px', - }} - > - <div - style={{ - background: '#db2828', - borderRadius: '2px', - height: '7px', - width: `${Math.round((row.count / maxParetoCount) * 100)}%`, - }} - /> - </div> - </Table.Cell> - <Table.Cell textAlign="right"> - <strong>{row.count.toLocaleString()}</strong> - </Table.Cell> - <Table.Cell textAlign="right"> - {row.distinctUsers.toLocaleString()} - </Table.Cell> - </Table.Row> - ))} - </Table.Body> - </Table> - <Divider /> - <Header as="h5">Recent Errors</Header> - <Table - className="unstackable" - compact="very" - > - <Table.Header> - <Table.Row> - <Table.HeaderCell>Time</Table.HeaderCell> - <Table.HeaderCell>Direction</Table.HeaderCell> - <Table.HeaderCell>Username</Table.HeaderCell> - <Table.HeaderCell>Filename</Table.HeaderCell> - <Table.HeaderCell>Exception</Table.HeaderCell> - </Table.Row> - </Table.Header> - <Table.Body> - {(!recentRows || recentRows.length === 0) && ( - <Table.Row> - <Table.Cell - colSpan={5} - style={{ opacity: 0.5, textAlign: 'center' }} - > - No data to display - </Table.Cell> - </Table.Row> - )} - {recentRows && - recentRows.map((row) => ( - <Table.Row - key={`${row.direction}-${row.endedAt}-${row.filename}`} - > - <Table.Cell style={{ whiteSpace: 'nowrap' }}> - {formatDateTime(row.endedAt)} - </Table.Cell> - <Table.Cell>{row.direction}</Table.Cell> - <Table.Cell>{row.username}</Table.Cell> - <Table.Cell title={row.filename}> - {getFilename(row.filename)} - </Table.Cell> - <Table.Cell title={row.exception}> - {truncate(row.exception, 80)} - </Table.Cell> - </Table.Row> - ))} - </Table.Body> - </Table> + <ExceptionPareto + direction={paretoDirection} + loading={paretoLoading} + onDirectionChange={onParetoDirectionChange} + rows={displayedParetoRows} + /> + <ExceptionList + direction={recentDirection} + loading={recentLoading} + onDirectionChange={onRecentDirectionChange} + rows={displayedRecentRows} + /> </div> ); }; |
