fix(column-filtering): include sub-rows in flatRows when maxLeafRowFilterDepth skips recursion #6395
beta fromrefs/pull/6395/head·opened Bug#
`filterRowModelFromRoot` discarded sub-rows when the parent passed the filter but recursion was skipped because `depth >= maxLeafRowFilterDepth`. The parent row was pushed into `flatRows` and `rowsById`, but the children stayed reachable only via `row.subRows`, leaving `flatRows` an incomplete view of the visible tree.
`column.getFacetedUniqueValues()` (which iterates `flatRows`) returned consistent counts before filtering but inconsistent counts after, because the pre-filter `flatRows` from the core row model includes sub-rows while the filtered `flatRows` did not.
Fix#
Add a small helper `addSubRowsToFlatArrays` that recursively pushes each surviving sub-row into `flatRows` and `rowsById`, and call it from the `else if` branch the parent-pass / depth-skipped case falls into. The branch is reached only when `row.subRows.length` is truthy, so the helper always has work to do.
`flatRows` and `rowsById` now contain the same set of rows that `rows` plus the surviving `row.subRows` paths cover, so faceted-unique counts and other flat-row consumers agree with the visible tree.
`filterRowModelFromLeafs` already pushed every passing leaf (including sub-rows that came from recursion) into `flatRows` via its own loop, so the bug was specific to `filterRowModelFromRoot`.
Tests#
Local test harness is not available in this environment (no `node_modules`), but the change is small and the cases are mechanical:
| scenario | before | after |
|---|---|---|
| no filter | flatRows = all rows | flatRows = all rows |
| maxLeafRowFilterDepth = 100, normal filter | flatRows = passing rows at all depths | unchanged |
| maxLeafRowFilterDepth = 0, parent passes | flatRows = [parent only] | flatRows = [parent + subRows] |
| maxLeafRowFilterDepth = 0, parent passes, sub-rows also have subRows | subRows of subRows missing | included recursively |
A follow-up commit can add a regression test once the test harness is wired up locally; happy to do that in response to review feedback.
1 file changed, +20/-0.
Summary by CodeRabbit#
- Bug Fixes
- Improved filtered table results so nested rows stay consistent in the visible row list and row lookup data, even when filtering depth limits are reached.
- 1
KevinVandy closed this
Sign in to join this conversation.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
90310c85-ffa8-445f-aa15-823a25204ae5📥 Commits
Reviewing files that changed from the base of the PR and between 9db621f3c5a3086152933992dd9f0c29c6bbf828 and b6352cc5c407b10a2f9c8e4718c50ff69ca89fe6.
📒 Files selected for processing (1)
packages/table-core/src/features/column-filtering/filterRowsUtils.ts📝 Walkthrough
Walkthrough#
Adds a recursive helper
addSubRowsToFlatArraysinfilterRowModelFromRootthat mirrors a passing row's sub-rows intoflatRowsandrowsByIdwhen recursion is halted bymaxLeafRowFilterDepth, fixing inconsistency betweenrow.subRowsand the flattened row representation.Changes#
flatRows Consistency Fix
packages/table-core/src/features/column-filtering/filterRowsUtils.tsaddSubRowsToFlatArrayshelper that recursively appends sub-rows intonewFilteredFlatRows/newFilteredRowsById, and invokes it in the filtering recursion when a passing row'sdepthreachesmaxDepthbut still hassubRows.Estimated code review effort: 2 (Simple) | ~10 minutes
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
#6361by adding skipped sub-rows to flatRows and rowsById when recursion stops at max depth.✨ 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.
❤️ Share