Make every table sortable and exportable to CSV

Applies the useSortable/SortableTh infrastructure introduced in the
Diagnostic Log commit to the rest of the app's tables: Audit Log,
Users, Servers (manage table), server task tables (grouped by
schedule type, on both the all-servers and per-server views), DNS
providers/zones/records, Docker containers, Gitea repos, Integrations
(manage table), IP Addresses, Proxmox guests, Secrets (already had
CSV, gained sorting), Semaphore templates, Synology volumes/disks, and
Tailscale devices.

Every column header is now click-to-sort (again on the raw field, not
its formatted display -- a byte count sorts numerically even though
the cell shows "1.2 GB", a date sorts chronologically even though the
cell shows "5d 15h 2m"), and every table got an "Export CSV" button
next to its Refresh button, exporting whatever's currently
sorted/filtered via the existing downloadCsv util.

Grouped tables (ServerTaskTable renders one sub-table per schedule
type) can't call the useSortable hook per group without breaking the
Rules of Hooks, so extracted its comparison core as a standalone
sortItems() function, driven by one shared sort-state pair at the
component's top level and applied per group.

Deliberately left two small (1-6 row) tables embedded inside stat
cards unsorted -- Proxmox's per-node storage list and ServerDetail's
agent-reported disk list -- since they're secondary detail inside an
already-scannable card, not primary list content; happy to add if
useful in practice.

Verified the shared sort core (sortItems) directly: numeric-aware
string compare (so "item2" sorts before "item10"), numbers, booleans,
and that null/undefined always sort to the end regardless of
direction.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5 committed 2026-09-17 21:54:36 +02:00
1 parent e35da87886
commit f4274c1ad8
16 files changed
+651 -119

No files matched your search

+99 -13
View File
@@ -6,7 +6,12 @@ import {
type IntegrationSummary,
type SynologyStorageResponse,
type SynologySystemInfo,
type SynologyVolume,
type SynologyDisk,
} from "../api/client";
import { useSortable } from "../hooks/useSortable";
import SortableTh from "../components/SortableTh";
import { downloadCsv } from "../utils/csv";
function healthBadge(status: string) {
return status === "normal" ? (
@@ -103,6 +108,29 @@ export default function Synology({ user: _user }: { user: CurrentUser }) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedId]);
const { sorted: sortedVolumes, sortKey: volumeSortKey, sortDir: volumeSortDir, requestSort: requestVolumeSort } = useSortable(
data?.volumes,
);
const { sorted: sortedDisks, sortKey: diskSortKey, sortDir: diskSortDir, requestSort: requestDiskSort } = useSortable(data?.disks);
function exportVolumesCsv() {
if (!sortedVolumes) return;
downloadCsv(
"synology-volumes.csv",
["Volume", "Type", "Used", "Total", "Status"],
sortedVolumes.map((v) => [v.id, v.deviceType, formatBytes(v.sizeUsed), formatBytes(v.sizeTotal), v.status]),
);
}
function exportDisksCsv() {
if (!sortedDisks) return;
downloadCsv(
"synology-disks.csv",
["Disk", "Device", "Temp", "S.M.A.R.T.", "Status"],
sortedDisks.map((d) => [d.name, d.device, d.temp ?? "", d.smartStatus, d.status]),
);
}
return (
<>
<h2 className="page-title mb-3">Synology</h2>
@@ -216,6 +244,13 @@ export default function Synology({ user: _user }: { user: CurrentUser }) {
<div className="card-header">
<h3 className="card-title">Volumes</h3>
<div className="card-actions">
<button
className="btn btn-sm btn-outline-secondary"
onClick={exportVolumesCsv}
disabled={!sortedVolumes || sortedVolumes.length === 0}
>
Export CSV
</button>
<button
className="btn btn-sm btn-outline-secondary"
onClick={() => selected && loadStorage(selected.id)}
@@ -229,14 +264,32 @@ export default function Synology({ user: _user }: { user: CurrentUser }) {
<table className="table table-vcenter card-table">
<thead>
<tr>
<th>Volume</th>
<th>Type</th>
<th>Used</th>
<th>Status</th>
<SortableTh<SynologyVolume> label="Volume" sortKeyName="id" activeKey={volumeSortKey} direction={volumeSortDir} onSort={requestVolumeSort} />
<SortableTh<SynologyVolume>
label="Type"
sortKeyName="deviceType"
activeKey={volumeSortKey}
direction={volumeSortDir}
onSort={requestVolumeSort}
/>
<SortableTh<SynologyVolume>
label="Used"
sortKeyName="sizeUsed"
activeKey={volumeSortKey}
direction={volumeSortDir}
onSort={requestVolumeSort}
/>
<SortableTh<SynologyVolume>
label="Status"
sortKeyName="status"
activeKey={volumeSortKey}
direction={volumeSortDir}
onSort={requestVolumeSort}
/>
</tr>
</thead>
<tbody>
{data?.volumes.map((v) => (
{sortedVolumes?.map((v) => (
<tr key={v.id}>
<td>{v.id}</td>
<td className="text-secondary">{v.deviceType}</td>
@@ -246,7 +299,7 @@ export default function Synology({ user: _user }: { user: CurrentUser }) {
<td>{healthBadge(v.status)}</td>
</tr>
))}
{data?.volumes.length === 0 && (
{sortedVolumes?.length === 0 && (
<tr>
<td colSpan={4} className="text-secondary text-center">
No volumes found.
@@ -262,20 +315,53 @@ export default function Synology({ user: _user }: { user: CurrentUser }) {
<div className="card">
<div className="card-header">
<h3 className="card-title">Disks</h3>
<div className="card-actions">
<button
className="btn btn-sm btn-outline-secondary"
onClick={exportDisksCsv}
disabled={!sortedDisks || sortedDisks.length === 0}
>
Export CSV
</button>
</div>
</div>
<div className="table-responsive">
<table className="table table-vcenter card-table">
<thead>
<tr>
<th>Disk</th>
<th>Device</th>
<th>Temp</th>
<th>S.M.A.R.T.</th>
<th>Status</th>
<SortableTh<SynologyDisk> label="Disk" sortKeyName="name" activeKey={diskSortKey} direction={diskSortDir} onSort={requestDiskSort} />
<SortableTh<SynologyDisk>
label="Device"
sortKeyName="device"
activeKey={diskSortKey}
direction={diskSortDir}
onSort={requestDiskSort}
/>
<SortableTh<SynologyDisk>
label="Temp"
sortKeyName="temp"
activeKey={diskSortKey}
direction={diskSortDir}
onSort={requestDiskSort}
/>
<SortableTh<SynologyDisk>
label="S.M.A.R.T."
sortKeyName="smartStatus"
activeKey={diskSortKey}
direction={diskSortDir}
onSort={requestDiskSort}
/>
<SortableTh<SynologyDisk>
label="Status"
sortKeyName="status"
activeKey={diskSortKey}
direction={diskSortDir}
onSort={requestDiskSort}
/>
</tr>
</thead>
<tbody>
{data?.disks.map((d) => (
{sortedDisks?.map((d) => (
<tr key={d.id}>
<td>{d.name}</td>
<td className="text-secondary">{d.device}</td>
@@ -288,7 +374,7 @@ export default function Synology({ user: _user }: { user: CurrentUser }) {
</td>
</tr>
))}
{data?.disks.length === 0 && (
{sortedDisks?.length === 0 && (
<tr>
<td colSpan={5} className="text-secondary text-center">
No disks found.