Abhishek 🔥: resolve role distribution stats crash on comparison filter#2275
Merged
one-community merged 1 commit intoJul 20, 2026
Merged
Conversation
one-community
approved these changes
Jul 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's Working Well
TypeError: roleDistributionStats is not iterable) that occurred whenever a comparison filter (Previous Week, Week Over Week, Month Over Month, Year Over Year) was selected on the Total Org Summary page.Root Cause
getRoleDistributionStatsinoverviewReportHelper.jsbranched on whether comparison dates were provided:{_id: role, count}— the shape the frontend (RoleDistributionPieChart.jsx) has always expected.$facetaggregation and returned an object{ current: [...], comparison: [...] }instead — a completely different shape, which crashed the frontend when it tried to spread/iterate the response as an array.Notably, role distribution is explicitly documented in the code as a live snapshot (
isActive: true, no date filtering) — it isn't a time-series metric. The comparison branch'scurrentandcomparisonfacets both used the exact same match stage with no date filter, so they always returned identical data anyway. The branching added complexity and a shape mismatch without providing any real comparison value.Changes
overviewReportHelper.js: removed the comparison branching ingetRoleDistributionStats. The function now always returns a flat array, matching the frontend's expectation and eliminating the now-unnecessary duplicate aggregation. UnusedstartDate,endDate,comparisonStartDate,comparisonEndDateparameters were dropped from the function signature (the call site still passes them positionally, which is harmless since JS ignores unused arguments).Testing
Via the UI
Abhishek_FixRoleDistributionStatsComparisonCrashand HighestGoodNetworkApp (frontend) ondevelopmentVia direct API call
The backend runs on port
4500by default, and this endpoint requires an authenticated Bearer token (obtainable via/api/loginor from the frontend's local storage after logging in).Verified locally: this request, which previously would have returned
roleDistributionStatsas an object ({ current: [...], comparison: [...] }) and crashed the frontend, now returns 200 OK withroleDistributionStatsas a flat array, e.g.: