From 68118cb83c6993eae0f46d92ea29861bf5d7679c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 7 Dec 2025 00:46:31 +0000 Subject: Add sorting functionality to System Files view Co-authored-by: jpdillingham <17145758+jpdillingham@users.noreply.github.com> --- src/web/src/components/System/Files/Explorer.jsx | 70 ++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/web/src/components/System/Files/Explorer.jsx b/src/web/src/components/System/Files/Explorer.jsx index e577b31c..543c0744 100644 --- a/src/web/src/components/System/Files/Explorer.jsx +++ b/src/web/src/components/System/Files/Explorer.jsx @@ -126,6 +126,8 @@ const Explorer = ({ remoteFileManagement, root }) => { const [directory, setDirectory] = useState({ directories: [], files: [] }); const [subdirectory, setSubdirectory] = useState([]); const [loading, setLoading] = useState(false); + const [sortColumn, setSortColumn] = useState('name'); + const [sortDirection, setSortDirection] = useState('ascending'); const fetch = async () => { setLoading(true); @@ -155,11 +157,45 @@ const Explorer = ({ remoteFileManagement, root }) => { setSubdirectory(copy); }; + const handleSort = (column) => { + if (sortColumn === column) { + setSortDirection( + sortDirection === 'ascending' ? 'descending' : 'ascending', + ); + } else { + setSortColumn(column); + setSortDirection('ascending'); + } + }; + + const sortItems = (items) => { + if (!items || items.length === 0) return items; + + return [...items].sort((a, b) => { + let compareValue = 0; + + if (sortColumn === 'name') { + compareValue = a.name.localeCompare(b.name, undefined, { + numeric: true, + sensitivity: 'base', + }); + } else if (sortColumn === 'date') { + const dateA = new Date(a.modifiedAt); + const dateB = new Date(b.modifiedAt); + compareValue = dateA - dateB; + } + + return sortDirection === 'ascending' ? compareValue : -compareValue; + }); + }; + if (loading) { return ; } const total = directory?.directories?.length + directory?.files?.length ?? 0; + const sortedDirectories = sortItems(directory?.directories); + const sortedFiles = sortItems(directory?.files); return ( <> @@ -176,11 +212,37 @@ const Explorer = ({ remoteFileManagement, root }) => { > - + handleSort('name')} + style={{ cursor: 'pointer' }} + > Name + {sortColumn === 'name' && ( + + )} - + handleSort('date')} + style={{ cursor: 'pointer' }} + > Date Modified + {sortColumn === 'date' && ( + + )} Size @@ -215,7 +277,7 @@ const Explorer = ({ remoteFileManagement, root }) => { subdirectory={subdirectory} /> )} - {directory?.directories?.map((d) => ( + {sortedDirectories?.map((d) => ( select({ path: d.name })} @@ -225,7 +287,7 @@ const Explorer = ({ remoteFileManagement, root }) => { {...d} /> ))} - {directory?.files?.map((f) => ( + {sortedFiles?.map((f) => (