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 () => { 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..d09e1370 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' @@ -19,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, @@ -52,8 +53,8 @@ export const LineListPlugin: FC = ({ ...newPagination, }), { - page: FIRST_PAGE, - pageSize: PAGE_SIZE, + page: 1, + pageSize: 100, } ) @@ -62,15 +63,11 @@ export const LineListPlugin: FC = ({ ? visualization.sorting[0] : { dimension: undefined, direction: undefined } - const onPaginate = useCallback(({ page, pageSize }) => { + const onPaginate = 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 }) } }, [])