Skip to content

[MPDX-9912] - Wire Run & Send buttons to the run and send mutation - #2014

Merged
wjames111 merged 9 commits into
mainfrom
MPDX-9912
Sep 3, 2026
Merged

[MPDX-9912] - Wire Run & Send buttons to the run and send mutation#2014
wjames111 merged 9 commits into
mainfrom
MPDX-9912

Conversation

@wjames111

@wjames111 wjames111 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Description

Wires the Run & Send buttons (mocked in MPDX-9700) to the real runAndSendNewStaffCohort mutation from MPDX-9842.

  • All three entry points — "Run and Send All", "Run & Send Selected", and a new per-row action — share one useRunAndSendFlow hook, so confirm/send/toast behavior can't drift.
  • The toast reports the server's sentCount, not the client's guess; the two can differ when a goal stops being Complete before the confirm. A zero count reports "nothing eligible" rather than success.
  • Sent chips and statuses refresh via a NewStaffCohortAttendees refetch; the cohort normalizes itself from the mutation payload.
  • Chips carry their own goalSentAt date, so a row sent in an earlier batch keeps its date while the cohort banner moves to the latest.
  • New CohortBar banner from goalsSentAt. Copy reads "The last batch of MPD goals was run and sent on …" — goalsSentAt tracks the most recent batch, so the AC's "All complete goals were …" would be untrue after a partial run.
  • Blocked states use the AC's tooltip copy verbatim, gated on the cohort's canRunAndSend (its first consumer). The confirm dialog locks down with a spinner while sending.

Notes:

  • MPDX-9912 assigns "Run & Send Selected" to MPDX-9693, but that ticket closed with the mock handler still in place. All three paths share one handler, so wiring it covered Selected too.
  • Run & Send always passes explicit attendeeIds. Omitting them means "every Complete goal in the cohort", which diverges from the modal's preview under an active search.
  • No mpdx_api change needed — MPDX-9842 shipped the mutation and both timestamp columns. It stamps goal_sent_at (the gate on staff seeing their goal) and does not send email; that is MPDX-9523's mailer, still blocked.

Related: MPDX-9842, MPDX-9700, MPDX-9693. Reviewed with /quality:agent-review (6 agents, no blockers); findings fixed in follow-up commits.

Testing

Needs MPD Goals team access and a cohort with all 13 training costs entered.

  • Go to HR Tools → MPD Goal Calculator - Admin Table → Active Goals
  • On a cohort with no training costs: check "Run and Send All" is disabled and its tooltip reads "All inputs and per-training costs are required to run & send goals."
  • Switch to a cohort with costs. Hover the on an Incomplete row — disabled, same tooltip.
  • Click the on a Complete row → "Run & Send this goal" → confirm. Check the toast count, that the row's chip becomes "Sent ", and that the banner appears.
  • Click "Run and Send All" on a mixed cohort. Check the dialog reports "N of the M MPD goals cannot be sent." with names, and lists already-sent rows separately.
  • Re-open "Run and Send All" after sending. Check previously sent rows appear under "have already been sent" and are not re-sent.
  • Check a row's Sent date does not change when a later batch moves the banner.

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

@wjames111 wjames111 self-assigned this Sep 1, 2026
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Bundle sizes [mpdx-react]

Compared against 419829b

No significant changes found

@wjames111 wjames111 changed the title MPDX-9912 Wire Run & Send buttons to the run and send mutation [MPDX-9912] - Wire Run & Send buttons to the run and send mutation Sep 1, 2026
@wjames111 wjames111 added the Preview Environment Add this label to create an Amplify Preview label Sep 1, 2026
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Preview branch generated at https://MPDX-9912.d3dytjb8adxkk5.amplifyapp.com

@wjames111 wjames111 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Multi-Agent Code Review — 6 agents + adversarial cross-examination

Verdict: APPROVED WITH SUGGESTIONS. No finding survives calibration at severity >= 8.0. One genuine defect worth fixing; the rest are small, verified fixes.

Agents run: Architecture, Data Integrity, Testing, Standards, UX, Financial Reporting. Security was skipped (no auth, API-route, Apollo-config, process.env, workflow, or dependency changes). Every changed file drew findings from 2+ agents, so no coverage-gap pass was needed.

Findings were then put through an adversarial severity round. Two items rated 9.0 by a single agent were revised down after verification, one of them refuted on facts.

The one real defect

useRunAndSendFlow.tsx toasts a green success for sentCount === 0. Flagged independently by 5 of 6 agents, confirmed reachable against mpdx_api origin/master, and reproduced with a probe test. Commented inline.

Refuted during cross-examination

  • "Already-sent goals being re-sent is untested" (rated 9.0) — refuted on facts. mpdGoalAdminHelpers.test.ts:202 already exercises partitionSendable with a Sent row, asserting it lands in alreadySent and not sendable. The consumer is covered at RunAndSendModal.test.tsx:98, and the server re-filters independently. Tested pure function plus two guards.
  • "Empty attendeeIds array might send everything"refuted. find([]) returns [], so [] sends nothing; it is also unreachable while Continue is disabled on sendableCount === 0.
  • "Mocks encode an impossible post-send state"refuted. can_run_and_send? is purely run_and_send_blockers.empty? and does not depend on whether goals have been sent, so canRunAndSend: true after a send is correct.

Findings on lines outside the diff

public/locales/en/translation.json:245[Medium] severity 5.0. The _one plural form of "{{count}} MPD Goals were run and sent." is byte-identical to _other. Pre-existing, but this PR adds the per-row entry point where the count is always 1, making "1 MPD Goals were run and sent." the common case rather than an edge case. Worth correcting the _one form here.

src/components/HrTools/CLAUDE.md[Suggestion] severity 4.0. The "Mock / prototype tools — not wired to a backend" section still says MpdGoalAdmin has "no .graphql", hits "neither API", and has "modals exist, no mutations", and tells readers not to wire tests against a real operation. All four claims are now wrong, and that file auto-loads for anything under HrTools/.

Correction to this PR's own description

The description says Run & Send "emails staff and their coaches". It does not. run_and_send.rb stamps goal_sent_at and goals_sent_at and nothing else — there is no mailer in the service or the mutation. That was MPDX-9842 AC #4, delegated to MPDX-9523, which is currently BLOCKED. The action is still effectively irreversible and does gate staff visibility of the goal, but the email framing overstates present behavior and will be corrected.

Also verified clean

yarn lint:ts and yarn eslint pass; 129/129 tests pass serially. All 5 new i18n keys have matching literal t() strings with no dynamic keys. No any, @ts-ignore, non-null assertions, new Date(), export default, debug output, or unreferenced TODOs added. Cache normalization is sound (NewStaffCohort has merge: true, and id is present on the one normalizable type). Money invariants intact — the null MPD goal still renders an em-dash rather than $0.00, and no new ?? 0 was introduced on an amount field. Test timezone is pinned to UTC in globalSetup.ts, so the hardcoded-ISO date assertions are not a flake risk.

The rotating 1-4 test failures under parallel load are pre-existing and outside this PR — four verification runs had all 12 MpdGoalAdmin suites passing while 9 sibling HrTools suites timed out on waitFor starvation.

Comment thread src/components/HrTools/MpdGoalAdmin/useRunAndSendFlow.tsx Outdated
Comment thread src/components/HrTools/MpdGoalAdmin/GoalsTable/GoalsTable.tsx Outdated
Comment thread src/components/HrTools/MpdGoalAdmin/RunAndSendModal/RunAndSendModal.tsx Outdated
Comment thread src/components/HrTools/MpdGoalAdmin/useRunAndSendFlow.tsx
Comment thread src/components/HrTools/MpdGoalAdmin/useRunAndSendFlow.tsx Outdated
Comment thread src/components/HrTools/MpdGoalAdmin/useRunAndSendFlow.tsx
Comment thread src/components/HrTools/MpdGoalAdmin/NewStaffCohorts.graphql Outdated
Comment thread src/components/HrTools/MpdGoalAdmin/GoalsTableToolbar/GoalsTableToolbar.tsx Outdated
Comment thread public/locales/en/translation.json Outdated
Comment thread public/locales/en/translation.json Outdated
…eRunAndSendFlow.tsx:54

Name the withdrawn-id cost of sending explicit attendee ids
# Conflicts:
#	src/components/HrTools/MpdGoalAdmin/MpdGoalAdminContext.test.tsx
#	src/components/HrTools/MpdGoalAdmin/mpdGoalAdminMocks.ts
@wjames111
wjames111 requested a review from dr-bizz September 1, 2026 20:52
@wjames111 wjames111 added the On Staging Will be merged to the staging branch by Github Actions label Sep 2, 2026
@canac
canac requested review from canac and removed request for dr-bizz September 2, 2026 20:38

@canac canac 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 tested it out, and this works really well!

# Conflicts:
#	src/components/HrTools/MpdGoalAdmin/GoalsTable/GoalsTable.test.tsx
#	src/components/HrTools/MpdGoalAdmin/GoalsTable/GoalsTable.tsx
# Conflicts:
#	src/components/HrTools/MpdGoalAdmin/CohortBar/CohortBar.tsx
#	src/components/HrTools/MpdGoalAdmin/mpdGoalAdminHelpers.test.ts
#	src/components/HrTools/MpdGoalAdmin/mpdGoalAdminMocks.ts
@wjames111
wjames111 merged commit 914884c into main Sep 3, 2026
22 of 24 checks passed
@wjames111
wjames111 deleted the MPDX-9912 branch September 3, 2026 14:24
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 Preview Environment Add this label to create an Amplify Preview

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants