Skip to content

dashboard refactor phase 3: extract home dashboard view-model helpers#3342

Draft
ChristopherChudzicki wants to merge 2 commits into
mainfrom
cc/dashboard-refactor-phase-3-v2
Draft

dashboard refactor phase 3: extract home dashboard view-model helpers#3342
ChristopherChudzicki wants to merge 2 commits into
mainfrom
cc/dashboard-refactor-phase-3-v2

Conversation

@ChristopherChudzicki
Copy link
Copy Markdown
Contributor

Warning

#3341 should be merged first

What are the relevant tickets?

For https://github.com/mitodl/hq/issues/11205

Description (What does it do?)

This PR refactors HomeEnrollmentsDisplay by extracting utils (its bucketing, filtering, grouping, and deduplication logic) into dedicated pure helper functions. The component is now much thinner, mostly composing utils. A private useHomeDashboardData hook handles query orchestration and assembles the render-ready data shape.

Tests: Intentionally split:

  • dashboardViewModel.test.ts new unit tests for the utils
  • HomeEnrollmentsDisplay.test.tsx: All the original integration / UI tests remain in place unchanged, two added

How can this be tested?

  1. There should be no behavioral change in the home dashboard:
    • Sanity check that course/program enrollments from MITxOnline (not b2b) show up
  2. Read HomeEnrollmentsDisplay, particularly useHomeDashboardData. Hopefully it's easier to understand.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 13, 2026

OpenAPI Changes

No changes detected

View full changelog

Unexpected changes? Ensure your branch is up-to-date with main (consider rebasing).

@ChristopherChudzicki ChristopherChudzicki force-pushed the cc/split-enrollment-display branch 2 times, most recently from 560ffef to 7e6bfe7 Compare May 15, 2026 13:48
Base automatically changed from cc/split-enrollment-display to main May 15, 2026 14:29
ChristopherChudzicki and others added 2 commits May 15, 2026 17:15
Move home-only data orchestration out of the home dashboard component
and into a typed composer (private function in HomeEnrollmentsDisplay.tsx)
that calls named pure helpers from model/dashboardViewModel.ts.

New pure helpers in dashboardViewModel.ts (with unit tests):
  bucketAndSortHomeEnrollments, enrollmentCourseIsInPrograms,
  groupModuleCoursesByProgramId, getModuleCourseIdsFromPrograms,
  getNonContractProgramEnrollments, getTopLevelProgramEnrollments,
  isProgramAsCourse, isNonContractEnrollment.

ProgramEnrollmentDisplay's two inline reduces (enrollmentsByCourseId,
programEnrollmentsById) now use the simplified helpers added in Phase 1.
Drop the dead courses parameter from groupCourseRunEnrollmentsByCourseId
— its filter never tripped because both callers only look up by ids the
helper would have included.

Soften the plan's "zero inline transforms" exit check across Phases 3-5
to "no inline-defined domain logic" — composing a named predicate or
comparator with .filter() is glue, not orchestration. Add an Open
question noting Phase 3 inlined useHomeDashboardData as a private
function rather than its own file; Phase 4/5 settle the hook location
and test strategy before they begin.

Rename ProgramContent.test.tsx's mock testid enrollment-display →
program-enrollment-display for clarity now that two dashboards exist.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ChristopherChudzicki ChristopherChudzicki force-pushed the cc/dashboard-refactor-phase-3-v2 branch from cc6c776 to d812730 Compare May 15, 2026 21:15
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.

1 participant