Skip to content

feat: Migrate pages and resources to React Query - #3222

Open
ChrisChV wants to merge 11 commits into
masterfrom
chris/redux-migration/pages-and-resources
Open

feat: Migrate pages and resources to React Query#3222
ChrisChV wants to merge 11 commits into
masterfrom
chris/redux-migration/pages-and-resources

Conversation

@ChrisChV

@ChrisChV ChrisChV commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Description

  • Migrates the pages and resources from React Redux to React Query
  • Stops using the courseApps and XpertSettings models.
  • Updates some Settings Modals of course Apps: Learning Assistant, Live, Ora, Proctoring, Progress, Teams, Wiki, Xpert.
  • Which user roles will this change impact? "Developer".

Supporting information

Testing instructions

  • Create a new course for testing.
  • Go to Content > Pages & Resources
  • Verify that the list of apps is rendered as expected.

Learning Assistant

  • Install the learning assistant plugin.
  • Add LEARNING_ASSISTANT_AVAILABLE = True to your cms/envs/private.py
  • Restart your instances
  • Go to the Pages and resources page and verify that you can see the Learning Assistant card.
  • Verify that you can open the settings modal.
  • Verify that you can enable and disable the app.

Live

ORA

  • Create an ORA xblock in your course.
  • Go to the Pages and resources page and verify that you can see the Flexible Peer Grading for ORAs card.
  • Verify that you can open the settings modal.
  • Verify that you can enable and disable the app.

Proctoring

  • Add ENABLE_PROCTORED_EXAMS = True to your cms/envs/private.py
  • Go to the Pages and resources page and verify that you can see the Proctoring card.
  • Verify that you can open the settings modal.
  • Verify that you can enable and disable the app.
  • Test updating the extra settings.

Progress

  • Go to the Pages and resources page.
  • Verify that you can see the Progress card.
  • Verify that you can enable and disable the app.
  • Test updating the extra settings.

Teams

  • Create the waffle flag teams.enable_teams_app activated for Everyone.
  • Go to the Pages and resources page and verify that you can see the Teams card.
  • Verify that you can enable and disable the app.
  • Test updating the extra settings

Wiki

  • Go to the Pages and resources page.
  • Verify that you can see the Wiki card.
  • Verify that you can enable and disable the app.
  • Test updating the extra settings.

Xpert

  • Create the waffle flag summaryhook.summaryhook_summaries_configuration activated for Everyone.
  • Go to the Pages and resources and verify that you can see the Xpert unit summaries card.
  • Verify that you can enable and disable the app.
  • Test updating the extra settings.

Best Practices Checklist

We're trying to move away from some deprecated patterns in this codebase. Please
check if your PR meets these recommendations before asking for a review:

  • Any new files are using TypeScript (.ts, .tsx).
  • Avoid propTypes and defaultProps in any new or modified code.
  • Tests should use the helpers in src/testUtils.tsx (specifically initializeMocks)
  • Do not add new fields to the Redux state/store. Use React Context to share state among multiple components.
  • Use React Query to load data from REST APIs. See any apiHooks.ts in this repo for examples.
  • All new i18n messages in messages.ts files have a description for translators to use.
  • Avoid using ../ in import paths. To import from parent folders, use @src, e.g. import { initializeMocks } from '@src/testUtils'; instead of from '../../../../testUtils'

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Aug 31, 2026
@openedx-webhooks

openedx-webhooks commented Aug 31, 2026

Copy link
Copy Markdown

Thanks for the pull request, @ChrisChV!

This repository is currently maintained by @bradenmacdonald.

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.

@github-project-automation github-project-automation Bot moved this to Needs Triage in Contributions Aug 31, 2026
@ChrisChV
ChrisChV marked this pull request as draft August 31, 2026 00:38
@codecov

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.61017% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.02%. Comparing base (f5041a7) to head (41ade6a).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...-resources/app-settings-modal/AppSettingsModal.tsx 91.30% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3222      +/-   ##
==========================================
+ Coverage   95.93%   96.02%   +0.09%     
==========================================
  Files        1397     1393       -4     
  Lines       33622    33589      -33     
  Branches     7701     7711      +10     
==========================================
- Hits        32256    32255       -1     
+ Misses       1323     1291      -32     
  Partials       43       43              

☔ View full report in Codecov by Harness.
📢 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.

@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Sep 2, 2026
@ChrisChV
ChrisChV marked this pull request as ready for review September 3, 2026 02:23

@bradenmacdonald bradenmacdonald 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.

Thanks for taking this on!

Comment on lines +136 to +137
courseApps: sortedCourseApps || [],
courseAppsStatus,

@bradenmacdonald bradenmacdonald Sep 8, 2026

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.

Are these used only on the "Pages & Resources" page? If so, I think they should be in their own CourseAppsContext rather than in the general CourseAuthoringContext.

We don't want to load the course apps on every page.

Comment on lines +109 to +116
// courseApps is the array reference held by the React Query cache; sort a copy
// so we don't mutate it during render (StrictMode double-renders can otherwise
// produce inconsistent results between the two passes).
const sortedCourseApps = courseApps ?
[...courseApps].sort((firstEl, secondEl) => (
COURSE_APPS_ORDER.indexOf(firstEl.id) - COURSE_APPS_ORDER.indexOf(secondEl.id)
)) :
courseApps;

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.

Do we need to have both courseApps and sortedCourseApps?

It would be simpler if you move this sorting into the getCourseApps API function directly, so it's always sorted everywhere. There's no harm in always sorting the array. And then you can sort it in place without needing to make a copy of it.

And in modern JS you can just write courseApps.toSorted(...) instead of [...courseApps].sort(...) although either is fine.

failureReason: courseAppsError,
} = useCourseApps(courseId);

let courseAppsStatus: RequestStatusType = RequestStatus.SUCCESSFUL;

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.

Can we just use the react query status property of the query instead of a custom RequestStatus enum here?

Comment thread src/data/api.ts
Comment on lines +309 to +338
/**
* Get's advanced setting for a course.
*/
export async function getCourseAdvancedSettings(
courseId: string,
settings: string[],
): Promise<any> {
const { data } = await getAuthenticatedHttpClient()
.get(`${getCourseAdvancedSettingsApiUrl()}/${courseId}`, {
params: {
filter_fields: settings.map(snakeCase).join(','),
},
});

return camelCaseObject(data);
}

/**
* Get's advanced setting for a course.
*/
export async function updateCourseAdvancedSettings(
courseId: string,
setting: string,
value: any,
): Promise<Record<string, any>> {
const { data } = await getAuthenticatedHttpClient()
.patch(`${getCourseAdvancedSettingsApiUrl()}/${courseId}`, { [snakeCase(setting)]: { value } });

return camelCaseObject(data);
}

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 see you've removed the existing implementations of getCourseAdvancedSettings and updateCourseAdvancedSettings from src/pages-and-resources/data/api.js which is great, but there's still duplicate implementations of them both in src/advanced-settings/data/api.ts so please combine those with your new API implementation too.

Comment thread src/data/apiHooks.ts
*/
export const useCourseAdvancedSettings = (courseId: string, settings: string[]) => (
useQuery({
queryKey: ['courseSettings', courseId],

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.

This is the same queryKey as useCourseSettings above, which is going to cause bugs.

Also, the settings filter must be in the query key, or we'll have even more bugs.

Suggested change
queryKey: ['courseSettings', courseId],
queryKey: ['courseAdvancedSettings', courseId, settings],

const {
data: courseApps,
isPending: courseAppsIsPending,
failureReason: courseAppsError,

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.

It's better to use error instead of failureReason, because failureReason resets to null when a retry begins, and it will temporarily show a success with courseApps being undefined, whereas error will be preserved until the new fetch succeeds.

// oxlint-disable-next-line @typescript-eslint/await-thenable - this dispatch() IS returning a promise.
success = await dispatch(updateAppStatus(courseId, appInfo.id, values.enabled));
if (!appInfo) {
return;

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.

Shouldn't we display an error in this case?

}, 2000);
}
}, [resetStatusRequestStatus]);
}, [updateSettingsMutation]);

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.

Suggested change
}, [updateSettingsMutation]);
}, [updateSettingsMutation.status]);

The mutation object can change for various reasons; it's better to just depend on the status if that's what's relevant to the effect.

Comment on lines +257 to +258
updateSettingsMutation,
deleteSettingsMutation,

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.

Suggested change
updateSettingsMutation,
deleteSettingsMutation,
updateSettingsMutation.status,
deleteSettingsMutation.status,

setTimeout(() => {
dispatch(updateResetStatus({ status: '' }));
updateSettingsMutation.reset();
}, 2000);

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.

The effect should have a cleanup function that clears the timer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

open-source-contribution PR author is not from Axim or 2U

Projects

Status: Waiting on Author

Development

Successfully merging this pull request may close these issues.

4 participants