Skip to content

dashboard refactor phase 5 - extract b2b contract dashboard hooks#3355

Merged
gumaerc merged 12 commits into
mainfrom
cg/dashboard-refactor-phase-5
May 21, 2026
Merged

dashboard refactor phase 5 - extract b2b contract dashboard hooks#3355
gumaerc merged 12 commits into
mainfrom
cg/dashboard-refactor-phase-5

Conversation

@gumaerc
Copy link
Copy Markdown
Contributor

@gumaerc gumaerc commented May 19, 2026

What are the relevant tickets?

Part of https://github.com/mitodl/hq/issues/11205

Description (What does it do?)

This PR implements phase 5 of the dashboard frontend code refactoring we have been doing. It mainly extracts the various hooks used in ContractContent and consolidates data fetching for the contract dashboard into the new useContractDashboardData hook. It fetches course run enrollments, program enrollments, programs (filtered by org_id + contract_id), program collections, and courses. It also computes language options and manages the selected-language picker state. It composes raw API data into render-ready ContractProgramDisplayData and ContractCollectionDisplayData rows using named model helpers, so ContractContent has no direct access to raw query results.

New helpers were added to dashboardViewModel:

  • programHasContractRuns — checks whether any of a program's courses appear in the contract-scoped course list.
  • getSortedStandaloneContractPrograms — excludes collection-member programs, filters to only those with contract runs, and preserves contract.programs order.
  • getRenderableContractCollections — keeps only collections that have at least one program with valid contract runs.
  • getProgramCoursesInContractOrder — returns a program's courses in program-defined order, skipping any not present in the contract response.
  • getCollectionFirstCoursesInDisplayOrder — selects the first available contract course per program within a collection, in collection order.
  • buildContractCourseDisplaySlots — maps courses to display slots, resolving the correct run and enrollment for the selected language and scoping enrollments to the current contract.

New unit tests were also added based on the refactoring plan.

How can this be tested?

  • Ensure that you have MITx Online and Learn connected as described in the readme with sufficient test data, which in this case is a B2B contract with several programs and program collections. Also make sure your user is enrolled in said contract.
  • Browse to the dashboard and open the contract. Ensure that everything looks the same as it does when running Learn on main

Copilot AI review requested due to automatic review settings May 19, 2026 19:13
@gumaerc gumaerc added the Needs Review An open Pull Request that is ready for review label May 19, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 19, 2026

OpenAPI Changes

No changes detected

View full changelog

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the B2B contract dashboard to move contract-scoped data fetching and slot composition out of ContractContent into a dedicated hook (useContractDashboardData) and a set of view-model helpers, aiming to keep rendering components insulated from raw query results.

Changes:

  • Added contract-dashboard helper functions to dashboardViewModel for filtering/sorting programs/collections and building render-ready course slots.
  • Introduced useContractDashboardData to consolidate contract-scoped queries (programs, collections, courses, enrollments) and manage language picker state.
  • Updated ContractContent to consume the new hook, simplified program/collection rendering, and adjusted skeleton UI; added/updated unit tests.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
frontends/main/src/app-pages/DashboardPage/CoursewareDisplay/model/dashboardViewModel.ts Adds contract dashboard helper utilities and exports a new display-slot type.
frontends/main/src/app-pages/DashboardPage/CoursewareDisplay/model/dashboardViewModel.test.ts Adds unit tests covering the new contract dashboard helper functions.
frontends/main/src/app-pages/DashboardPage/CoursewareDisplay/hooks/useContractDashboardData.ts New hook that orchestrates contract dashboard data fetching, language options, and row/slot composition.
frontends/main/src/app-pages/DashboardPage/CoursewareDisplay/hooks/useContractDashboardData.test.tsx New hook tests validating program/collection composition behavior and ordering.
frontends/main/src/app-pages/DashboardPage/CoursewareDisplay/dashboardRefactorPlan.md Updates the refactor plan with Phase 5 implementation decisions and checklist adjustments.
frontends/main/src/app-pages/DashboardPage/ContractContent.tsx Switches contract dashboard rendering to the new hook and updates loading skeleton structure.
frontends/main/src/app-pages/DashboardPage/ContractContent.test.tsx Updates mocks and adds coverage for contract-scoped program filtering behavior.

@ChristopherChudzicki ChristopherChudzicki self-assigned this May 19, 2026
@gumaerc gumaerc force-pushed the cg/dashboard-refactor-phase-5 branch from 72570aa to 4fdede7 Compare May 20, 2026 17:49
Comment thread frontends/main/src/app-pages/DashboardPage/ContractContent.tsx
Copy link
Copy Markdown
Contributor

@ChristopherChudzicki ChristopherChudzicki left a comment

Choose a reason for hiding this comment

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

Sorry I didn't finish this review today. Got caught up looking at the certificate issue.

Overall this looks good. I did leave one suggest, which a possible commit to cherry-pick. Can finish reviewing tomorrow (will be out in the morning some though for son's dentist appointment.)

@gumaerc gumaerc force-pushed the cg/dashboard-refactor-phase-5 branch from b52a666 to 368c707 Compare May 21, 2026 15:52
Copy link
Copy Markdown
Contributor

@ChristopherChudzicki ChristopherChudzicki left a comment

Choose a reason for hiding this comment

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

👍

@gumaerc gumaerc merged commit dd95d1a into main May 21, 2026
14 checks passed
@gumaerc gumaerc deleted the cg/dashboard-refactor-phase-5 branch May 21, 2026 18:32
@odlbot odlbot mentioned this pull request May 21, 2026
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Review An open Pull Request that is ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants