mirror of
https://github.com/simstudioai/sim.git
synced 2026-04-06 03:00:16 -04:00
fix(resource): sorting
This commit is contained in:
@@ -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])
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user