Skip to content

Commit fd84a06

Browse files
committed
feat: add result panel pagination
1 parent c3b444a commit fd84a06

14 files changed

Lines changed: 572 additions & 42 deletions

‎DESIGN.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ Interactive components must cover default, hover, focus-visible, active / select
234234
### SQL editor and result grids
235235

236236
- Keep the result-set selector inside the existing result toolbar. Collapse secondary export actions into a menu at narrow panel widths to preserve a single toolbar row.
237+
- Result grids page the returned rows locally, starting at 100 rows per page. Keep first / previous / next / last, direct page entry, page size, and the row range in the footer. Wrap footer groups at narrow widths; keep navigation reachable for empty results and disable it while loading or showing an error. Copy / export all retains its full returned-result scope. See [RESULT_PAGINATION_DESIGN.md](docs/RESULT_PAGINATION_DESIGN.md).
237238
- Keep Monaco's theme integration (currently `vs / vs-dark`) and user font-size settings. Syntax highlighting is outside the application decoration color budget; reducing colors must not damage syntax recognition.
238239
- Keep data central: neutral headers, subtle hover, stable selection, and clear sorting / filtering indicators. Preserve virtual scrolling; do not rebuild the whole grid for animation.
239240
- Distinguish `NULL`, empty strings, and booleans. Show true / false or equivalent text / symbols; do not default to red / green boolean mapping.

‎docs/GRID_SORT_DESIGN.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ menu disables its sort entries and explains why.
7979

8080
### `DataGrid` (query results)
8181

82-
- `sortedRows` is the single source of truth for rendering, row actions,
83-
copy/export and the status bar.
82+
- `sortedRows` contains the current result page and is the source of truth for
83+
rendering, row actions, selected-row exports, and the status bar. Copy / export
84+
all includes every returned row in execution order. See
85+
[Result Panel Pagination](RESULT_PAGINATION_DESIGN.md).
8486
- Header clicks call `handleHeaderSort`; the context menu is told `sortable`.
8587
- Selection is cleared whenever rows, columns or the sort state change, because
8688
selection is positional.

‎docs/RESULT_PAGINATION_DESIGN.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Result Panel Pagination
2+
3+
Query results are paged locally over the rows returned by the execution command.
4+
Page navigation never executes SQL, so it also works for script results and
5+
statements that cannot be wrapped in a SELECT. Pagination does not reduce the
6+
number of rows fetched by the backend or bypass a SQL LIMIT or driver row limit.
7+
8+
- Start at 100 rows per page. Offer 50, 100, 200, 500, and 1000 rows, a positive
9+
safe-integer custom size, and all returned rows.
10+
- Provide first, previous, next, and last page buttons plus direct page entry.
11+
Enter or blur applies a valid page, numbers past the end clamp to the last page,
12+
and invalid input or Escape restores the current page.
13+
- Display the visible range and total returned rows. Empty results show 0–0 of 0
14+
on page 1 of 1. Truncated results show the loaded count with a limited-result
15+
label rather than claiming a complete database count.
16+
- A page-size change starts at page 1. Replacing results, including a filter
17+
response or new execution, starts at page 1 while retaining the current size.
18+
Switching script results creates a fresh grid with the default page size.
19+
- Sort primitive values within the current page using the existing grid sort
20+
rules. Copy / export all includes the entire returned result in execution
21+
order; selected-row and individual-row actions use the visible page.
22+
- Clear positional selection, row context menus, and row dialogs when the page
23+
changes. Reset vertical scrolling to the top and preserve horizontal scrolling.
24+
- Keep the footer outside the row viewport so it remains visible during loading,
25+
errors, and empty results. Disable controls during loading and errors. Footer
26+
groups wrap in constrained panels; table overflow stays inside the grid.
27+
- Use shared neutral buttons, inputs, and portalled menus. Localize accessible
28+
names and labels in English and Chinese, retaining visible keyboard focus.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/** @jest-environment jsdom */
2+
import { mount } from '@vue/test-utils'
3+
import DataGridPagination from '@/components/grid/DataGridPagination.vue'
4+
5+
jest.mock('vue-i18n', () => ({ useI18n: () => ({ t: (key: string) => key }) }))
6+
jest.mock('@/components/ui/button', () => ({
7+
Button: { template: '<button><slot /></button>' },
8+
}))
9+
jest.mock('@/components/ui/input', () => ({
10+
Input: {
11+
props: ['modelValue'],
12+
emits: ['update:modelValue'],
13+
template: '<input :value="modelValue" @input="$emit(\'update:modelValue\', $event.target.value)">',
14+
},
15+
}))
16+
jest.mock('@/components/ui/dropdown-menu', () => ({
17+
DropdownMenu: { template: '<div><slot /></div>' },
18+
DropdownMenuContent: { template: '<div><slot /></div>' },
19+
DropdownMenuItem: { template: '<button @click="$emit(\'select\')"><slot /></button>' },
20+
DropdownMenuSeparator: { template: '<hr />' },
21+
DropdownMenuTrigger: { template: '<div><slot /></div>' },
22+
}))
23+
24+
const mountPagination = () => mount(DataGridPagination, {
25+
props: { currentPage: 2, pageCount: 5, pageSize: 100, disabled: false },
26+
})
27+
28+
describe('result pagination controls', () => {
29+
it('navigates in all four directions and disables boundary buttons', async () => {
30+
const wrapper = mountPagination()
31+
const action = (name: string) => wrapper.get(`button[aria-label="components.dataGrid.pagination.${name}"]`)
32+
await action('firstPage').trigger('click')
33+
await action('previousPage').trigger('click')
34+
await action('nextPage').trigger('click')
35+
await action('lastPage').trigger('click')
36+
expect(wrapper.emitted('pageChange')).toEqual([[1], [1], [3], [5]])
37+
await wrapper.setProps({ currentPage: 1 })
38+
expect(action('firstPage').attributes('disabled')).toBeDefined()
39+
expect(action('previousPage').attributes('disabled')).toBeDefined()
40+
await wrapper.setProps({ currentPage: 5 })
41+
expect(action('nextPage').attributes('disabled')).toBeDefined()
42+
expect(action('lastPage').attributes('disabled')).toBeDefined()
43+
})
44+
45+
it('validates direct page entry, clamps to the last page, and restores invalid input', async () => {
46+
const wrapper = mountPagination()
47+
const input = wrapper.get('input[aria-label="components.dataGrid.pagination.goToPage"]')
48+
await input.setValue('4')
49+
await input.trigger('keydown', { key: 'Enter' })
50+
expect(wrapper.emitted('pageChange')).toEqual([[4]])
51+
await input.setValue('999')
52+
await input.trigger('blur')
53+
expect(wrapper.emitted('pageChange')?.slice(-1)[0]).toEqual([5])
54+
await input.setValue('1.5')
55+
await input.trigger('keydown', { key: 'Enter' })
56+
expect((input.element as HTMLInputElement).value).toBe('2')
57+
expect(wrapper.emitted('pageChange')).toHaveLength(2)
58+
await input.setValue('')
59+
await input.trigger('blur')
60+
expect((input.element as HTMLInputElement).value).toBe('2')
61+
await input.setValue('4')
62+
await input.trigger('keydown', { key: 'Escape' })
63+
expect((input.element as HTMLInputElement).value).toBe('2')
64+
await wrapper.setProps({ currentPage: 3 })
65+
expect((input.element as HTMLInputElement).value).toBe('3')
66+
})
67+
68+
it('applies valid custom sizes and prevents interaction while disabled', async () => {
69+
const wrapper = mountPagination()
70+
const input = wrapper.get('input[aria-label="components.dataGrid.pagination.customSize"]')
71+
await input.setValue('37')
72+
await wrapper.get('form').trigger('submit')
73+
expect(wrapper.emitted('pageSizeChange')).toEqual([[37]])
74+
await input.setValue('0')
75+
await wrapper.get('form').trigger('submit')
76+
expect(wrapper.emitted('pageSizeChange')).toHaveLength(1)
77+
await wrapper.setProps({ disabled: true })
78+
await input.setValue('50')
79+
await wrapper.get('form').trigger('submit')
80+
expect(wrapper.emitted('pageSizeChange')).toHaveLength(1)
81+
expect(wrapper.findAll('nav > button').every(button => button.attributes('disabled') !== undefined)).toBe(true)
82+
})
83+
})
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/** @jest-environment jsdom */
2+
import { shallowMount } from '@vue/test-utils'
3+
import { DataGrid } from '@/components/grid'
4+
5+
jest.mock('@tauri-apps/api/core', () => ({ invoke: jest.fn() }))
6+
jest.mock('@vueuse/core', () => ({ useResizeObserver: jest.fn() }))
7+
jest.mock('@/composables/useNotifications', () => ({ toast: { error: jest.fn() } }))
8+
jest.mock('@/composables/useDataGridCopy', () => {
9+
const copyUtil = { copyRowsAs: jest.fn(), exportToFile: jest.fn() }
10+
return { useDataGridCopy: () => copyUtil }
11+
})
12+
jest.mock('vue-i18n', () => ({
13+
useI18n: () => ({ t: (key: string, params?: Record<string, unknown>) => `${key} ${JSON.stringify(params ?? {})}` }),
14+
}))
15+
jest.mock('@tanstack/vue-virtual', () => ({
16+
useVirtualizer: (options: { value: { count: number } }) => ({
17+
getTotalSize: () => options.value.count * 32,
18+
getVirtualItems: () => Array.from({ length: options.value.count }, (_, index) => ({ index, size: 32, start: index * 32 })),
19+
}),
20+
}))
21+
jest.mock('@/components/grid/DataGridPagination.vue', () => ({
22+
__esModule: true,
23+
default: { name: 'DataGridPagination', props: ['currentPage', 'pageCount', 'pageSize', 'disabled'], template: '<nav />' },
24+
}))
25+
jest.mock('@/components/grid/EditRowDialog.vue', () => ({ __esModule: true, default: { template: '<div />' } }))
26+
jest.mock('@/components/grid/RowDetailsDialog.vue', () => ({
27+
__esModule: true,
28+
default: { name: 'RowDetailsDialog', props: ['row'], template: '<div />' },
29+
}))
30+
jest.mock('@/components/grid/JsonViewDialog.vue', () => ({ __esModule: true, default: { template: '<div />' } }))
31+
jest.mock('@/components/grid/CellContextMenu.vue', () => ({ __esModule: true, default: { template: '<div />' } }))
32+
jest.mock('@/components/grid/ColumnHeaderContextMenu.vue', () => ({ __esModule: true, default: { template: '<div />' } }))
33+
jest.mock('@/components/grid/BatchActionBar.vue', () => ({ __esModule: true, default: { template: '<div />' } }))
34+
jest.mock('@/components/grid/FilterBar.vue', () => ({ __esModule: true, default: { template: '<div />' } }))
35+
jest.mock('@/components/ui/button', () => ({ Button: { name: 'Button', template: '<button><slot /></button>' } }))
36+
jest.mock('@/components/ui/checkbox', () => ({ Checkbox: { name: 'Checkbox', template: '<input type="checkbox">' } }))
37+
jest.mock('@/components/ui/dropdown-menu', () => ({}))
38+
jest.mock('@/components/ui/alert-dialog', () => Object.fromEntries(
39+
['AlertDialog', 'AlertDialogAction', 'AlertDialogCancel', 'AlertDialogContent', 'AlertDialogDescription', 'AlertDialogFooter', 'AlertDialogHeader', 'AlertDialogTitle']
40+
.map(name => [name, { name, template: '<div><slot /></div>' }]),
41+
))
42+
43+
const rows = Array.from({ length: 235 }, (_, id) => ({ id: 235 - id }))
44+
const mountGrid = () => shallowMount(DataGrid, {
45+
props: { columns: ['id'], rows, rowCount: rows.length, columnTypes: { id: 'integer' } },
46+
global: { renderStubDefaultSlot: true, mocks: { $t: (key: string) => key } },
47+
})
48+
49+
describe('paged result grid', () => {
50+
it('renders the requested page and sorts only its rows without mutating the result', async () => {
51+
const wrapper = mountGrid()
52+
const pagination = wrapper.findComponent({ name: 'DataGridPagination' })
53+
expect(wrapper.findAll('[data-index]')).toHaveLength(100)
54+
expect(pagination.props('pageCount')).toBe(3)
55+
pagination.vm.$emit('pageChange', 3)
56+
await wrapper.vm.$nextTick()
57+
expect(wrapper.findAll('[data-index]')).toHaveLength(35)
58+
expect(wrapper.find('[data-index="0"]').text()).toContain('35')
59+
expect(wrapper.find('[role="status"]').text()).toContain('"start":201,"end":235,"total":"235"')
60+
const sortHeader = wrapper.findAll('button').find(button => button.text().includes('id'))!
61+
await sortHeader.trigger('click')
62+
expect(wrapper.find('[data-index="0"]').text()).toContain('1')
63+
expect(rows[0].id).toBe(235)
64+
expect(rows[200].id).toBe(35)
65+
const { invoke } = jest.requireMock('@tauri-apps/api/core')
66+
expect(invoke).not.toHaveBeenCalled()
67+
})
68+
69+
it('resets selection and scroll when changing pages', async () => {
70+
const wrapper = mountGrid()
71+
const firstRow = wrapper.get('[data-index="0"]')
72+
firstRow.findComponent({ name: 'Checkbox' }).vm.$emit('update:checked', true)
73+
await wrapper.vm.$nextTick()
74+
expect(wrapper.get('[data-index="0"]').classes()).toContain('bg-primary/[0.08]')
75+
const scroller = wrapper.find('.overflow-auto').element as HTMLDivElement
76+
scroller.scrollTop = 320
77+
wrapper.findComponent({ name: 'DataGridPagination' }).vm.$emit('pageChange', 2)
78+
await wrapper.vm.$nextTick()
79+
expect(scroller.scrollTop).toBe(0)
80+
expect(wrapper.get('[data-index="0"]').classes()).not.toContain('bg-primary/[0.08]')
81+
expect(wrapper.get('[data-index="0"]').text()).toContain('135')
82+
})
83+
84+
it('copies and exports every returned row while viewing a later page', async () => {
85+
const wrapper = mountGrid()
86+
wrapper.findComponent({ name: 'DataGridPagination' }).vm.$emit('pageChange', 3)
87+
await wrapper.vm.$nextTick()
88+
const buttons = wrapper.findAllComponents({ name: 'Button' })
89+
buttons[0].vm.$emit('click')
90+
buttons[3].vm.$emit('click')
91+
const copyUtil = jest.requireMock('@/composables/useDataGridCopy').useDataGridCopy()
92+
expect(copyUtil.copyRowsAs).toHaveBeenCalledWith(rows, ['id'], 'csv', undefined)
93+
expect(copyUtil.exportToFile).toHaveBeenCalledWith(rows, ['id'], 'csv', undefined)
94+
await wrapper.setProps({ truncated: true })
95+
expect(wrapper.get('[role="status"]').text()).toContain('status.showingLimited')
96+
expect(wrapper.get('[role="status"]').text()).toContain('"start":201,"end":235,"loaded":"235"')
97+
})
98+
99+
it('shows all rows and resets to the first page when results are replaced', async () => {
100+
const wrapper = mountGrid()
101+
const pagination = wrapper.findComponent({ name: 'DataGridPagination' })
102+
pagination.vm.$emit('pageSizeChange', 'all')
103+
await wrapper.vm.$nextTick()
104+
expect(wrapper.findAll('[data-index]')).toHaveLength(235)
105+
pagination.vm.$emit('pageSizeChange', 50)
106+
pagination.vm.$emit('pageChange', 4)
107+
await wrapper.vm.$nextTick()
108+
expect(pagination.props('currentPage')).toBe(4)
109+
await wrapper.setProps({ rows: [{ id: 7 }], rowCount: 1 })
110+
expect(pagination.props('currentPage')).toBe(1)
111+
expect(pagination.props('pageSize')).toBe(50)
112+
expect(wrapper.findAll('[data-index]')).toHaveLength(1)
113+
await wrapper.setProps({ rows: [], rowCount: 0 })
114+
expect(pagination.exists()).toBe(true)
115+
expect(wrapper.get('[role="status"]').text()).toContain('"start":0,"end":0,"total":"0"')
116+
await wrapper.setProps({ loading: true })
117+
expect(pagination.props('disabled')).toBe(true)
118+
await wrapper.setProps({ loading: false, error: 'Failed' })
119+
expect(pagination.props('disabled')).toBe(true)
120+
})
121+
})
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { effectScope, nextTick, ref } from 'vue'
2+
import { useDataGridPagination } from '@/composables/useDataGridPagination'
3+
4+
const makeRows = (count: number) => Array.from({ length: count }, (_, id) => ({ id }))
5+
6+
describe('result pagination', () => {
7+
it('covers every row exactly once, including a partial last page', () => {
8+
const rows = ref(makeRows(235))
9+
const scope = effectScope()
10+
const pagination = scope.run(() => useDataGridPagination(rows))!
11+
expect(pagination.pageCount.value).toBe(3)
12+
expect(pagination.pageRows.value).toEqual(rows.value.slice(0, 100))
13+
pagination.setPage(2)
14+
expect(pagination.offset.value).toBe(100)
15+
expect(pagination.pageRows.value).toEqual(rows.value.slice(100, 200))
16+
pagination.setPage(3)
17+
expect(pagination.pageRows.value).toEqual(rows.value.slice(200))
18+
pagination.setPage(999)
19+
expect(pagination.currentPage.value).toBe(3)
20+
pagination.setPage(-1)
21+
expect(pagination.currentPage.value).toBe(1)
22+
scope.stop()
23+
})
24+
25+
it('supports custom sizes and all rows, resetting the page when size changes', () => {
26+
const rows = ref(makeRows(200))
27+
const scope = effectScope()
28+
const pagination = scope.run(() => useDataGridPagination(rows))!
29+
pagination.setPage(2)
30+
pagination.setPageSize(37)
31+
expect(pagination.currentPage.value).toBe(1)
32+
expect(pagination.pageCount.value).toBe(6)
33+
expect(pagination.pageRows.value).toHaveLength(37)
34+
pagination.setPageSize('all')
35+
expect(pagination.pageCount.value).toBe(1)
36+
expect(pagination.pageRows.value).toEqual(rows.value)
37+
pagination.setPageSize(100)
38+
expect(pagination.pageCount.value).toBe(2)
39+
expect(pagination.pageRows.value).toHaveLength(100)
40+
scope.stop()
41+
})
42+
43+
it('ignores unsafe and invalid sizes and page numbers', () => {
44+
const scope = effectScope()
45+
const pagination = scope.run(() => useDataGridPagination(ref(makeRows(235))))!
46+
;[0, -1, 1.5, Number.NaN, Number.POSITIVE_INFINITY, Number.MAX_SAFE_INTEGER + 1].forEach((size) => {
47+
pagination.setPageSize(size)
48+
expect(pagination.pageSize.value).toBe(100)
49+
})
50+
;[1.5, Number.NaN, Number.POSITIVE_INFINITY, Number.MAX_SAFE_INTEGER + 1].forEach((page) => {
51+
pagination.setPage(page)
52+
expect(pagination.currentPage.value).toBe(1)
53+
})
54+
scope.stop()
55+
})
56+
57+
it('resets when results are replaced and handles zero rows or shrinking results', async () => {
58+
const rows = ref(makeRows(235))
59+
const scope = effectScope()
60+
const pagination = scope.run(() => useDataGridPagination(rows))!
61+
pagination.setPage(3)
62+
rows.value = makeRows(235)
63+
expect(pagination.currentPage.value).toBe(1)
64+
pagination.setPage(3)
65+
rows.value = []
66+
expect(pagination.currentPage.value).toBe(1)
67+
expect(pagination.pageCount.value).toBe(1)
68+
expect(pagination.pageRows.value).toEqual([])
69+
rows.value = makeRows(235)
70+
pagination.setPage(3)
71+
rows.value.length = 50
72+
await nextTick()
73+
expect(pagination.currentPage.value).toBe(1)
74+
expect(pagination.pageRows.value).toHaveLength(50)
75+
scope.stop()
76+
})
77+
})

‎src/components/database-browser/QueryResultPanel.vue‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { invoke } from '@tauri-apps/api/core'
88
import { computed, ref, watch } from 'vue'
99
import { useI18n } from 'vue-i18n'
1010
import { ExplainPlanPanel } from '@/components/explain-plan'
11-
import DataGrid from '@/components/grid/DataGrid.vue'
11+
import { DataGrid } from '@/components/grid'
1212
import { Button } from '@/components/ui/button'
1313
import {
1414
DropdownMenu,
@@ -481,6 +481,7 @@ const handleExport = (action: typeof exportActions[number]) => {
481481
:column-types="displayColumnTypes"
482482
:rows="displayResults.rows"
483483
:row-count="displayResults.rows.length"
484+
:truncated="displayResults.truncated"
484485
:execution-time-ms="displayExecutionTime"
485486
:connection-id="connectionId"
486487
:database="database"

0 commit comments

Comments
 (0)