Skip to content

MPDX-10092 Check staffAccountId before showing the PGA balance card - #2129

Merged
jbirdjavi merged 2 commits into
mainfrom
MPDX-10092-pga-staff-account-id
Oct 8, 2026
Merged

jbirdjavi merged 2 commits into
mainfrom
MPDX-10092-pga-staff-account-id

Conversation

@jbirdjavi

@jbirdjavi jbirdjavi commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Description

  • To decide whether to show the balance card, Partner Giving Analysis ran the StaffAccount query. For a user with a staff account id, the API answers that with a full, unfiltered SAA account summary (one of SAA's most expensive calls) on every page load, only to read the id. (Users without one never reached SAA; the resolver returns nil first.) The card then runs its own FundBalances summary anyway.
  • The report now decides with the existing StaffAccountId query (user.staffAccountId, a plain MPDX read with no SAA call). That saves one SAA account summary per page load for staff.
  • BalanceCard never leaves its skeleton up once loading ends:
    • It renders nothing when FundBalances fails. That case used to stay hidden because StaffAccount failed first for a user whose staff account SAA does not know. Now such a user passes the id check, so the card has to handle the failure itself. The same single "SAA Error" snackbar shows as before.
    • It renders nothing when the query succeeds with no Primary fund (an older bug, found in review).
  • Also fixed, found in review: when the period had no gifts, {donationPeriodTotalSum && ...} printed a bare "0" (the field is Int!) and hid the total. The card now shows "Total Donations for this period $0.00".
  • Tests: the report shows the card without running StaffAccount, and hides it (with no FundBalances call) when staffAccountId is null. The card renders nothing on a query error or with no Primary fund, and shows a zero total. All five fail on main.
  • A local /code-review at xhigh (fresh Opus agent) found no regressions. It traced impersonation, users with no staff account, an id SAA doesn't know, and loading through both versions.

Jira ticket: MPDX-10092
API side of the same ticket: https://github.com/CruGlobal/mpdx_api/pull/3680 (independent; either can ship first)

Testing

  • Sign in as a user with a staff account and go to Reports > Partner Giving Analysis.
  • Check that the Primary Account Balance card still shows.
  • In the browser's network tab, check that the page sends StaffAccountId and FundBalances, and no StaffAccount operation.
  • Sign in as (or impersonate) a user without a staff account, such as a non-Cru user. Check that no balance card shows and no FundBalances request is sent.
  • Pick a filter period with no gifts. Check that the card shows "Total Donations for this period" with $0.00, not a stray "0".

Checklist:

  • I have given my PR a title with the format "MPDX-(JIRA#) (summary sentence max 80 chars)"
  • I have applied the appropriate labels (Add the label "Preview" to automatically create a preview environment)
  • I have run the Claude Code /quality:agent-review command locally and fixed any relevant suggestions
  • I have requested a review from another person on the project
  • I have tested my changes in preview or in staging
  • I have cleaned up my commit history

🤖 Generated with Claude Code

Partner Giving Analysis is open to every user, and it decided whether to
show the balance card by running the StaffAccount query. That query asks
SAA for a full, unfiltered account summary, one of SAA's most expensive
calls, on every page load, just to read the id. The card then runs its
own FundBalances summary anyway.

The report now uses the existing StaffAccountId query (user.staffAccountId,
a plain MPDX read) to decide.

BalanceCard now renders nothing when FundBalances fails. Before, it showed
its skeleton forever on an error. That case used to be hidden because the
StaffAccount query failed first for a user whose staff account SAA does not
know. Now such a user passes the id check, so the card has to handle the
failure itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jbirdjavi jbirdjavi self-assigned this Oct 7, 2026
@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Bundle sizes [mpdx-react]

Compared against 8cef3e7

No significant changes found

- With no Primary fund in a successful FundBalances answer, the card kept
  its skeleton up forever. It now renders nothing once loading ends, the
  same as on an error.
- donationPeriodTotalSum is Int!, so `{donationPeriodTotalSum && ...}`
  printed a bare "0" and hid the total for a period with no gifts. The
  total now shows $0.00.
- The report test comment states the rule (showing the card must not call
  SAA) instead of describing the old code, and the card tests type their
  GqlMockedProvider with the ApolloErgonoMockMap override pattern.

Found in a local /code-review pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jbirdjavi
jbirdjavi requested a review from dr-bizz October 7, 2026 21:36

@dr-bizz dr-bizz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm so glad you found this and are fixing it. I don't think the person who added it knew that it would cost SAA as much as it did.

@jbirdjavi jbirdjavi added the On Staging Will be merged to the staging branch by Github Actions label Oct 8, 2026
@jbirdjavi
jbirdjavi merged commit f3e315d into main Oct 8, 2026
47 checks passed
@jbirdjavi
jbirdjavi deleted the MPDX-10092-pga-staff-account-id branch October 8, 2026 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

On Staging Will be merged to the staging branch by Github Actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants