refactor(react-virtualized-helpers): migrate withInfiniteLoader from … - #4744
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds the ChangesInfinite loader helper
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested labels: Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant Consumer
participant withInfiniteLoader
participant InfiniteLoader
participant WrappedComponent
Consumer->>withInfiniteLoader: provide loader configuration and component props
withInfiniteLoader->>InfiniteLoader: render with loader configuration
InfiniteLoader->>WrappedComponent: inject onRowsRendered and registerChild
withInfiniteLoader->>WrappedComponent: forward remaining props
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/components/react-virtualized-helpers/withInfiniteLoader.tsx (1)
12-16: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse concrete callback signatures for
InfiniteLoaderConfig.Replace
isRowLoaded: FunctionandloadMoreRows: Functionwith theInfiniteLoadercallback signatures:(index: number) => booleanand(startIndex: number, stopIndex: number) => PromiseLike<unknown>.This keeps the public configuration API type-safe from unrelated callbacks and missing return values.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/components/react-virtualized-helpers/withInfiniteLoader.tsx` around lines 12 - 16, In the InfiniteLoaderConfig interface, replace the generic Function types for the isRowLoaded and loadMoreRows properties with concrete callback signatures. Update isRowLoaded to use (index: number) => boolean and loadMoreRows to use (startIndex: number, stopIndex: number) => PromiseLike<unknown>. This ensures the configuration API enforces type safety and prevents callbacks with incorrect signatures or missing return values from being accepted.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/components/react-virtualized-helpers/withInfiniteLoader.tsx`:
- Around line 12-16: In the InfiniteLoaderConfig interface, replace the generic
Function types for the isRowLoaded and loadMoreRows properties with concrete
callback signatures. Update isRowLoaded to use (index: number) => boolean and
loadMoreRows to use (startIndex: number, stopIndex: number) =>
PromiseLike<unknown>. This ensures the configuration API enforces type safety
and prevents callbacks with incorrect signatures or missing return values from
being accepted.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: f10fe41d-f93c-4301-a5fa-410a807a3a85
📒 Files selected for processing (5)
src/components/react-virtualized-helpers/__tests__/withInfiniteLoader.test.tsxsrc/components/react-virtualized-helpers/index.js.flowsrc/components/react-virtualized-helpers/index.tssrc/components/react-virtualized-helpers/withInfiniteLoader.js.flowsrc/components/react-virtualized-helpers/withInfiniteLoader.tsx
caaa911 to
9811f57
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/components/react-virtualized-helpers/withInfiniteLoader.tsx (1)
38-58: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winTighten
WithInfiniteLoaderPropsto avoid the unsafe double cast.The
[key: string]: unknownindex signature onWithInfiniteLoaderProps(Line 40) makesrestat Line 58 lose its connection toP, which is why the code needsrest as unknown as P. This double cast bypasses type checking for every pass-through prop, so a mismatch betweenrestandPat the call site would not be caught by the compiler. This directly follows up on the past review feedback about avoiding overly loose types, this time on the props side rather than the function-signature side.Remove the catch-all index signature and let
resttype naturally asOmit<P, keyof WithOnRowsRendered>, which lets the spread type-check without anunknowndetour.💡 Proposed refactor to remove the catch-all index signature
export interface WithInfiniteLoaderProps { - /** Properties passed through to the wrapped component. */ - [key: string]: unknown; /** Configuration passed to the react-virtualized InfiniteLoader. */ infiniteLoaderProps: InfiniteLoaderConfig; } function withInfiniteLoader<P extends WithOnRowsRendered>(WrappedComponent: React.ComponentClass<P>) { const InfiniteLoaderComponent = ({ infiniteLoaderProps: { isRowLoaded, loadMoreRows, minimumBatchSize, rowCount, threshold }, ...rest }: WithInfiniteLoaderProps & Omit<P, keyof WithOnRowsRendered>) => ( <InfiniteLoader isRowLoaded={isRowLoaded} loadMoreRows={loadMoreRows} minimumBatchSize={minimumBatchSize} rowCount={rowCount} threshold={threshold} > {({ onRowsRendered, registerChild }) => ( - <WrappedComponent {...(rest as unknown as P)} ref={registerChild} onRowsRendered={onRowsRendered} /> + <WrappedComponent {...(rest as Omit<P, keyof WithOnRowsRendered>)} ref={registerChild} onRowsRendered={onRowsRendered} /> )} </InfiniteLoader> );🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/components/react-virtualized-helpers/withInfiniteLoader.tsx` around lines 38 - 58, Remove the catch-all string index signature from WithInfiniteLoaderProps and type the component props so the destructured rest value is Omit<P, keyof WithOnRowsRendered>. Update the WrappedComponent render in withInfiniteLoader to spread rest directly, eliminating the unsafe unknown double cast while preserving the existing InfiniteLoader props and ref/onRowsRendered wiring.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/components/react-virtualized-helpers/withInfiniteLoader.tsx`:
- Around line 38-58: Remove the catch-all string index signature from
WithInfiniteLoaderProps and type the component props so the destructured rest
value is Omit<P, keyof WithOnRowsRendered>. Update the WrappedComponent render
in withInfiniteLoader to spread rest directly, eliminating the unsafe unknown
double cast while preserving the existing InfiniteLoader props and
ref/onRowsRendered wiring.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 9174d11f-feb7-44b2-b276-717ad24646a9
📒 Files selected for processing (5)
src/components/react-virtualized-helpers/__tests__/withInfiniteLoader.test.tsxsrc/components/react-virtualized-helpers/index.js.flowsrc/components/react-virtualized-helpers/index.tssrc/components/react-virtualized-helpers/withInfiniteLoader.js.flowsrc/components/react-virtualized-helpers/withInfiniteLoader.tsx
🚧 Files skipped from review as they are similar to previous changes (4)
- src/components/react-virtualized-helpers/index.js.flow
- src/components/react-virtualized-helpers/index.ts
- src/components/react-virtualized-helpers/withInfiniteLoader.js.flow
- src/components/react-virtualized-helpers/tests/withInfiniteLoader.test.tsx
9811f57 to
8ca8023
Compare
8ca8023 to
b9d91d7
Compare
jpan-box
left a comment
There was a problem hiding this comment.
LGTM — prior feedback addressed.
…Flow to TypeScript
b9d91d7 to
c1fd5d7
Compare
Merge Queue Status
This pull request spent 12 seconds in the queue, including 1 second running CI. Required conditions to merge
|
Convert
withInfiniteLoaderto TypeScriptThis PR converts
src/components/react-virtualized-helpersfrom Flow to TypeScript.Changes
withInfiniteLoader.jsto TypeScript with exported interfaces.js.flowfiles for backward compatibilityTesting
yarn lintpassesyarn flow checkpasses with 0 errorsSummary by CodeRabbit
New Features
Tests