Fix paginationConfigs type in useCioPlp to match CioPlpGrid#240
Fix paginationConfigs type in useCioPlp to match CioPlpGrid#240
Conversation
CDX-425 (#230) retyped CioPlpGridProps.paginationConfigs from Omit<UsePaginationProps, 'totalNumResults'> to Omit<PaginationProps, 'totalNumResults'> so consumers could pass useAnchors, but the parallel declaration on UseCioPlpProps was missed. Headless consumers of useCioPlp couldn't pass useAnchors without a TS error. Retype to restore parity.
There was a problem hiding this comment.
Pull request overview
This PR aligns the public paginationConfigs type exposed by the headless useCioPlp hook with the CioPlpGrid component, so consumers can pass useAnchors (added in #230) without TypeScript errors.
Changes:
- Update
UseCioPlpProps.paginationConfigstoOmit<PaginationProps, 'totalNumResults'>to matchCioPlpGrid. - Add JSDoc documentation for
useAnchors/ v2 deprecation note to keep IntelliSense consistent. - Remove the now-unused
UsePaginationPropsimport fromuseCioPlp.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Mudaafi
left a comment
There was a problem hiding this comment.
lgtm just some code placements
| expect(mockPagination.mock.calls[0][0]).toEqual( | ||
| expect.objectContaining({ useAnchors: true, windowSize: 7 }), | ||
| ); |
This reverts commit 7caa1df.
There was a problem hiding this comment.
Code Review
This PR fixes a type mismatch between UseCioPlpProps.paginationConfigs and CioPlpGridProps.paginationConfigs by upgrading the former to use Omit<PaginationProps, 'totalNumResults'>, and adds integration tests verifying paginationConfigs forwarding.
Inline comments: 3 discussions added
Overall Assessment:
|
|
||
| await waitFor(() => { | ||
| expect(mockPagination).toHaveBeenCalled(); | ||
| expect(mockPagination.mock.calls[0][0]).toEqual( |
There was a problem hiding this comment.
Suggestion: mockPagination.mock.calls[0][0] is fragile — it asserts against the first call, but the Pagination component may render multiple times (e.g. initial render before data loads, then after). If a render cycle changes, this index silently tests the wrong invocation. Prefer mockPagination.mock.lastCall[0] or collect all calls and assert the last one:
const lastCallProps = mockPagination.mock.calls[mockPagination.mock.calls.length - 1][0];
expect(lastCallProps).toEqual(expect.objectContaining({ useAnchors: true, windowSize: 7 }));This applies to both the CioPlpGrid-level and CioPlp-level tests.
| }); | ||
| }); | ||
|
|
||
| it('Should forward paginationConfigs to the Pagination component when passed at CioPlp level', async () => { |
There was a problem hiding this comment.
Important Issue: This test passes paginationConfigs at the <CioPlp> level and asserts that the <Pagination> component receives those props. However, <CioPlp> forwards paginationConfigs to <CioPlpGrid>, which then spreads it directly onto <Pagination> — it does not flow through useCioPlp. This test therefore does not validate the scenario described in the PR description (a user calling useCioPlp({ paginationConfigs: { useAnchors: true } }) directly from the headless hook). A dedicated test for the headless hook path (e.g. a useCioPlp.test or a CioPlp test that renders custom children using the hook) would be needed to prove the type fix has the intended runtime effect.
Pull Request Checklist
Before you submit a pull request, please make sure you have to following:
PR Type
What kind of change does this PR introduce?
What's up
Tiny follow-up to #230 (CDX-425). That PR added
useAnchorsonPaginationPropsand updatedCioPlpGridProps.paginationConfigsto useOmit<PaginationProps, 'totalNumResults'>— but the twin declaration onUseCioPlpPropsgot left on the oldUsePaginationPropstype. So if you use the headlessuseCioPlphook directly and try to passpaginationConfigs={{ useAnchors: true }}, TS yells at you even though<Pagination>happily accepts it.This bumps
useCioPlp'spaginationConfigsto the same type so the two public surfaces match. Also copied over the JSDoc bit aboutuseAnchors/ the v2 deprecation note fromCioPlpGridso IntelliSense stays consistent.Notes
PaginationPropsis a strict superset ofUsePaginationProps(just adds optionaluseAnchors), so nothing breaks for existing consumers.useAnchorsruntime path is already covered by thePaginationspecs added in [CDX-425] Add seo friendly anchor based pagination #230.