Records: default to newest first on the source's date field

The page loaded unsorted, so the most recent rows were rarely on screen. On
source change it now looks up the source's first date-typed field and sorts
descending on it, falling back to unsorted when a source has no date field.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Paul Trowbridge 2026-07-26 22:13:30 -04:00
parent ba4e382487
commit 426f975d9c

View File

@ -119,7 +119,14 @@ export default function Records({ source }) {
setPanelOpen(false) setPanelOpen(false)
setOverrideCols([]) setOverrideCols([])
setExtraCols([]) setExtraCols([])
load(0, null, 'asc', []) // Default to newest first on the source's first date field, if it has one
api.getSource(source)
.then(src => (src?.config?.fields || []).find(f => f.type === 'date')?.name || null)
.catch(() => null)
.then(dateCol => {
if (dateCol) setSort({ col: dateCol, dir: 'desc' })
load(0, dateCol, 'desc', [])
})
api.getOverrideKeys(source).then(setOverrideCols).catch(() => {}) api.getOverrideKeys(source).then(setOverrideCols).catch(() => {})
api.getGlobalValues().then(setGlobalValues).catch(() => {}) api.getGlobalValues().then(setGlobalValues).catch(() => {})
setSelected(new Set()) setSelected(new Set())