feat: add defaultValue support in datatable filters#704
feat: add defaultValue support in datatable filters#704rohanchkrabrty wants to merge 1 commit intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughAdded a new Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
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/hooks/useFilters.tsx`:
- Around line 21-26: The fallback for select filters uses options[0].value which
will throw if options is empty; in the useFilters hook replace that direct
access (the expression that chooses between columnDef.defaultFilterValue,
FilterType.date, FilterType.select) with a safe check that only reads
options[0].value when options && options.length > 0, otherwise fall back to an
empty string (or columnDef.defaultFilterValue if present); update the expression
around FilterType.select to use a guarded lookup (e.g., options?.length ?
options[0].value : '') so the code in useFilters.tsx referencing FilterType and
options won't crash when filterOptions is empty.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 18352ba8-5092-48f0-93b1-d6759f468d26
📒 Files selected for processing (3)
apps/www/src/components/datatable-demo.tsxpackages/raystack/components/data-table/data-table.types.tsxpackages/raystack/components/data-table/hooks/useFilters.tsx
| columnDef.defaultFilterValue ?? | ||
| (filterType === FilterType.date | ||
| ? new Date() | ||
| : filterType === FilterType.select | ||
| ? options[0].value | ||
| : ''; | ||
| : ''); |
There was a problem hiding this comment.
Guard select fallback against empty options to prevent runtime error.
At Line 25, options[0].value will throw when filterOptions is empty and no defaultFilterValue is provided. Please make this access safe.
💡 Proposed fix
- const defaultValue =
- columnDef.defaultFilterValue ??
- (filterType === FilterType.date
- ? new Date()
- : filterType === FilterType.select
- ? options[0].value
- : '');
+ const defaultValue =
+ columnDef.defaultFilterValue ??
+ (filterType === FilterType.date
+ ? new Date()
+ : filterType === FilterType.select
+ ? (options[0]?.value ?? '')
+ : '');📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| columnDef.defaultFilterValue ?? | |
| (filterType === FilterType.date | |
| ? new Date() | |
| : filterType === FilterType.select | |
| ? options[0].value | |
| : ''; | |
| : ''); | |
| const defaultValue = | |
| columnDef.defaultFilterValue ?? | |
| (filterType === FilterType.date | |
| ? new Date() | |
| : filterType === FilterType.select | |
| ? (options[0]?.value ?? '') | |
| : ''); |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/raystack/components/data-table/hooks/useFilters.tsx` around lines 21
- 26, The fallback for select filters uses options[0].value which will throw if
options is empty; in the useFilters hook replace that direct access (the
expression that chooses between columnDef.defaultFilterValue, FilterType.date,
FilterType.select) with a safe check that only reads options[0].value when
options && options.length > 0, otherwise fall back to an empty string (or
columnDef.defaultFilterValue if present); update the expression around
FilterType.select to use a guarded lookup (e.g., options?.length ?
options[0].value : '') so the code in useFilters.tsx referencing FilterType and
options won't crash when filterOptions is empty.
Description
This PR adds support for
defaultValuein datatable filtersSummary by CodeRabbit
Release Notes