From 45abc5d59decdc333b56aced99c149a09ad47923 Mon Sep 17 00:00:00 2001 From: HendrikThePendric Date: Wed, 24 Sep 2025 16:34:27 +0200 Subject: [PATCH 1/3] refactor: make `page` required in PaginateFn and let StickyNavigation handle page reset --- src/components/line-list/sticky-pagination.tsx | 2 +- src/components/line-list/types.ts | 6 +----- .../plugin-wrapper/line-list-plugin.tsx | 16 ++++++++-------- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/components/line-list/sticky-pagination.tsx b/src/components/line-list/sticky-pagination.tsx index b7864a04..0168f6f8 100644 --- a/src/components/line-list/sticky-pagination.tsx +++ b/src/components/line-list/sticky-pagination.tsx @@ -40,7 +40,7 @@ const StickyPagination = ({ ) const onPageSizeChange = useCallback( (pageSize: number) => { - onPaginate({ pageSize }) + onPaginate({ page: 1, pageSize }) }, [onPaginate] ) diff --git a/src/components/line-list/types.ts b/src/components/line-list/types.ts index aa6aca05..cec2988b 100644 --- a/src/components/line-list/types.ts +++ b/src/components/line-list/types.ts @@ -52,10 +52,6 @@ export type DataSortPayload = { dimension: string direction?: SortDirection } -export type PaginatePayload = { - page?: number - pageSize?: number -} export type DataSortFn = (payload: DataSortPayload) => void -export type PaginateFn = (payload: PaginatePayload) => void +export type PaginateFn = (payload: { page: number; pageSize?: number }) => void export type ColumnHeaderClickFn = (cleanedHeaderName: string) => void diff --git a/src/components/plugin-wrapper/line-list-plugin.tsx b/src/components/plugin-wrapper/line-list-plugin.tsx index 4284ddfa..3a20b212 100644 --- a/src/components/plugin-wrapper/line-list-plugin.tsx +++ b/src/components/plugin-wrapper/line-list-plugin.tsx @@ -4,7 +4,11 @@ import { useLineListAnalyticsData } from './hooks/use-line-list-analytics-data' import type { MetadataInput } from '@components/app-wrapper/metadata-helpers' import { LineList } from '@components/line-list' import type { LineListAnalyticsData } from '@components/line-list' -import type { DataSortFn, DataSortPayload } from '@components/line-list/types' +import type { + DataSortFn, + DataSortPayload, + PaginateFn, +} from '@components/line-list/types' import { transformVisualization } from '@modules/visualization' import type { CurrentUser, CurrentVisualization, SortDirection } from '@types' @@ -62,15 +66,11 @@ export const LineListPlugin: FC = ({ ? visualization.sorting[0] : { dimension: undefined, direction: undefined } - const onPaginate = useCallback(({ page, pageSize }) => { + const onPaginate: PaginateFn = useCallback(({ page, pageSize }) => { if (pageSize) { - setPagination({ page: pageSize ? FIRST_PAGE : page, pageSize }) - } else if (page) { - setPagination({ page }) + setPagination({ page, pageSize }) } else { - throw new Error( - 'onPaginate was called with neither a page nor pageSize. At least one is expected' - ) + setPagination({ page }) } }, []) From 5384afb65b44bdc658876fead6f04736114bde4e Mon Sep 17 00:00:00 2001 From: HendrikThePendric Date: Wed, 24 Sep 2025 16:36:46 +0200 Subject: [PATCH 2/3] test: adjust test to new implementation --- src/components/line-list/__tests__/line-list.spec.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/line-list/__tests__/line-list.spec.tsx b/src/components/line-list/__tests__/line-list.spec.tsx index a90262d2..cf2036c1 100644 --- a/src/components/line-list/__tests__/line-list.spec.tsx +++ b/src/components/line-list/__tests__/line-list.spec.tsx @@ -163,7 +163,7 @@ describe('LineList', () => { ).getByText('50') await user.click(option50) - expect(onPaginate).toHaveBeenCalledWith({ pageSize: 50 }) + expect(onPaginate).toHaveBeenCalledWith({ page: 1, pageSize: 50 }) }) it('displays pagination information correctly', async () => { From bb2d4c68a095f90134b0a2ee397b42452dc713c4 Mon Sep 17 00:00:00 2001 From: HendrikThePendric Date: Thu, 25 Sep 2025 09:29:43 +0200 Subject: [PATCH 3/3] chore: implement pr suggestions --- src/components/plugin-wrapper/line-list-plugin.tsx | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/components/plugin-wrapper/line-list-plugin.tsx b/src/components/plugin-wrapper/line-list-plugin.tsx index 3a20b212..d09e1370 100644 --- a/src/components/plugin-wrapper/line-list-plugin.tsx +++ b/src/components/plugin-wrapper/line-list-plugin.tsx @@ -23,9 +23,6 @@ type LineListPluginProps = { onResponseReceived?: (metadata: MetadataInput) => void } -const FIRST_PAGE: number = 1 -const PAGE_SIZE: number = 100 - export const LineListPlugin: FC = ({ displayProperty, visualization: originalVisualization, @@ -56,8 +53,8 @@ export const LineListPlugin: FC = ({ ...newPagination, }), { - page: FIRST_PAGE, - pageSize: PAGE_SIZE, + page: 1, + pageSize: 100, } ) @@ -66,7 +63,7 @@ export const LineListPlugin: FC = ({ ? visualization.sorting[0] : { dimension: undefined, direction: undefined } - const onPaginate: PaginateFn = useCallback(({ page, pageSize }) => { + const onPaginate = useCallback(({ page, pageSize }) => { if (pageSize) { setPagination({ page, pageSize }) } else {