fix(design): correct the incident list footer range on empty and out-of-range pages

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-01 09:43:44 +08:00
co-authored by Claude Haiku 4.5
parent 582504c24b
commit 87f553321b
2 changed files with 18 additions and 3 deletions
+3 -3
View File
@@ -82,8 +82,8 @@ export function IncidentTable({ incidents, basePath, total, counts, params, site
const clearable = Boolean(params.q || params.status || params.type || params.siteId || params.truckId) const clearable = Boolean(params.q || params.status || params.type || params.siteId || params.truckId)
const pageCount = Math.max(1, Math.ceil(total / PAGE_SIZE)) const pageCount = Math.max(1, Math.ceil(total / PAGE_SIZE))
const from = total === 0 ? 0 : (params.page - 1) * PAGE_SIZE + 1 const from = incidents.length === 0 ? 0 : (params.page - 1) * PAGE_SIZE + 1
const to = Math.min(total, from + incidents.length - 1) const to = incidents.length === 0 ? 0 : from + incidents.length - 1
const toolbar = ( const toolbar = (
<> <>
@@ -161,7 +161,7 @@ export function IncidentTable({ incidents, basePath, total, counts, params, site
const next = nextSort({ key: params.sort, dir: params.dir }, key as SortKey) const next = nextSort({ key: params.sort, dir: params.dir }, key as SortKey)
update({ sort: next.key, dir: next.dir }) update({ sort: next.key, dir: next.dir })
}} }}
footer={{ from, to, total, page: params.page, pageCount, onPage: p => update({ page: String(p) }) }} footer={total > 0 ? { from, to, total, page: params.page, pageCount, onPage: p => update({ page: String(p) }) } : undefined}
empty={{ empty={{
title: 'No incidents found', title: 'No incidents found',
action: <Button onClick={() => router.push('/report')}>Report incident</Button>, action: <Button onClick={() => router.push('/report')}>Report incident</Button>,
@@ -93,6 +93,21 @@ describe('IncidentTable', () => {
expect(replace).toHaveBeenCalledWith('/hse/incidents?page=2') expect(replace).toHaveBeenCalledWith('/hse/incidents?page=2')
}) })
it('hides the footer when there are no results', () => {
render(<IncidentTable {...props} incidents={[]} total={0} counts={{ all: 0, open: 0, closed: 0 }} />)
expect(screen.queryByText(/Showing/)).toBeNull()
})
it('shows a sane range on a page past the end', () => {
render(<IncidentTable {...props} incidents={[]} total={7} params={{ ...props.params, page: 2 }} />)
expect(screen.getByText('Showing 0–0 of 7')).toBeTruthy()
})
it('shows the range for a partial last page', () => {
render(<IncidentTable {...props} total={27} params={{ ...props.params, page: 2 }} />)
expect(screen.getByText('Showing 26–27 of 27')).toBeTruthy()
})
it('renders the stacked mobile list', () => { it('renders the stacked mobile list', () => {
const { container } = render(<IncidentTable {...props} />) const { container } = render(<IncidentTable {...props} />)
expect(container.querySelector('ul.md\\:hidden')).not.toBeNull() expect(container.querySelector('ul.md\\:hidden')).not.toBeNull()