-
Notifications
You must be signed in to change notification settings - Fork 19
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
Conversation
5c957ca
to
780da7e
Compare
Codecov ReportAttention: Patch coverage is
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. |
1826700
to
15569ba
Compare
f9f6936
to
7730e4c
Compare
7730e4c
to
920ce08
Compare
920ce08
to
45a66f4
Compare
src/components/app/data/utils.js
Outdated
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, | ||
}; | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
courseMetadata, | ||
allocatedCourseRunAssignmentKeys, | ||
}) { | ||
if (hasMultipleAssignedCourseRuns && allocatedCourseRunAssignmentKeys.length > 1) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
039e49b
to
2313a27
Compare
…al-enterprise into hu/ent-8886
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job!
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 filtercourseMetadata
'scourseRuns
&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
Only if submitting a visual change