Skip to content

React query and react context conversion#786

Merged
arbrandes merged 38 commits intoopenedx:masterfrom
WGU-Open-edX:react-query-migration
Mar 3, 2026
Merged

React query and react context conversion#786
arbrandes merged 38 commits intoopenedx:masterfrom
WGU-Open-edX:react-query-migration

Conversation

@jacobo-dominguez-wgu
Copy link
Contributor

@jacobo-dominguez-wgu jacobo-dominguez-wgu commented Jan 30, 2026

Description

This PR implements a migration from Redux to React Query and React Context.
This modernizes state management while maintaining all existing functionality.
All the redux code and files were removed, including all redux and related packages.
The folder and files structure for react query hooks and context were refactored.
Also includes a small refactor on the api files.
It closes #769
It closes #770
Part of react query migration initiative: #768

What Changed

Replaced Redux with React Query for server state management (API calls, caching)
Added React Context for client-side state (Pagination, filters, masquerading, course list back up)
Maintained backward compatibility with existing component interfaces
Created new apiHooks.ts with React Query hooks for all data operations

New Context Providers

FiltersProvider: Course filtering and pagination state
MasqueradeProvider: Admin masquerade functionality
SelectSessionProvider: Entitlement session selection
BackedDataProvider: Backup data for masquerade error handling

Component Updates

Updated all components, containers and hooks to use React Query hooks instead of Redux selectors
All tests were updated to work with the new state management system

Packages removed:

dependencies: {
    "@redux-devtools/extension": "3.3.0",
    "@reduxjs/toolkit": "^2.0.0",
    "react-redux": "^7.2.4",
    "redux": "4.2.1",
    "redux-logger": "3.0.6",
    "redux-thunk": "2.4.2",
    "reselect": "^4.0.0",
},
devDependencies: {
    "redux-mock-store": "^1.5.4"
}

Context and react query folders after the refactor:

src/
└── data/
    │
    ├── constants/                   # Application constants
    │
    ├── context/                     # React Context providers
    │   ├── index.tsx                # Context exports
    │   ├── index.test.tsx           # Context tests
    │   ├── BackedDataProvider.tsx   # Backed data context
    │   ├── BackedData.test.tsx      # Backed data tests
    │   ├── FiltersProvider.tsx      # Filters state context
    │   ├── Filters.test.tsx         # Filters tests
    │   ├── MasqueradeProvider.tsx   # Masquerade context
    │   ├── Masquerade.test.tsx      # Masquerade tests
    │   ├── SelectSessionProvider.tsx # Session selection context
    │   └── SelectSession.test.tsx   # Session selection tests
    │
    ├── hooks/                       # React query hooks
    │   ├── index.ts                 # Hooks exports
    │   ├── queryHooks.ts            # React Query hooks
    │   ├── queryHooks.test.tsx      # Query hooks tests
    │   ├── mutationHooks.ts         # React Query mutations
    │   ├── mutationHooks.test.tsx   # Mutation hooks tests
    │   └── queryKeys.ts             # React Query key definitions
    │
    └── services/                    # External service integrations
        │
        ├── lms/                     # Learning Management System
        │   ├── index.js             # LMS service exports
        │   ├── api.ts               # LMS API client
        │   ├── api.test.tsx         # LMS API tests
        │
        └── segment/                 # Analytics/Segment integration

Migration Strategy

Phase 1: Update Dependencies (does not apply)
Phase 2 (This PR): Add React Query + Context alongside Redux
Phase 3 (#792 Now also included on this PR): Remove all Redux related code and tests and refactor data folder structure

How to test it

Make sure all existing features work as before:
Dashboard Loading: Verify courses load correctly on initial page load and the fallback screen when there are no courses.
Course Filtering: Test search, status filters, and sorting functionality.
Course Card and Actions: Test unenroll, social sharing, email settings, entitlement, banners shows correctly.
Masquerade Feature: Test admin masquerade functionality with valid/invalid users.
Select session modal: I could not test it using the UI, but unit test passes (Manual testing required here).

@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Jan 30, 2026
@openedx-webhooks
Copy link

openedx-webhooks commented Jan 30, 2026

Thanks for the pull request, @jacobo-dominguez-wgu!

This repository is currently maintained by @2U-aperture.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@codecov
Copy link

codecov bot commented Jan 30, 2026

Codecov Report

❌ Patch coverage is 98.31650% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.19%. Comparing base (f1180bf) to head (f228023).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...components/CourseCardBanners/CertificateBanner.jsx 81.25% 3 Missing ⚠️
...Card/components/CourseCardBanners/CourseBanner.jsx 71.42% 2 Missing ⚠️
...ners/CourseFilterControls/CourseFilterControls.jsx 88.23% 2 Missing ⚠️
...components/CourseCardBanners/CreditBanner/hooks.js 90.00% 1 Missing ⚠️
...ners/CourseCard/components/CourseCardMenu/hooks.js 94.11% 1 Missing ⚠️
src/data/hooks/queryHooks.ts 94.44% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #786      +/-   ##
==========================================
+ Coverage   97.54%   98.19%   +0.64%     
==========================================
  Files         148      145       -3     
  Lines        1302     1382      +80     
  Branches      225      297      +72     
==========================================
+ Hits         1270     1357      +87     
+ Misses         31       25       -6     
+ Partials        1        0       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jacobo-dominguez-wgu jacobo-dominguez-wgu marked this pull request as ready for review January 30, 2026 22:51
@jacobo-dominguez-wgu jacobo-dominguez-wgu marked this pull request as draft January 30, 2026 22:53
@jacobo-dominguez-wgu jacobo-dominguez-wgu force-pushed the react-query-migration branch 2 times, most recently from 25d3bf6 to 983f04e Compare February 3, 2026 23:37
@jacobo-dominguez-wgu jacobo-dominguez-wgu marked this pull request as ready for review February 3, 2026 23:40
@jacobo-dominguez-wgu jacobo-dominguez-wgu moved this from Needs Triage to Ready for Review in Contributions Feb 3, 2026
@jacobo-dominguez-wgu jacobo-dominguez-wgu added the mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). label Feb 3, 2026
@jacobo-dominguez-wgu jacobo-dominguez-wgu moved this to In Review in frontend-base Feb 3, 2026
@jacobo-dominguez-wgu
Copy link
Contributor Author

Thanks again! Found a couple more bugs.

Thanks @arbrandes, I have addressed this set of comments, I used a different approach from your suggestion for using the backUpData to run away from eslint errors.

Copy link
Contributor

@arbrandes arbrandes left a comment

Choose a reason for hiding this comment

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

Thanks! A few more things in the comments.

(Apologies this is taking so many review passes. It's not reflective of the quality of your code, but rather on the size and importance of the refactor.)

@jacobo-dominguez-wgu
Copy link
Contributor Author

Thanks! A few more things in the comments.

(Apologies this is taking so many review passes. It's not reflective of the quality of your code, but rather on the size and importance of the refactor.)

No problem, I appreciate you take the time to review and find this details before it get merged.
I have addressed this set of comments, it is ready for another round of review.
Thank you!

Copy link
Contributor

@arbrandes arbrandes left a comment

Choose a reason for hiding this comment

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

Found a small bug.


const openSessionModal = reduxHooks.useUpdateSelectSessionModalCallback(cardId);
} = useEntitlementInfo(courseData);
const updateSelectSessionModal = useSelectSessionModal();
Copy link
Contributor

Choose a reason for hiding this comment

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

The fix is simple:

Suggested change
const updateSelectSessionModal = useSelectSessionModal();
const { updateSelectSessionModal } = useSelectSessionModal();

But I'm concerned that no unit test caught this. I think we're either over-mocking, or there's no unit test for this code path. Mind fixing the test up as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was not specific unit test for this path, I have added it.

@itsjeyd itsjeyd moved this from Ready for Review to In Eng Review in Contributions Feb 19, 2026
Copy link
Contributor

@arbrandes arbrandes left a comment

Choose a reason for hiding this comment

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

A couple of minor things.


export const Dashboard = () => {
hooks.useInitializeDashboard();
const { data, isFetching } = useInitializeLearnerHome();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we want isPending instead of isFetching, here. We only want the loading spinner during initial load, not afterwards.

sortBy,
pageNumber,
);
}, [data, filters, sortBy, pageNumber]);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a minor thing, but the old Redux code would reset the pagenumber after loading data, and it seems we're not doing that anymore. The problem is the classic one: if a user removes the last item from a list, and that happens to be the only item on the page they're on, they're going to see an empty list until they manually navigate to another page.

But instead of doing it at the mutation layer, I suggest you clamp the page number right here:

Suggested change
}, [data, filters, sortBy, pageNumber]);
}, [data, filters, sortBy, pageNumber]);
// Clamp page number when filtered/mutated list shrinks
React.useEffect(() => {
if (numPages > 0 && pageNumber > numPages) {
setPageNumber(1);
}
}, [numPages, pageNumber, setPageNumber]);

If you could add a test for this, it would be great. Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied, thanks.

});
};

const useLogShare = () => useMutation({
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems we're not actually using this hook anywhere. SocialShareMenu uses a different codepath.

This implementation looks better (there's some error catching), but I leave it up to you to decide whether we remove it, or actual use it in SocialShareMenu.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed it was not being used and forgot to remove it, doing it now.

Copy link
Contributor

@arbrandes arbrandes left a comment

Choose a reason for hiding this comment

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

Caught a couple more.

updateEntitlementEnrollment: () => [...learnerDashboardQueryKeys.all, 'updateEntitlementEnrollment'] as const,
deleteEntitlementEnrollment: () => [...learnerDashboardQueryKeys.all, 'deleteEntitlementEnrollment'] as const,
updateEmailSettings: () => [...learnerDashboardQueryKeys.all, 'updateEmailSettings'] as const,
logShare: () => [...learnerDashboardQueryKeys.all, 'logShare'] as const,
Copy link
Contributor

Choose a reason for hiding this comment

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

Missed a spot:

Suggested change
logShare: () => [...learnerDashboardQueryKeys.all, 'logShare'] as const,

Comment on lines +24 to +25
onSuccess: (data) => {
setRequestData(data);
Copy link
Contributor

@arbrandes arbrandes Feb 26, 2026

Choose a reason for hiding this comment

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

In this case, onSuccess receives a response object, not response.data.

Suggested change
onSuccess: (data) => {
setRequestData(data);
onSuccess: (response) => {
setRequestData(response.data);

There used to be an assertion that tested this, but it was removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Also modernized the test file to use renderHook and cover the removed assertion.

@itsjeyd itsjeyd added waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. and removed waiting for eng review PR is ready for review. Review and merge it, or suggest changes. labels Feb 27, 2026
Copy link
Contributor

@arbrandes arbrandes left a comment

Choose a reason for hiding this comment

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

Alright, I think this is good to go! Thanks again!

Can you please rebase on master, though?

@arbrandes arbrandes merged commit 0d2eb96 into openedx:master Mar 3, 2026
6 checks passed
@github-project-automation github-project-automation bot moved this from In Eng Review to Done in Contributions Mar 3, 2026
@openedx-webhooks openedx-webhooks removed the waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. label Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). open-source-contribution PR author is not from Axim or 2U

Projects

Status: Done
Status: Done

Development

Successfully merging this pull request may close these issues.

[react-query] Phase 3: Cleanup [react-query, learner-dashboard] Phase2: Redux → React Query

4 participants