From e86882aa36e403e32f1789ed47dc698a51eba0d8 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 6 Jul 2026 21:19:52 -0500 Subject: tweak componensts for consistency --- src/web/src/components/Dashboard/ExceptionList.jsx | 96 ++++++++ .../src/components/Dashboard/ExceptionPareto.jsx | 110 +++++++++ src/web/src/components/Dashboard/Leaderboard.jsx | 35 ++- .../src/components/Dashboard/TopDirectories.jsx | 93 ++++---- .../src/components/Dashboard/TransferErrors.jsx | 248 +++++++++------------ 5 files changed, 374 insertions(+), 208 deletions(-) create mode 100644 src/web/src/components/Dashboard/ExceptionList.jsx create mode 100644 src/web/src/components/Dashboard/ExceptionPareto.jsx (limited to 'src/web') 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 }) => ( + <> +
+ + Recent Errors + + {DIRECTIONS.map((d) => ( + + ))} + +
+ + + + Time + Direction + Username + Filename + Exception + + + + {loading && ( + + + + + + )} + {rows.length === 0 && !loading && ( + + + No data to display + + + )} + {!loading && + rows.map((row) => ( + + + {row.endedAt ? formatDate(row.endedAt) : ''} + + {row.direction} + {row.username} + + {row.filename ? getFileName(row.filename) : ''} + + + {truncate(row.exception, 80)} + + + ))} + +
+ +); + +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 ( + <> +
+ + Error Count By Type + + {DIRECTIONS.map((d) => ( + + ))} + +
+ + + + Direction + Exception + + Count + + Distinct Users + + + + + {loading && ( + + + + + + )} + {!loading && rows.length === 0 && ( + + + No data to display + + + )} + {!loading && + rows.map((row) => ( + + {row.direction} + + {truncate(row.exception, 80)} + + + + + + {row.count.toLocaleString()} + + + {row.distinctUsers.toLocaleString()} + + + ))} + +
+ + ); +}; + +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 > -
+
Downloads
{ -
+
Uploads
{ if (!path) { @@ -16,56 +16,61 @@ const getLastTwoSegments = (path) => { }; const TopDirectories = ({ rows }) => ( - - - - - # - - Directory - Downloads - Distinct Users - - - - {(!rows || rows.length === 0) && ( + <> +
+ Directories +
+
+ - - No data to display - + # + + Directory + Downloads + Distinct Users - )} - {rows && - rows.map((row, index) => ( - + + + {(!rows || rows.length === 0) && ( + - {index + 1} - - - {getLastTwoSegments(row.directory)} - - - {row.count.toLocaleString()} - - - {row.distinctUsers.toLocaleString()} + No data to display - ))} - -
+ )} + {rows && + rows.map((row, index) => ( + + + {index + 1} + + + {getLastTwoSegments(row.directory)} + + + {row.count.toLocaleString()} + + + {row.distinctUsers.toLocaleString()} + + + ))} + + + ); 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 (
-
Error Count Over Time
+
+ Errors +
- -
- Top Fault Types - - pareto - -
- - - - Exception - - Count - - Distinct Users - - - - - {(!paretoRows || paretoRows.length === 0) && ( - - - No data to display - - - )} - {paretoRows && - paretoRows.map((row) => ( - - - {truncate(row.exception, 80)} - - -
-
-
- - - {row.count.toLocaleString()} - - - {row.distinctUsers.toLocaleString()} - - - ))} - -
- -
Recent Errors
- - - - Time - Direction - Username - Filename - Exception - - - - {(!recentRows || recentRows.length === 0) && ( - - - No data to display - - - )} - {recentRows && - recentRows.map((row) => ( - - - {formatDateTime(row.endedAt)} - - {row.direction} - {row.username} - - {getFilename(row.filename)} - - - {truncate(row.exception, 80)} - - - ))} - -
+ +
); }; -- cgit v1.2.3