Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion app/table/QueryTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ export function useQueryTable<TItem>({
(row: TItem) => row.id as string

const { items, isEmpty, pagination, queryResult } = usePaginatedList(query, getRowId)
const isEmptyPage =
items.length === 0 && queryResult.isSuccess && !queryResult.isPlaceholderData

const table = useReactTable({
columns,
Expand All @@ -133,7 +135,13 @@ export function useQueryTable<TItem>({
<TableEmptyBox>{emptyState || <EmptyMessage title="No results" />}</TableEmptyBox>
) : (
<>
<Table table={table} rowHeight={rowHeight} />
{isEmptyPage ? (
<TableEmptyBox>
<EmptyMessage title="No more results" />
</TableEmptyBox>
) : (
<Table table={table} rowHeight={rowHeight} />
)}
{pagination}
</>
)
Expand Down
12 changes: 11 additions & 1 deletion mock-api/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { GiB } from '~/util/units'

import { disks } from './disk'
import type { Json } from './json-type'
import { project } from './project'
import { project, project2 } from './project'

// Use seeded random for consistent states across runs
const rando = new Rando(0)
Expand Down Expand Up @@ -51,6 +51,9 @@ const generatedSnapshots: Json<Snapshot>[] = Array.from({ length: 160 }, (_, i)
generateSnapshot(i)
)

// The disk fixtures seed other-project with disks for pagination tests.
const otherProjectDisk = disks.find((disk) => disk.project_id === project2.id)!

export const snapshots: Json<Snapshot>[] = [
{
id: 'ab805e59-b6b8-4c73-8081-6a224b6b0698',
Expand Down Expand Up @@ -130,4 +133,11 @@ export const snapshots: Json<Snapshot>[] = [
state: 'ready',
},
...generatedSnapshots,
// An exact multiple of the page size allows Next to lead to an empty page.
...generatedSnapshots.slice(0, 50).map((snapshot) => ({
...snapshot,
id: crypto.randomUUID(),
project_id: project2.id,
disk_id: otherProjectDisk.id,
})),
]
19 changes: 19 additions & 0 deletions test/e2e/pagination.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,25 @@ test('pagination', async ({ page }) => {
await expect(spinner).toBeHidden({ timeout: 10 }) // no spinner, cached page
})

test('empty page after a full page of results', async ({ page }) => {
await page.goto('/projects/other-project/snapshots')

const nextButton = page.getByRole('button', { name: 'next' })
const prevButton = page.getByRole('button', { name: 'prev', exact: true })
const emptyMessage = page.getByRole('heading', { name: 'No more results' })

await expectCell(page, 'disk-1-snapshot-8')
await nextButton.click()

await expect(emptyMessage).toBeVisible()
await expect(nextButton).toBeDisabled()
await prevButton.click()

await expectCell(page, 'disk-1-snapshot-8')
await expect(emptyMessage).toBeHidden()
await expect(prevButton).toBeDisabled()
})

// Pagination and full-page form buttons are portaled into the same footer
// element, which is replaced when the layout changes
test('footer content follows navigation', async ({ page }) => {
Expand Down