Skip to content

feat: add defaultValue support in datatable filters#704

Open
rohanchkrabrty wants to merge 1 commit intomainfrom
feat-defaultvalue-in-datatable-filters
Open

feat: add defaultValue support in datatable filters#704
rohanchkrabrty wants to merge 1 commit intomainfrom
feat-defaultvalue-in-datatable-filters

Conversation

@rohanchkrabrty
Copy link
Contributor

@rohanchkrabrty rohanchkrabrty commented Mar 13, 2026

Description

This PR adds support for defaultValue in datatable filters

Summary by CodeRabbit

Release Notes

  • New Features
    • Data table columns now support custom default filter values for improved filtering behavior.
    • Status column filtering enhanced: changed from multiselect to single select with autocomplete enabled for more precise filtering and search capabilities.

@vercel
Copy link

vercel bot commented Mar 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
apsara Ready Ready Preview, Comment Mar 13, 2026 11:30am

@rohanchkrabrty rohanchkrabrty self-assigned this Mar 13, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 13, 2026

📝 Walkthrough

Walkthrough

Added a new defaultFilterValue property to data table column definitions, enabling columns to specify custom default filter values that override type-based defaults. Implementation includes type definition, hook logic with precedence handling, and demo usage showing select-type filtering with autocomplete.

Changes

Cohort / File(s) Summary
Type Definition
packages/raystack/components/data-table/data-table.types.tsx
Added optional defaultFilterValue?: unknown property to DataTableColumnDef<TData, TValue> interface.
Filter Logic
packages/raystack/components/data-table/hooks/useFilters.tsx
Implemented precedence logic in filter initialization to use columnDef.defaultFilterValue when provided, falling back to existing type-based defaults (dates, selects, strings).
Demo Usage
apps/www/src/components/datatable-demo.tsx
Updated Status column configuration: changed filterType from multiselect to select, added defaultFilterValue as empty string, and enabled select.autocomplete via filterProps.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A filter's default, once rigid and bound,
Now bends to each column's desire!
From autocomplete to values of choice,
The table dances ever higher—
Configuration sings, backward stays true,
CodeRabbit hops with delight! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add defaultValue support in datatable filters' clearly and accurately describes the main change: introducing support for defaultValue in datatable filters, which is confirmed by all three modified files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat-defaultvalue-in-datatable-filters
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 600819e and 7e75789.

📒 Files selected for processing (3)
  • apps/www/src/components/datatable-demo.tsx
  • packages/raystack/components/data-table/data-table.types.tsx
  • packages/raystack/components/data-table/hooks/useFilters.tsx

Comment on lines +21 to +26
columnDef.defaultFilterValue ??
(filterType === FilterType.date
? new Date()
: filterType === FilterType.select
? options[0].value
: '';
: '');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

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.

Suggested change
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant