Skip to content

Commit dc62a08

Browse files
feat: update default sorting to group by server then container ID
- Change default sort field from 'script_name' to 'server_name' - Implement multi-level sorting: server name first, then container ID - Use numeric sorting for container IDs for proper ordering - Maintain existing sorting behavior for other fields - Improves organization by grouping related containers together
1 parent 762d748 commit dc62a08

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

src/app/_components/InstalledScriptsTab.tsx

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function InstalledScriptsTab() {
2929
const [searchTerm, setSearchTerm] = useState('');
3030
const [statusFilter, setStatusFilter] = useState<'all' | 'success' | 'failed' | 'in_progress'>('all');
3131
const [serverFilter, setServerFilter] = useState<string>('all');
32-
const [sortField, setSortField] = useState<'script_name' | 'container_id' | 'server_name' | 'status' | 'installation_date'>('script_name');
32+
const [sortField, setSortField] = useState<'script_name' | 'container_id' | 'server_name' | 'status' | 'installation_date'>('server_name');
3333
const [sortDirection, setSortDirection] = useState<'asc' | 'desc'>('asc');
3434
const [updatingScript, setUpdatingScript] = useState<{ id: number; containerId: string; server?: any } | null>(null);
3535
const [editingScriptId, setEditingScriptId] = useState<number | null>(null);
@@ -225,6 +225,33 @@ export function InstalledScriptsTab() {
225225
return matchesSearch && matchesStatus && matchesServer;
226226
})
227227
.sort((a: InstalledScript, b: InstalledScript) => {
228+
// Default sorting: group by server, then by container ID
229+
if (sortField === 'server_name') {
230+
const aServer = a.server_name ?? 'Local';
231+
const bServer = b.server_name ?? 'Local';
232+
233+
// First sort by server name
234+
if (aServer !== bServer) {
235+
return sortDirection === 'asc' ?
236+
aServer.localeCompare(bServer) :
237+
bServer.localeCompare(aServer);
238+
}
239+
240+
// If same server, sort by container ID
241+
const aContainerId = a.container_id ?? '';
242+
const bContainerId = b.container_id ?? '';
243+
244+
if (aContainerId !== bContainerId) {
245+
// Convert to numbers for proper numeric sorting
246+
const aNum = parseInt(aContainerId) || 0;
247+
const bNum = parseInt(bContainerId) || 0;
248+
return sortDirection === 'asc' ? aNum - bNum : bNum - aNum;
249+
}
250+
251+
return 0;
252+
}
253+
254+
// For other sort fields, use the original logic
228255
let aValue: any;
229256
let bValue: any;
230257

@@ -237,10 +264,6 @@ export function InstalledScriptsTab() {
237264
aValue = a.container_id ?? '';
238265
bValue = b.container_id ?? '';
239266
break;
240-
case 'server_name':
241-
aValue = a.server_name ?? 'Local';
242-
bValue = b.server_name ?? 'Local';
243-
break;
244267
case 'status':
245268
aValue = a.status;
246269
bValue = b.status;

0 commit comments

Comments
 (0)