feat (DataTable): add getRowId support to get unique row key#690
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughAdded a new optional Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/raystack/components/data-table/__tests__/data-table.test.tsx`:
- Around line 579-593: The test's getRowKey callback returns a number
(TestData.id is typed number) but the DataTable.getRowKey prop expects a string;
fix by aligning types: change the TestData.id type to string or update the
getRowKey return type/signature to accept number (or cast the returned id to
string) so the TypeScript error is resolved, locating this in the test where
TestData is defined and where DataTable is rendered with getRowKey; additionally
add a focused assertion that verifies stable keys behavior (e.g., capture row
key values before and after a sort or re-render and assert they remain
consistent) to validate stable row identity.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 800a5a24-46f5-47c0-a3d9-329303c6c3be
📒 Files selected for processing (5)
apps/www/src/content/docs/components/datatable/index.mdxapps/www/src/content/docs/components/datatable/props.tspackages/raystack/components/data-table/__tests__/data-table.test.tsxpackages/raystack/components/data-table/data-table.tsxpackages/raystack/components/data-table/data-table.types.tsx
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/raystack/components/data-table/data-table.tsx`:
- Around line 122-128: The table currently passes the consumer-provided getRowId
directly into useReactTable while groupedData contains synthetic
GroupedData<TData> rows; wrap getRowId with a function that detects group header
rows (presence of subRows or group_key) and returns a stable synthetic id (e.g.,
derived from group_key and an index or prefix like `group-${group_key}`) for
those, and otherwise delegates to the original getRowId for leaf rows; locate
the useReactTable call and replace the getRowId argument with this wrapper so
GroupedData headers get unique, stable IDs while real TData rows still use the
consumer callback.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a6510b72-afd0-46c4-a308-119272e7e244
📒 Files selected for processing (5)
apps/www/src/content/docs/components/datatable/index.mdxapps/www/src/content/docs/components/datatable/props.tspackages/raystack/components/data-table/__tests__/data-table.test.tsxpackages/raystack/components/data-table/data-table.tsxpackages/raystack/components/data-table/data-table.types.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
- apps/www/src/content/docs/components/datatable/props.ts
- apps/www/src/content/docs/components/datatable/index.mdx
Description
Issue
With sorting, grouping, or filtering, rows could get wrong React keys and cause rendering issues.
Usage
Fix
getRowId?: (row: TData, index: number) => string.It’s passed through as TanStack’s
getRowId, so each row can have a stable key (e.g.getRowId={row => row.id}).Type of Change
How Has This Been Tested?
[Describe the tests that you ran to verify your changes]
Checklist:
Screenshots (if appropriate):
[Add screenshots here]
Related Issues
[Link any related issues here using #issue-number]
Summary by CodeRabbit
New Features
Documentation
Tests