Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: display allocated runs on the course about page #1142

Merged
merged 11 commits into from
Aug 13, 2024
Merged

Conversation

brobro10000
Copy link
Member

@brobro10000 brobro10000 commented Aug 6, 2024

For variant based assignments, if an assignment is allocated to a specific variant (course run) or multiple variants of the same course, we want to ensure that the course about page only displays the enrollable course run card and calls can-redeem appropriately.

We leverage the field isAssignedCourseRun to conditionally filter courseMetadata's courseRuns & availableCourseRuns to conditionally render single or multiple course run cards.

The changes made also ensures that on load of the course about page, if there is an allocated assignment with a variant, only run can-redeem on that specific variant to improve page performance.

Screen.Recording.2024-08-06.at.10.52.56.AM.mov

TODOs:
Verify only the late enrollment card is displayed.
Clear up TODOs in the code
Tests

For all changes

  • Ensure adequate tests are in place (or reviewed existing tests cover changes)
  • Ensure English strings are marked for translation. See documentation for more details.

Only if submitting a visual change

  • Ensure to attach screenshots
  • Ensure to have UX team confirm screenshots

Copy link

codecov bot commented Aug 7, 2024

Codecov Report

Attention: Patch coverage is 96.87500% with 1 line in your changes missing coverage. Please review.

Project coverage is 88.07%. Comparing base (10362ba) to head (4f3397f).

Files Patch % Lines
src/components/course/data/courseLoader.ts 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1142      +/-   ##
==========================================
+ Coverage   88.05%   88.07%   +0.02%     
==========================================
  Files         393      393              
  Lines        8268     8292      +24     
  Branches     2021     2027       +6     
==========================================
+ Hits         7280     7303      +23     
  Misses        946      946              
- Partials       42       43       +1     

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

@brobro10000 brobro10000 force-pushed the hu/ent-8886 branch 2 times, most recently from f9f6936 to 7730e4c Compare August 7, 2024 19:42
@brobro10000 brobro10000 marked this pull request as ready for review August 7, 2024 19:53
Comment on lines 751 to 781
export function determineAllocatedCourseRuns({
redeemableLearnerCreditPolicies,
courseKey,
}) {
const { learnerContentAssignments } = redeemableLearnerCreditPolicies;
if (learnerContentAssignments.hasAllocatedAssignments) {
let allocatedCourseRunAssignments = learnerContentAssignments.allocatedAssignments.filter(
(assignment) => assignment?.isAssignedCourseRun,
);
if (courseKey) {
allocatedCourseRunAssignments = allocatedCourseRunAssignments.filter(
(assignment) => assignment?.parentContentKey === courseKey,
);
}
const allocatedCourseRunAssignmentKeys = allocatedCourseRunAssignments.map(assignment => assignment.contentKey);
const hasAssignedCourseRuns = allocatedCourseRunAssignmentKeys.length > 0;
const hasMultipleAssignedCourseRuns = allocatedCourseRunAssignmentKeys.length > 1;
return {
allocatedCourseRunAssignmentKeys,
allocatedCourseRunAssignments,
hasAssignedCourseRuns,
hasMultipleAssignedCourseRuns,
};
}
return {
allocatedCourseRunAssignmentKeys: [],
allocatedCourseRunAssignments: [],
hasAssignedCourseRuns: false,
hasMultipleAssignedCourseRuns: false,
};
}
Copy link
Member Author

@brobro10000 brobro10000 Aug 9, 2024

Choose a reason for hiding this comment

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

Spent some time making this a hook that sourced its own courseKey and redeemableLearnerCreditPolicies but ran into an issue attempting to use this in the couresLoader. B/c the courseLoader is not a functional react component, I could not utilize this function as a hook. The tradeoff of using a hook vs a function was not including the performance enhancements of the can-redeem call, so I opted to retain the performance enhancements of can-redeem and keep it as a function.

One improvement is the return of the allocatedCourseRunAssignments value which returns the metadata of the course run based allocations versus just the course keys.

Copy link
Member

@adamstankiewicz adamstankiewicz left a comment

Choose a reason for hiding this comment

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

Overall, looking great! Left mostly nit comments, but also had a few clarifying questions and handful of minor suggestions.

src/components/app/data/utils.js Outdated Show resolved Hide resolved
src/components/app/data/utils.js Outdated Show resolved Hide resolved
src/components/app/data/utils.js Outdated Show resolved Hide resolved
src/components/app/data/utils.js Outdated Show resolved Hide resolved
src/components/app/data/utils.js Outdated Show resolved Hide resolved
src/components/app/data/utils.js Outdated Show resolved Hide resolved
courseMetadata,
allocatedCourseRunAssignmentKeys,
}) {
if (hasMultipleAssignedCourseRuns && allocatedCourseRunAssignmentKeys.length > 1) {
Copy link
Member

Choose a reason for hiding this comment

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

[question/clarification] Why might we only want to mutate the below courseRuns and availableCourseRuns values when hasMultipleAssignedCourseRuns: true? Is there a particular reason we wouldn't want to go that if the user has a single allocated assignment applicable to the current course?

Copy link
Member Author

@brobro10000 brobro10000 Aug 12, 2024

Choose a reason for hiding this comment

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

When a user has a single allocated assignment, we alter how we retrieve course metadata.

  let courseRunKey = searchParams.get('course_run_key')?.replaceAll(' ', '+');
  if (!courseRunKey && hasAssignedCourseRuns) {
    courseRunKey = hasMultipleAssignedCourseRuns ? null : allocatedCourseRunAssignmentKeys[0];
  }

For a single allocation with no course_run_key defined, we are defaulting the courseRunKey to the allocated course run key, only returning a single course from course metadata. That way we don't have to go through the additional step of filtering by the allocated course run a second time.

For a single allocation with a course_run_key, we are returning a single course regardless, so any UI changes (such as important dates) would have to be parsed down stream to determine if the singular course run displayed (via course_run_key) is an allocated course run.

For hasMultipleAssignedCourseRuns: true state, we are opting to use the courseKey to return all course runs from course metadata. Then we transform it further with this function. This approach allows us to treat the multiple course runs for a single course as a true edge case (that could easily be ripped out) as opposed to baking it into the default logic.

src/components/course/data/courseLoader.js Outdated Show resolved Hide resolved
src/components/course/data/courseLoader.js Outdated Show resolved Hide resolved
src/components/app/data/utils.js Outdated Show resolved Hide resolved
Copy link
Member

@adamstankiewicz adamstankiewicz left a comment

Choose a reason for hiding this comment

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

Great job!

@brobro10000 brobro10000 merged commit 4f4566e into master Aug 13, 2024
7 checks passed
@brobro10000 brobro10000 deleted the hu/ent-8886 branch August 13, 2024 16:22
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.

2 participants