diff --git a/components/incidents/incident-table.tsx b/components/incidents/incident-table.tsx
index 3be87c7..d4ea679 100644
--- a/components/incidents/incident-table.tsx
+++ b/components/incidents/incident-table.tsx
@@ -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 pageCount = Math.max(1, Math.ceil(total / PAGE_SIZE))
- const from = total === 0 ? 0 : (params.page - 1) * PAGE_SIZE + 1
- const to = Math.min(total, from + incidents.length - 1)
+ const from = incidents.length === 0 ? 0 : (params.page - 1) * PAGE_SIZE + 1
+ const to = incidents.length === 0 ? 0 : from + incidents.length - 1
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)
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={{
title: 'No incidents found',
action: ,
diff --git a/tests/components/incidents/incident-table.test.tsx b/tests/components/incidents/incident-table.test.tsx
index 13a2b8f..a0fc00d 100644
--- a/tests/components/incidents/incident-table.test.tsx
+++ b/tests/components/incidents/incident-table.test.tsx
@@ -93,6 +93,21 @@ describe('IncidentTable', () => {
expect(replace).toHaveBeenCalledWith('/hse/incidents?page=2')
})
+ it('hides the footer when there are no results', () => {
+ render()
+ expect(screen.queryByText(/Showing/)).toBeNull()
+ })
+
+ it('shows a sane range on a page past the end', () => {
+ render()
+ expect(screen.getByText('Showing 0–0 of 7')).toBeTruthy()
+ })
+
+ it('shows the range for a partial last page', () => {
+ render()
+ expect(screen.getByText('Showing 26–27 of 27')).toBeTruthy()
+ })
+
it('renders the stacked mobile list', () => {
const { container } = render()
expect(container.querySelector('ul.md\\:hidden')).not.toBeNull()