fix: Improve Assigned To column sorting behavior

Fixed sorting logic for the "Assigned To" column on dashboard:

Problem:
- "Unassigned" was sorted alphabetically with user names
- Appeared randomly in middle of list (after 'S', before 'V')
- Made it hard to find unassigned tickets when sorted

Solution:
- "Unassigned" tickets now always appear at end of list
- Regardless of sort direction (A→Z or Z→A)
- Assigned user names still sort normally among themselves
- Example A→Z: Alice, Bob, Charlie... Unassigned
- Example Z→A: Zack, Yolanda, Xavier... Unassigned

This keeps unassigned tickets grouped together and predictable.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-09 16:38:16 -05:00
parent 837c4baf56
commit 08a73eb84c

View File

@@ -132,7 +132,7 @@ function sortTable(table, column) {
rows.sort((a, b) => { rows.sort((a, b) => {
const aValue = a.children[column].textContent.trim(); const aValue = a.children[column].textContent.trim();
const bValue = b.children[column].textContent.trim(); const bValue = b.children[column].textContent.trim();
// Check if this is a date column // Check if this is a date column
const headerText = headers[column].textContent.toLowerCase(); const headerText = headers[column].textContent.toLowerCase();
if (headerText === 'created' || headerText === 'updated') { if (headerText === 'created' || headerText === 'updated') {
@@ -140,18 +140,36 @@ function sortTable(table, column) {
const dateB = new Date(bValue); const dateB = new Date(bValue);
return currentDirection === 'asc' ? dateA - dateB : dateB - dateA; return currentDirection === 'asc' ? dateA - dateB : dateB - dateA;
} }
// Special handling for "Assigned To" column
if (headerText === 'assigned to') {
const aUnassigned = aValue === 'Unassigned';
const bUnassigned = bValue === 'Unassigned';
// Both unassigned - equal
if (aUnassigned && bUnassigned) return 0;
// Put unassigned at the end regardless of sort direction
if (aUnassigned) return 1;
if (bUnassigned) return -1;
// Otherwise sort names normally
return currentDirection === 'asc'
? aValue.localeCompare(bValue)
: bValue.localeCompare(aValue);
}
// Numeric comparison // Numeric comparison
const numA = parseFloat(aValue); const numA = parseFloat(aValue);
const numB = parseFloat(bValue); const numB = parseFloat(bValue);
if (!isNaN(numA) && !isNaN(numB)) { if (!isNaN(numA) && !isNaN(numB)) {
return currentDirection === 'asc' ? numA - numB : numB - numA; return currentDirection === 'asc' ? numA - numB : numB - numA;
} }
// String comparison // String comparison
return currentDirection === 'asc' return currentDirection === 'asc'
? aValue.localeCompare(bValue) ? aValue.localeCompare(bValue)
: bValue.localeCompare(aValue); : bValue.localeCompare(aValue);
}); });