From 82e279bae99d026c8d911ff0d47d25d56a3de94f Mon Sep 17 00:00:00 2001 From: cstns Date: Wed, 11 Nov 2026 14:08:34 +0200 Subject: [PATCH 1/3] Page through a table's rows in the Tables explorer The explorer only showed the first 10 rows of a table with no way to reach the rest. The grid now has the paging footer the instances list uses, with a rows per page picker, the range being shown out of the table total, and page buttons. The page and page size live in the Tables store so Refresh reloads the current page, and picking another table starts back on the first page. Sorting by clicking a column header is gone for now, since it only reordered the rows on screen. --- docs/user/ff-tables.md | 2 +- frontend/src/api/tables.js | 6 +-- .../TableExplorer/components/RowsList.vue | 34 ++++++++++-- frontend/src/stores/product-tables.js | 21 ++++++-- .../pages/team/Tables/RowsList.spec.js | 53 ++++++++++++++++++- .../frontend/stores/product-tables.spec.js | 46 ++++++++++++++-- 6 files changed, 145 insertions(+), 17 deletions(-) diff --git a/docs/user/ff-tables.md b/docs/user/ff-tables.md index a0c04e4367..3076840805 100644 --- a/docs/user/ff-tables.md +++ b/docs/user/ff-tables.md @@ -22,7 +22,7 @@ Once you have created a database you can use the wizard to create some tables. T ![Screenshot of create tables wizard](./images/tables/create-table-wizard.png){data-zoomable} _Screenshot of create tables wizard_ -Once the tables have data in them then the first 10 rows will be displayed in the Explorer tab. +Once the tables have data in them the rows will be displayed in the Explorer tab, 25 at a time. On a longer table, use the controls under the grid to move between pages or change how many rows are shown per page. ![Screenshot of Tables Explorer](./images/tables/tables-ui-screenshot.png){data-zoomable} _Screenshot of Tables Explorer_ diff --git a/frontend/src/api/tables.js b/frontend/src/api/tables.js index e9dd20bccc..54a30260dd 100644 --- a/frontend/src/api/tables.js +++ b/frontend/src/api/tables.js @@ -21,10 +21,10 @@ const getTableSchema = (teamId, databaseId, tableName, schemaName) => { .then(res => res.data) } -const getTableData = (teamId, databaseId, tableName, schemaName) => { +const getTableData = (teamId, databaseId, tableName, schemaName, { page, limit } = {}) => { const suffix = schemaName ? `/${schemaName}` : '' - return client.get(`/api/v1/teams/${teamId}/databases/${databaseId}/tables/${tableName}/data${suffix}`) - .then(res => res.data.rows) + return client.get(`/api/v1/teams/${teamId}/databases/${databaseId}/tables/${tableName}/data${suffix}`, { params: { page, limit } }) + .then(res => res.data) } const createTable = (teamId, databaseId, payload) => { diff --git a/frontend/src/pages/team/Tables/Table/TableExplorer/components/RowsList.vue b/frontend/src/pages/team/Tables/Table/TableExplorer/components/RowsList.vue index f3b2ba4d78..84ed474240 100644 --- a/frontend/src/pages/team/Tables/Table/TableExplorer/components/RowsList.vue +++ b/frontend/src/pages/team/Tables/Table/TableExplorer/components/RowsList.vue @@ -22,8 +22,11 @@ @@ -53,14 +56,13 @@ export default defineComponent({ name: 'RowsList', components: { EmptyState, PlusIcon }, computed: { - ...mapState(useProductTablesStore, ['tables', 'tableSelection', 'isLoading', 'selectedTable']), + ...mapState(useProductTablesStore, ['tables', 'tableSelection', 'isLoading', 'selectedTable', 'page', 'pageSize']), ...mapState(useContextStore, ['team']), columns () { return (this.selectedTable?.schema ?? []).map((row) => { return { key: row.safeName, html: `${escapeHtml(row.name)} ${escapeHtml(row.type)}`, - sortable: true, component: { is: this.getTableComponent(row.type), extraProps: {}, @@ -80,6 +82,13 @@ export default defineComponent({ }, rows () { return (this.selectedTable?.payload?.safe ?? []) + }, + pagination () { + return { + page: this.page, + pageSize: this.pageSize, + total: this.selectedTable?.payload?.total ?? 0 + } } }, watch: { @@ -104,7 +113,7 @@ export default defineComponent({ this.updateTableSelection(null) }, methods: { - ...mapActions(useProductTablesStore, ['getTableSchema', 'getTableData', 'updateTableSelection']), + ...mapActions(useProductTablesStore, ['getTableSchema', 'getTableData', 'updateTableSelection', 'setPage', 'setPageSize', 'setTableLoadingState']), ...mapActions(useUxDrawersStore, ['openRightDrawer']), onCreateTable () { this.openRightDrawer({ @@ -113,6 +122,25 @@ export default defineComponent({ overlay: true }) }, + onPageChange (page) { + this.setPage(page) + this.loadPage() + }, + onPageSizeChange (pageSize) { + this.setPageSize(pageSize) + this.loadPage() + }, + loadPage () { + this.setTableLoadingState(true) + return this.getTableData({ + teamId: this.team.id, + databaseId: this.$route.params.id, + tableName: this.tableSelection.name, + schemaName: this.tableSelection.dbSchema + }) + .catch(e => e) + .finally(() => this.setTableLoadingState(false)) + }, getTableComponent (type) { const componentMap = { text: TextCell diff --git a/frontend/src/stores/product-tables.js b/frontend/src/stores/product-tables.js index 418eaedbb3..d4c498a1d7 100644 --- a/frontend/src/stores/product-tables.js +++ b/frontend/src/stores/product-tables.js @@ -20,6 +20,8 @@ export const useProductTablesStore = defineStore('product-tables', { databaseSelection: null, tables: {}, tableSelection: null, + page: 1, + pageSize: 25, newTable: { name: '', schema: 'public', columns: [{ ...emptyColumn }] }, isLoading: false }), @@ -63,11 +65,21 @@ export const useProductTablesStore = defineStore('product-tables', { tables = tables.map(({ schema, ...table }) => ({ ...table, dbSchema: schema })) tables = [...tables].sort((a, b) => a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' })) this.tables[databaseId] = tables - if (tables.length > 0) this.tableSelection = { name: tables[0].name, dbSchema: tables[0].dbSchema } + if (tables.length > 0) this.updateTableSelection({ name: tables[0].name, dbSchema: tables[0].dbSchema }) return tables }, clearState () { this.$reset() }, - updateTableSelection (table) { this.tableSelection = table }, + updateTableSelection (table) { + this.tableSelection = table + this.page = 1 + }, + setPage (page) { + this.page = page + }, + setPageSize (pageSize) { + this.pageSize = pageSize + this.page = 1 + }, updateDatabaseSelection (databaseId) { this.databaseSelection = databaseId }, async getTableSchema ({ databaseId, tableName, teamId, schemaName }) { const schema = await tablesApi.getTableSchema(teamId, databaseId, tableName, schemaName) @@ -80,10 +92,11 @@ export const useProductTablesStore = defineStore('product-tables', { }) }, async getTableData ({ databaseId, tableName, teamId, schemaName }) { - const data = await tablesApi.getTableData(teamId, databaseId, tableName, schemaName) + const { rows: data, count: total } = await tablesApi.getTableData(teamId, databaseId, tableName, schemaName, { page: this.page, limit: this.pageSize }) const payload = { data, - safe: data.map(row => Object.fromEntries(Object.entries(row).map(([k, v]) => [hashString(k), v]))) + safe: data.map(row => Object.fromEntries(Object.entries(row).map(([k, v]) => [hashString(k), v]))), + total } Object.keys(this.tables[databaseId]).forEach(key => { const table = this.tables[databaseId][key] diff --git a/test/unit/frontend/pages/team/Tables/RowsList.spec.js b/test/unit/frontend/pages/team/Tables/RowsList.spec.js index 12fc781345..aa4f936098 100644 --- a/test/unit/frontend/pages/team/Tables/RowsList.spec.js +++ b/test/unit/frontend/pages/team/Tables/RowsList.spec.js @@ -1,11 +1,24 @@ import { mount } from '@vue/test-utils' -import { describe, expect, test, vi } from 'vitest' +import { beforeEach, describe, expect, test, vi } from 'vitest' import RowsList from '../../../../../../frontend/src/pages/team/Tables/Table/TableExplorer/components/RowsList.vue' import ForgeUIComponents from '../../../../../../frontend/src/ui-components/index.js' const mocks = vi.hoisted(() => ({ - tablesStore: { tables: {}, tableSelection: null, isLoading: false, selectedTable: null }, + tablesStore: { + tables: {}, + tableSelection: null, + isLoading: false, + selectedTable: null, + page: 1, + pageSize: 25, + setPage: vi.fn(), + setPageSize: vi.fn(), + setTableLoadingState: vi.fn(), + getTableData: vi.fn(() => Promise.resolve()), + getTableSchema: vi.fn(() => Promise.resolve()), + updateTableSelection: vi.fn() + }, contextStore: { team: { id: 't1' } }, drawersStore: { openRightDrawer: vi.fn() } })) @@ -72,4 +85,40 @@ describe('RowsList', () => { expect(mountRowsList().find('[data-el="no-tables"]').exists()).toBe(false) }) }) + + describe('paging', () => { + const schema = [{ name: 'id', safeName: 'col', type: 'bigint' }] + + beforeEach(() => { + vi.clearAllMocks() + mocks.tablesStore.page = 2 + mocks.tablesStore.pageSize = 25 + mocks.tablesStore.tableSelection = { name: 'readings', dbSchema: 'public' } + mocks.tablesStore.selectedTable = { schema, payload: { safe: [{ col: 26 }], total: 1284 } } + }) + + test('shows where the current page sits in the whole table', () => { + const wrapper = mountRowsList() + expect(wrapper.find('[data-el="pagination"]').text()).toContain('26–50 of 1284') + }) + + test('shows no paging controls when the table fits on one page', () => { + mocks.tablesStore.page = 1 + mocks.tablesStore.selectedTable = { schema, payload: { safe: [{ col: 1 }], total: 1 } } + const wrapper = mountRowsList() + expect(wrapper.find('[data-el="pagination"]').exists()).toBe(false) + }) + + test('loads the chosen page for the selected table', async () => { + const wrapper = mountRowsList() + await wrapper.find('[data-action="page-next"]').trigger('click') + expect(mocks.tablesStore.setPage).toHaveBeenCalledWith(3) + expect(mocks.tablesStore.getTableData).toHaveBeenCalledWith({ teamId: 't1', databaseId: 'db1', tableName: 'readings', schemaName: 'public' }) + }) + + test('does not offer to sort by column, since only the current page is loaded', () => { + const wrapper = mountRowsList() + expect(wrapper.find('thead .sortable').exists()).toBe(false) + }) + }) }) diff --git a/test/unit/frontend/stores/product-tables.spec.js b/test/unit/frontend/stores/product-tables.spec.js index 468b3e8fc5..89ecde3714 100644 --- a/test/unit/frontend/stores/product-tables.spec.js +++ b/test/unit/frontend/stores/product-tables.spec.js @@ -193,27 +193,65 @@ describe('product-tables store', () => { }) describe('getTableData', () => { - it('stores data and safe-keyed data on the table', async () => { + it('stores data, safe-keyed data and the table total on the table', async () => { const store = useProductTablesStore() store.tables = { 'db-1': [{ name: 'users' }] } - tablesApi.getTableData.mockResolvedValue([{ id: 1, name: 'Alice' }]) + tablesApi.getTableData.mockResolvedValue({ count: 42, rows: [{ id: 1, name: 'Alice' }] }) await store.getTableData({ databaseId: 'db-1', tableName: 'users', teamId: 'team-1' }) const table = store.tables['db-1'][0] expect(table.payload.data).toEqual([{ id: 1, name: 'Alice' }]) expect(table.payload.safe[0].safe_id).toBe(1) + expect(table.payload.total).toBe(42) + }) + + it('asks for the first page of 25 rows by default', async () => { + const store = useProductTablesStore() + store.tables = { 'db-1': [{ name: 'users' }] } + tablesApi.getTableData.mockResolvedValue({ count: 0, rows: [] }) + await store.getTableData({ databaseId: 'db-1', tableName: 'users', teamId: 'team-1' }) + expect(tablesApi.getTableData).toHaveBeenCalledWith('team-1', 'db-1', 'users', undefined, { page: 1, limit: 25 }) + }) + + it('asks for the current page at the current page size', async () => { + const store = useProductTablesStore() + store.tables = { 'db-1': [{ name: 'users' }] } + tablesApi.getTableData.mockResolvedValue({ count: 0, rows: [] }) + store.setPageSize(50) + store.setPage(3) + await store.getTableData({ databaseId: 'db-1', tableName: 'users', teamId: 'team-1' }) + expect(tablesApi.getTableData).toHaveBeenCalledWith('team-1', 'db-1', 'users', undefined, { page: 3, limit: 50 }) }) it('only updates the table matching both name and schemaName when schemaName is given', async () => { const store = useProductTablesStore() store.tables = { 'db-1': [{ name: 'users', dbSchema: 'public' }, { name: 'users', dbSchema: 'reports' }] } - tablesApi.getTableData.mockResolvedValue([{ id: 1, name: 'Alice' }]) + tablesApi.getTableData.mockResolvedValue({ count: 1, rows: [{ id: 1, name: 'Alice' }] }) await store.getTableData({ databaseId: 'db-1', tableName: 'users', teamId: 'team-1', schemaName: 'reports' }) - expect(tablesApi.getTableData).toHaveBeenCalledWith('team-1', 'db-1', 'users', 'reports') + expect(tablesApi.getTableData).toHaveBeenCalledWith('team-1', 'db-1', 'users', 'reports', { page: 1, limit: 25 }) expect(store.tables['db-1'][0].payload).toBeUndefined() expect(store.tables['db-1'][1].payload.data).toEqual([{ id: 1, name: 'Alice' }]) }) }) + describe('paging', () => { + it('goes back to the first page when the page size changes', () => { + const store = useProductTablesStore() + store.setPage(4) + store.setPageSize(100) + expect(store.pageSize).toBe(100) + expect(store.page).toBe(1) + }) + + it('goes back to the first page when another table is selected, keeping the page size', () => { + const store = useProductTablesStore() + store.setPageSize(50) + store.setPage(4) + store.updateTableSelection({ name: 'orders', dbSchema: 'public' }) + expect(store.page).toBe(1) + expect(store.pageSize).toBe(50) + }) + }) + describe('deleteTable', () => { it('passes schemaName through to the API', async () => { const store = useProductTablesStore() From 9a4efe82fe0c6fd05b5ddb566210664b6f1e899c Mon Sep 17 00:00:00 2001 From: Costin Serban Date: Thu, 12 Nov 2026 10:35:41 +0200 Subject: [PATCH 2/3] Update frontend/src/stores/product-tables.js Co-authored-by: Andrea Palmieri <76187074+andypalmi@users.noreply.github.com> --- frontend/src/stores/product-tables.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/frontend/src/stores/product-tables.js b/frontend/src/stores/product-tables.js index d4c498a1d7..97483e014c 100644 --- a/frontend/src/stores/product-tables.js +++ b/frontend/src/stores/product-tables.js @@ -92,7 +92,14 @@ export const useProductTablesStore = defineStore('product-tables', { }) }, async getTableData ({ databaseId, tableName, teamId, schemaName }) { - const { rows: data, count: total } = await tablesApi.getTableData(teamId, databaseId, tableName, schemaName, { page: this.page, limit: this.pageSize }) + const fetchPage = () => tablesApi.getTableData(teamId, databaseId, tableName, schemaName, { page: this.page, limit: this.pageSize }) + let res = await fetchPage() + const lastPage = Math.max(1, Math.ceil(res.count / this.pageSize)) + if (this.page > lastPage) { + this.page = lastPage + res = await fetchPage() + } + const { rows: data, count: total } = res const payload = { data, safe: data.map(row => Object.fromEntries(Object.entries(row).map(([k, v]) => [hashString(k), v]))), From 2460f77fe39e33d0b107359dc5e537575eab4b71 Mon Sep 17 00:00:00 2001 From: cstns Date: Thu, 12 Nov 2026 10:59:55 +0200 Subject: [PATCH 3/3] Ignore a table page that arrives after a newer one was asked for Clicking two pages quickly could let the older response land last, leaving the grid on one page while the footer showed another, and the first response to arrive turned the loading state off while the other was still on its way. A page response is now dropped when the page or page size changed while it was loading, and only the most recently chosen page clears the loading state. Also adds tests for falling back to the last page when the table shrinks. --- .../TableExplorer/components/RowsList.vue | 6 +- frontend/src/stores/product-tables.js | 15 ++- .../pages/team/Tables/RowsList.spec.js | 20 +++- .../frontend/stores/product-tables.spec.js | 103 ++++++++++++++++++ 4 files changed, 138 insertions(+), 6 deletions(-) diff --git a/frontend/src/pages/team/Tables/Table/TableExplorer/components/RowsList.vue b/frontend/src/pages/team/Tables/Table/TableExplorer/components/RowsList.vue index 84ed474240..a4491b327b 100644 --- a/frontend/src/pages/team/Tables/Table/TableExplorer/components/RowsList.vue +++ b/frontend/src/pages/team/Tables/Table/TableExplorer/components/RowsList.vue @@ -131,6 +131,7 @@ export default defineComponent({ this.loadPage() }, loadPage () { + const load = this.latestPageLoad = {} this.setTableLoadingState(true) return this.getTableData({ teamId: this.team.id, @@ -139,7 +140,10 @@ export default defineComponent({ schemaName: this.tableSelection.dbSchema }) .catch(e => e) - .finally(() => this.setTableLoadingState(false)) + .finally(() => { + // a page picked in the meantime is still loading, so leave the state to it + if (this.latestPageLoad === load) this.setTableLoadingState(false) + }) }, getTableComponent (type) { const componentMap = { diff --git a/frontend/src/stores/product-tables.js b/frontend/src/stores/product-tables.js index 97483e014c..d82f7919a0 100644 --- a/frontend/src/stores/product-tables.js +++ b/frontend/src/stores/product-tables.js @@ -92,12 +92,19 @@ export const useProductTablesStore = defineStore('product-tables', { }) }, async getTableData ({ databaseId, tableName, teamId, schemaName }) { - const fetchPage = () => tablesApi.getTableData(teamId, databaseId, tableName, schemaName, { page: this.page, limit: this.pageSize }) + const pageSize = this.pageSize + let page = this.page + // another page or page size picked while this one was loading makes its rows out of date + const isStale = () => this.page !== page || this.pageSize !== pageSize + const fetchPage = () => tablesApi.getTableData(teamId, databaseId, tableName, schemaName, { page, limit: pageSize }) let res = await fetchPage() - const lastPage = Math.max(1, Math.ceil(res.count / this.pageSize)) - if (this.page > lastPage) { - this.page = lastPage + if (isStale()) return + const lastPage = Math.max(1, Math.ceil(res.count / pageSize)) + if (page > lastPage) { + // the table shrank and this page is gone, so fall back to the last one + page = this.page = lastPage res = await fetchPage() + if (isStale()) return } const { rows: data, count: total } = res const payload = { diff --git a/test/unit/frontend/pages/team/Tables/RowsList.spec.js b/test/unit/frontend/pages/team/Tables/RowsList.spec.js index aa4f936098..7ac35d4ea1 100644 --- a/test/unit/frontend/pages/team/Tables/RowsList.spec.js +++ b/test/unit/frontend/pages/team/Tables/RowsList.spec.js @@ -1,4 +1,4 @@ -import { mount } from '@vue/test-utils' +import { flushPromises, mount } from '@vue/test-utils' import { beforeEach, describe, expect, test, vi } from 'vitest' import RowsList from '../../../../../../frontend/src/pages/team/Tables/Table/TableExplorer/components/RowsList.vue' @@ -116,6 +116,24 @@ describe('RowsList', () => { expect(mocks.tablesStore.getTableData).toHaveBeenCalledWith({ teamId: 't1', databaseId: 'db1', tableName: 'readings', schemaName: 'public' }) }) + test('keeps showing the loading state until the most recently chosen page has loaded', async () => { + const loads = [] + const pendingLoad = () => new Promise(resolve => loads.push(resolve)) + mocks.tablesStore.getTableData.mockImplementationOnce(pendingLoad).mockImplementationOnce(pendingLoad) + const wrapper = mountRowsList() + await wrapper.find('[data-action="page-next"]').trigger('click') + await wrapper.find('[data-action="page-next"]').trigger('click') + expect(loads).toHaveLength(2) + + loads[0]() + await flushPromises() + expect(mocks.tablesStore.setTableLoadingState).not.toHaveBeenCalledWith(false) + + loads[1]() + await flushPromises() + expect(mocks.tablesStore.setTableLoadingState).toHaveBeenLastCalledWith(false) + }) + test('does not offer to sort by column, since only the current page is loaded', () => { const wrapper = mountRowsList() expect(wrapper.find('thead .sortable').exists()).toBe(false) diff --git a/test/unit/frontend/stores/product-tables.spec.js b/test/unit/frontend/stores/product-tables.spec.js index 89ecde3714..99e3c45f7e 100644 --- a/test/unit/frontend/stores/product-tables.spec.js +++ b/test/unit/frontend/stores/product-tables.spec.js @@ -233,6 +233,109 @@ describe('product-tables store', () => { }) }) + describe('getTableData when the table or the page changes underneath it', () => { + const args = { databaseId: 'db-1', tableName: 'users', teamId: 'team-1' } + const deferred = () => { + let resolve + const promise = new Promise(_resolve => { resolve = _resolve }) + return { promise, resolve } + } + + it('falls back to the last page when the table shrank and the current page is gone', async () => { + const store = useProductTablesStore() + store.tables = { 'db-1': [{ name: 'users' }] } + store.setPage(5) + tablesApi.getTableData + .mockResolvedValueOnce({ count: 60, rows: [] }) + .mockResolvedValueOnce({ count: 60, rows: [{ id: 51 }] }) + await store.getTableData(args) + expect(tablesApi.getTableData).toHaveBeenNthCalledWith(1, 'team-1', 'db-1', 'users', undefined, { page: 5, limit: 25 }) + expect(tablesApi.getTableData).toHaveBeenNthCalledWith(2, 'team-1', 'db-1', 'users', undefined, { page: 3, limit: 25 }) + expect(store.page).toBe(3) + expect(store.tables['db-1'][0].payload.data).toEqual([{ id: 51 }]) + expect(store.tables['db-1'][0].payload.total).toBe(60) + }) + + it('falls back to the first page, without asking again and again, when the table is now empty', async () => { + const store = useProductTablesStore() + store.tables = { 'db-1': [{ name: 'users' }] } + store.setPage(4) + tablesApi.getTableData.mockResolvedValue({ count: 0, rows: [] }) + await store.getTableData(args) + expect(tablesApi.getTableData).toHaveBeenCalledTimes(2) + expect(store.page).toBe(1) + expect(store.tables['db-1'][0].payload.data).toEqual([]) + }) + + it('does not ask twice when the current page still exists', async () => { + const store = useProductTablesStore() + store.tables = { 'db-1': [{ name: 'users' }] } + store.setPage(3) + tablesApi.getTableData.mockResolvedValue({ count: 60, rows: [{ id: 51 }] }) + await store.getTableData(args) + expect(tablesApi.getTableData).toHaveBeenCalledTimes(1) + expect(store.page).toBe(3) + }) + + it('ignores a page that arrives after a newer page was asked for', async () => { + const store = useProductTablesStore() + store.tables = { 'db-1': [{ name: 'users' }] } + const page2 = deferred() + const page3 = deferred() + tablesApi.getTableData.mockReturnValueOnce(page2.promise).mockReturnValueOnce(page3.promise) + + store.setPage(2) + const loadingPage2 = store.getTableData(args) + store.setPage(3) + const loadingPage3 = store.getTableData(args) + + page3.resolve({ count: 120, rows: [{ id: 51 }] }) + await loadingPage3 + page2.resolve({ count: 120, rows: [{ id: 26 }] }) + await loadingPage2 + + expect(store.page).toBe(3) + expect(store.tables['db-1'][0].payload.data).toEqual([{ id: 51 }]) + }) + + it('ignores a page that arrives after the page size was changed', async () => { + const store = useProductTablesStore() + store.tables = { 'db-1': [{ name: 'users' }] } + const small = deferred() + const large = deferred() + tablesApi.getTableData.mockReturnValueOnce(small.promise).mockReturnValueOnce(large.promise) + + const loadingSmall = store.getTableData(args) + store.setPageSize(50) + const loadingLarge = store.getTableData(args) + + large.resolve({ count: 120, rows: [{ id: 1 }, { id: 2 }] }) + await loadingLarge + small.resolve({ count: 120, rows: [{ id: 1 }] }) + await loadingSmall + + expect(store.tables['db-1'][0].payload.data).toEqual([{ id: 1 }, { id: 2 }]) + }) + + it('does not move the page back when a stale response reports a smaller table', async () => { + const store = useProductTablesStore() + store.tables = { 'db-1': [{ name: 'users' }] } + const page5 = deferred() + tablesApi.getTableData.mockReturnValueOnce(page5.promise).mockResolvedValueOnce({ count: 120, rows: [{ id: 26 }] }) + + store.setPage(5) + const loadingPage5 = store.getTableData(args) + store.setPage(2) + await store.getTableData(args) + page5.resolve({ count: 10, rows: [] }) + await loadingPage5 + + expect(tablesApi.getTableData).toHaveBeenCalledTimes(2) + expect(store.page).toBe(2) + expect(store.tables['db-1'][0].payload.data).toEqual([{ id: 26 }]) + }) + }) + describe('paging', () => { it('goes back to the first page when the page size changes', () => { const store = useProductTablesStore()