fix(resource): sorting

This commit is contained in:
Emir Karabeg
2026-03-07 21:26:54 -08:00
parent 8170488488
commit 77bd2553f2
5 changed files with 31 additions and 5 deletions

View File

@@ -20,6 +20,7 @@ export interface ResourceCell {
export interface ResourceRow {
id: string
cells: Record<string, ResourceCell>
sortValues?: Record<string, string | number>
}
interface ResourceProps {
@@ -85,16 +86,20 @@ export function Resource({
const handleColumnSort = useCallback((columnId: string) => {
setSort((prev) => {
if (prev.column !== columnId) return { column: columnId, direction: 'asc' }
return { column: columnId, direction: prev.direction === 'asc' ? 'desc' : 'asc' }
if (prev.column !== columnId) return { column: columnId, direction: 'desc' }
return { column: columnId, direction: prev.direction === 'desc' ? 'asc' : 'desc' }
})
}, [])
const sortedRows = useMemo(() => {
return [...rows].sort((a, b) => {
const aLabel = a.cells[sort.column]?.label ?? ''
const bLabel = b.cells[sort.column]?.label ?? ''
const cmp = aLabel.localeCompare(bLabel)
const col = sort.column
const aVal = a.sortValues?.[col] ?? a.cells[col]?.label ?? ''
const bVal = b.sortValues?.[col] ?? b.cells[col]?.label ?? ''
const cmp =
typeof aVal === 'number' && typeof bVal === 'number'
? aVal - bVal
: String(aVal).localeCompare(String(bVal))
return sort.direction === 'asc' ? -cmp : cmp
})
}, [rows, sort])

View File

@@ -138,6 +138,11 @@ export function Files() {
owner: ownerCell(file.uploadedBy, members),
updated: timeCell(file.uploadedAt),
},
sortValues: {
size: file.size,
created: -new Date(file.uploadedAt).getTime(),
updated: -new Date(file.uploadedAt).getTime(),
},
}
}),
[filteredFiles, members]

View File

@@ -149,6 +149,12 @@ export function Knowledge() {
owner: ownerCell(kb.userId, members),
updated: timeCell(kb.updatedAt),
},
sortValues: {
documents: kbWithCount.docCount || 0,
tokens: kb.tokenCount || 0,
created: -new Date(kb.createdAt).getTime(),
updated: -new Date(kb.updatedAt).getTime(),
},
}
}),
[filteredKnowledgeBases, members]

View File

@@ -79,6 +79,10 @@ export function Schedules() {
from: { label: isJob ? item.prompt : item.workflowName },
lifecycle: { label: item.cronExpression ? 'Recurring' : 'One-time' },
},
sortValues: {
nextRun: item.nextRunAt ? -new Date(item.nextRunAt).getTime() : 0,
lastRun: item.lastRanAt ? -new Date(item.lastRanAt).getTime() : 0,
},
}
}),
[filteredItems]

View File

@@ -90,6 +90,12 @@ export function Tables() {
owner: ownerCell(table.createdBy, members),
updated: timeCell(table.updatedAt),
},
sortValues: {
columns: table.schema.columns.length,
rows: table.rowCount,
created: -new Date(table.createdAt).getTime(),
updated: -new Date(table.updatedAt).getTime(),
},
})),
[filteredTables, members]
)