Skip to content

Abhishek 🔥: resolve role distribution stats crash on comparison filter#2275

Merged
one-community merged 1 commit into
developmentfrom
Abhishek_FixRoleDistributionStatsComparisonCrash
Jul 20, 2026
Merged

Abhishek 🔥: resolve role distribution stats crash on comparison filter#2275
one-community merged 1 commit into
developmentfrom
Abhishek_FixRoleDistributionStatsComparisonCrash

Conversation

@Abhi-R0211

Copy link
Copy Markdown
Contributor

What's Working Well

  • Fixes a frontend crash ("Something went wrong" / 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

getRoleDistributionStats in overviewReportHelper.js branched on whether comparison dates were provided:

  • No comparison: returned a flat array of {_id: role, count} — the shape the frontend (RoleDistributionPieChart.jsx) has always expected.
  • With comparison: ran a MongoDB $facet aggregation 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's current and comparison facets 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 in getRoleDistributionStats. The function now always returns a flat array, matching the frontend's expectation and eliminating the now-unnecessary duplicate aggregation. Unused startDate, endDate, comparisonStartDate, comparisonEndDate parameters 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

  1. Start both HGNRest (backend) on the branch Abhishek_FixRoleDistributionStatsComparisonCrash and HighestGoodNetworkApp (frontend) on development
  2. Navigate to Total Org Summary.
  3. Toggle through each comparison option (Previous Week, Week Over Week, Month Over Month, Year Over Year) and confirm:
    • No crash / error screen
    • The Role Distribution pie chart (Volunteer Roles & Team Dynamics section) renders correctly
    • Switching back to "No Comparison" still works

Via direct API call

The backend runs on port 4500 by default, and this endpoint requires an authenticated Bearer token (obtainable via /api/login or from the frontend's local storage after logging in).

curl "http://localhost:4500/api/reports/volunteerstats?startDate=2026-07-05&endDate=2026-07-11&comparisonStartDate=2026-06-05&comparisonEndDate=2026-06-11" \
  -H "Authorization: Bearer YOUR_TOKEN_HERE"

Verified locally: this request, which previously would have returned roleDistributionStats as an object ({ current: [...], comparison: [...] }) and crashed the frontend, now returns 200 OK with roleDistributionStats as a flat array, e.g.:

"roleDistributionStats": [
  { "_id": "Volunteer", "count": 2400 },
  { "_id": "Manager", "count": 45 },
  ...
]
Screenshot 2026-07-17 162514 Screenshot 2026-07-17 162447

@Abhi-R0211 Abhi-R0211 self-assigned this Jul 17, 2026
@one-community one-community changed the title Abhishek_fix: resolve role distribution stats crash on comparison filter Abhishek 🔥: resolve role distribution stats crash on comparison filter Jul 19, 2026
@one-community
one-community merged commit 7601d46 into development Jul 20, 2026
2 checks passed
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.

2 participants