fix: coerce accessor key to string during column creation#5808
fix: coerce accessor key to string during column creation#5808schardev wants to merge 2 commits into
Conversation
Co-authored-by: Joao Pedro Henrique <joao.pedro.hsd@gmail.com>
|
WalkthroughThis PR enables support for numeric array indices as Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (3 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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/table-core/src/core/column.ts (1)
115-118: Use normalizedaccessorKeyfor consistency.Line 117 references
resolvedColumnDef.accessorKeydirectly, which could be a number. While JavaScript treatsarr[0]andarr["0"]equivalently, this is inconsistent with lines 85-88, 100, 104, and 108, which all use the normalizedaccessorKeyvariable.Apply this diff to use the normalized variable:
} else { accessorFn = (originalRow: TData) => - (originalRow as any)[resolvedColumnDef.accessorKey] + (originalRow as any)[accessorKey] }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
packages/react-table/tests/core/core.test.tsx(2 hunks)packages/table-core/src/core/column.ts(1 hunks)packages/table-core/src/types.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/react-table/tests/core/core.test.tsx (3)
packages/table-core/src/types.ts (2)
Table(137-152)ColumnDef(328-331)packages/react-table/src/index.tsx (1)
useReactTable(57-94)packages/table-core/src/utils/getCoreRowModel.ts (1)
getCoreRowModel(5-82)
🔇 Additional comments (4)
packages/table-core/src/types.ts (1)
337-337: LGTM! Type change enables numeric accessorKey values.The broadening of
accessorKeyto acceptstring | numbercorrectly supports the use case of numeric array indices. This aligns well with the normalization logic in column.ts that coerces numeric keys to strings.packages/table-core/src/core/column.ts (1)
78-81: LGTM! Normalization logic correctly handles numeric accessorKey.The coercion to string is implemented safely and handles both defined and undefined cases appropriately. This ensures that downstream code using string methods (replace, includes) won't encounter runtime errors.
packages/react-table/tests/core/core.test.tsx (2)
1-1: LGTM! Import enables testing library matchers.The vitest-compatible jest-dom import is necessary for the
.toBeInTheDocument()matcher used in the new test.
268-328: LGTM! Comprehensive test coverage for numeric accessorKey.The test effectively validates the fix for issue #4815 by:
- Using tuple array data with numeric indices (0, 1, 2) as accessorKey values
- Verifying headers render correctly with the expected text
- Verifying body content renders correctly with actual data values
This provides solid coverage for the numeric accessorKey use case.
|
Fixed by: #6434 |
This is based on the PR by @jpedroh (#4835)
fixes #4815
Summary by CodeRabbit
Release Notes
New Features