Repository navigation
fix: enhance boolean filter handling in SelectFilter component - #166
Conversation
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 40 minutes and 32 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe changes extend the Table stories with a new boolean Changes
Sequence DiagramsequenceDiagram
participant User
participant SelectFilter
participant Select
participant Callback
User->>SelectFilter: Update column config with filter variant
SelectFilter->>Select: Render with value prop (normalized to string)
User->>Select: Select option
Select->>SelectFilter: onChange(selectedValue)
alt Boolean Filter Variant
SelectFilter->>SelectFilter: Detect variant="boolean"
alt selectedValue = ""
SelectFilter->>Callback: setFilterValue(undefined)
else selectedValue = "true"
SelectFilter->>Callback: setFilterValue(true)
else Other non-empty value
SelectFilter->>Callback: setFilterValue(false)
end
else Non-Boolean Filter
SelectFilter->>Callback: setFilterValue(rawSelectedString)
end
Callback->>Callback: Update filter state
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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
🧹 Nitpick comments (3)
packages/react-formio/src/molecules/table/filters/SelectFilter.spec.tsx (2)
39-39: Optional: also cover the controlled-value path for a boolean filter.The current suite exercises
onChangebut never rendersSelectFilterwith a non-undefinedboolean filter value, so thevalue={columnFilterValue === undefined ? "" : String(columnFilterValue)}branch on line 42 ofSelectFilter.tsxis untested. A small case that stubsgetFilterValue: () => falseand asserts the<select>DOM value is"false"would lock in that behavior.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/react-formio/src/molecules/table/filters/SelectFilter.spec.tsx` at line 39, Add a test that renders SelectFilter with a non-undefined boolean filter value to exercise the controlled-value branch: mock the column's getFilterValue to return false (e.g., getFilterValue: () => false) when rendering SelectFilter in SelectFilter.spec.tsx, then assert the rendered <select> element's value is the string "false" (matching the component's value={columnFilterValue === undefined ? "" : String(columnFilterValue)} behavior); this ensures the controlled path for boolean values in SelectFilter is covered.
20-44: Minor: redundantsetFilterValueexposure.
setFilterValueis returned both at the top level ofcreateHeaderand assigned onheader.column. They reference the samevi.fn(), so it works, but keeping only one (e.g., destructure fromheader.column.setFilterValuein the tests) would make the fixture shape harder to get out of sync.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/react-formio/src/molecules/table/filters/SelectFilter.spec.tsx` around lines 20 - 44, The fixture currently exposes setFilterValue twice (top-level setFilterValue and header.column.setFilterValue); remove the redundant top-level setFilterValue from the object returned by createHeader and update any tests to use header.column.setFilterValue instead so the single vi.fn() remains only on header.column.setFilterValue and the fixture shape can't drift out of sync.packages/react-formio/src/molecules/table/Table.stories.tsx (1)
246-260: ReusetableColumnsinWithFiltersfor consistency.
WithPaginationOptionsandUsagealready pull their column definition from the centralizedtableColumns, butWithFiltersduplicates theis_openboolean-filter configuration inline. Inlining here drifts from the shared definition (e.g., theid: "is_open"explicit identity is missing) and any future change to the boolean column has to be mirrored in two places. Consider composing fromtableColumnsor a shared factory.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/react-formio/src/molecules/table/Table.stories.tsx` around lines 246 - 260, In WithFilters replace the duplicated inline boolean column definition with the shared tableColumns entry: find the column in tableColumns whose accessorKey is "data.is_open" and reuse it (or spread it into the WithFilters columns array) so the boolean filter configuration is centralized; ensure the reused column includes the explicit identity id: "is_open" and preserves meta.filter.variant/layout and labels so behavior matches the other stories.
🤖 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/react-formio/src/molecules/table/Table.stories.tsx`:
- Line 156: The current assertion uses canvas.queryByText("Kani") which can be
null and causes a TypeError when calling .closest("tr"); replace this with
canvas.getByText("Kani") to ensure the test fails clearly if the "Kani" row is
missing, then locate the row via .closest("tr") (on the guaranteed element) and
assert that its delete button lookup (querySelector('[data-testid$="-delete"]'))
is not.toBeInTheDocument(); update the assertion in the Table.stories test to
use getByText and perform the negative expectation only on the delete-button
query result.
---
Nitpick comments:
In `@packages/react-formio/src/molecules/table/filters/SelectFilter.spec.tsx`:
- Line 39: Add a test that renders SelectFilter with a non-undefined boolean
filter value to exercise the controlled-value branch: mock the column's
getFilterValue to return false (e.g., getFilterValue: () => false) when
rendering SelectFilter in SelectFilter.spec.tsx, then assert the rendered
<select> element's value is the string "false" (matching the component's
value={columnFilterValue === undefined ? "" : String(columnFilterValue)}
behavior); this ensures the controlled path for boolean values in SelectFilter
is covered.
- Around line 20-44: The fixture currently exposes setFilterValue twice
(top-level setFilterValue and header.column.setFilterValue); remove the
redundant top-level setFilterValue from the object returned by createHeader and
update any tests to use header.column.setFilterValue instead so the single
vi.fn() remains only on header.column.setFilterValue and the fixture shape can't
drift out of sync.
In `@packages/react-formio/src/molecules/table/Table.stories.tsx`:
- Around line 246-260: In WithFilters replace the duplicated inline boolean
column definition with the shared tableColumns entry: find the column in
tableColumns whose accessorKey is "data.is_open" and reuse it (or spread it into
the WithFilters columns array) so the boolean filter configuration is
centralized; ensure the reused column includes the explicit identity id:
"is_open" and preserves meta.filter.variant/layout and labels so behavior
matches the other stories.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: cc691c62-a190-4533-adb5-2567374b1554
📒 Files selected for processing (3)
packages/react-formio/src/molecules/table/Table.stories.tsxpackages/react-formio/src/molecules/table/filters/SelectFilter.spec.tsxpackages/react-formio/src/molecules/table/filters/SelectFilter.tsx
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1c14d8cabd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
1c14d8c to
6c73dcc
Compare
011dfaa to
68e2797
Compare
|
🎉 This PR is included in version 3.0.2 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Summary by CodeRabbit
New Features
Tests