dashboard refactor phase 5 - extract b2b contract dashboard hooks#3355
Conversation
OpenAPI ChangesNo changes detected Unexpected changes? Ensure your branch is up-to-date with |
There was a problem hiding this comment.
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
dashboardViewModelfor filtering/sorting programs/collections and building render-ready course slots. - Introduced
useContractDashboardDatato consolidate contract-scoped queries (programs, collections, courses, enrollments) and manage language picker state. - Updated
ContractContentto 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. |
72570aa to
4fdede7
Compare
ChristopherChudzicki
left a comment
There was a problem hiding this comment.
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.)
…g / filtering logic to dashboardViewModel and implement usage in ContractContent
…nly renders programs with contract scoped courses
…, not just programs
b52a666 to
368c707
Compare
and add a missing test for buildCourseEntry
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
ContractContentand consolidates data fetching for the contract dashboard into the newuseContractDashboardDatahook. It fetches course run enrollments, program enrollments, programs (filtered byorg_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-readyContractProgramDisplayDataandContractCollectionDisplayDatarows using named model helpers, soContractContenthas 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 preservescontract.programsorder.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?
main