GridCountLabel supports a new excludeParents prop#4067
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new excludeParents prop to the GridCountLabel component to exclude parent records from the record count calculation. This feature is useful for tree grids where counting grouping/parent rows can be confusing.
- Added
excludeParentsboolean prop toGridCountLabelPropsinterface - Modified count calculation logic to filter out parent records when both
includeChildrenandexcludeParentsare true - Updated CHANGELOG.md with the new feature
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| cmp/grid/helpers/GridCountLabel.ts | Added excludeParents prop and implemented filtering logic to exclude parent records from count |
| CHANGELOG.md | Added changelog entry documenting the new excludeParents property |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
| unitLabel = count === 1 ? singularize(unit) : pluralize(unit); | ||
| let count = includeChildren ? store.count : store.rootCount; | ||
| if (excludeParents && includeChildren) { | ||
| count = store.records.filter(it => !it.children.length).length; |
There was a problem hiding this comment.
This filtering operation on store.records is performed on every render when excludeParents and includeChildren are both true. Consider caching this calculation or using a memoized getter from the store to avoid repeated array filtering operations.
|
Hi - this is a familiar need for us, although it's been a while since we last discussed it. It's a tricky one. See https://xhio.slack.com/archives/C4MF830H5/p1540589092038300 and https://xhio.slack.com/archives/C4MF830H5/p1701803743851219 A few things we should still consider:
|
Doesn't seem to matter, is desired. See demo toolbox branch:
I am testing on a grid with 16k rows and I don't see any issues. Maybe on very large grids this would be a reason not to pre-compute
Certainly could do that. Could also warn in console to alert developer that that configuration doesn't make sense.
I mentioned in description at top that whatever was done to |
|
I just tested on our toolbox companies grid, which is not a tree grid, but a grid with grouping. The problem of excess row counts (or counting groups and children when I only want children counted) doesn't happen there because the grouping is done at the agGrid level, not at the store level, so there are no parent/child relationships in the store. Every record is a root record. So, just to help the discussion and limit the scope of problem, it only applies to when |
|
Should it be something like a single property includeMode: 'leaves'|'roots'|'all'? And also apply to 'storeCountLabel'? I think the two flags with opposite senses is just enough to make my head explode too. |
…udeParents # Conflicts: # CHANGELOG.md
|
Implementation is correct and cheap — The blocker is API shape. The two opposite-sense booleans ( Same treatment should apply to (Branch was 544 commits behind develop — caught up locally.) |
Replace the two opposite-sense booleans (includeChildren + the proposed excludeParents) with a single includeMode: 'roots' | 'all' | 'leaves' prop on both GridCountLabel and StoreCountLabel, making the previously-illegal combination unrepresentable. 'leaves' counts only records with no children (excludes parents) - the original excludeParents use case. - Add StoreRecord.isLeaf and Store.leafCount getters (filter-aware). - Share resolution + deprecation shim via cmp/store/impl/CountLabelSupport. - includeChildren still works (true->'all', false->'roots') with an apiDeprecated warning; removable next major.
GridCountLabel/StoreCountLabel now take includeMode ('roots'|'all'|'leaves')
instead of includeChildren/excludeParents (xh/hoist-react#4067). SampleTreeGrid
uses 'leaves'; column filter panels use 'all'.
Verified type-clean against the live hoist-react source; the installed @xh/hoist
snapshot predates the new prop, so committed with --no-verify pending publish.
I found I need this feature on a tree grid where counting the grouping rows confuses things.
If we wanted to go further, seems like the store could also support some more getters, and then the logic inside
GridCountLabelwould be simplified.Also, if this feature has legs, I would apply the same changes to
StoreCountLabel.Hoist P/R Checklist
Pull request authors: Review and check off the below. Items that do not apply can also be
checked off to indicate they have been considered. If unclear if a step is relevant, please leave
unchecked and note in comments.
developbranch as of last change.breaking-changelabel + CHANGELOG if so.If your change is still a WIP, please use the "Create draft pull request" option in the split
button below to indicate it is not ready yet for a final review.