feat: Use legacy_web_url to redirect to legacy courseware (#404)

As part of making the new courseware experience the
default for staff, the LMS /jump_to/ links that are
exposed by the Course Blocks API via the `lms_web_url`
field will soon direct users to whichever experience
is active to them (instead of always directing to
the legacy experience & relying on the learner
redirect).

Because of this, the MFE can no longer rely on
`lms_web_url` to land a staff user to the legacy
experience. However, the aformentioned change
will also introduce a `legacy_web_url` field
to the API, which we *can* use for this purpose.

TNL-7796
This commit is contained in:
Kyle McCormick
2021-04-07 09:21:07 -04:00
committed by GitHub
parent 32ac3632d0
commit cf58ff3d3f
9 changed files with 41 additions and 19 deletions

View File

@@ -61,8 +61,8 @@ const checkUnitToSequenceUnitRedirect = memoize((courseStatus, courseId, sequenc
const checkSpecialExamRedirect = memoize((sequenceStatus, sequence) => {
if (sequenceStatus === 'loaded') {
if (sequence.isTimeLimited && sequence.lmsWebUrl !== undefined) {
global.location.assign(sequence.lmsWebUrl);
if (sequence.isTimeLimited && sequence.legacyWebUrl !== undefined) {
global.location.assign(sequence.legacyWebUrl);
}
}
});
@@ -324,7 +324,7 @@ const sequenceShape = PropTypes.shape({
unitIds: PropTypes.arrayOf(PropTypes.string).isRequired,
sectionId: PropTypes.string.isRequired,
isTimeLimited: PropTypes.bool,
lmsWebUrl: PropTypes.string,
legacyWebUrl: PropTypes.string,
});
const sectionShape = PropTypes.shape({

View File

@@ -406,7 +406,7 @@ describe('CoursewareContainer', () => {
window.location = location;
});
it('should redirect to the sequence lmsWebUrl', async () => {
it('should redirect to the sequence legacyWebUrl', async () => {
const sequenceMetadata = Factory.build(
'sequenceMetadata',
{ is_time_limited: true }, // position index is 1-based and is converted to 0-based for activeUnitIndex
@@ -417,7 +417,7 @@ describe('CoursewareContainer', () => {
history.push(`/course/${courseId}/${sequenceBlock.id}/${unitBlocks[2].id}`);
await loadContainer();
expect(global.location.assign).toHaveBeenCalledWith(sequenceBlock.lms_web_url);
expect(global.location.assign).toHaveBeenCalledWith(sequenceBlock.legacy_web_url);
});
});
});

View File

@@ -8,7 +8,7 @@ export default function CourseRedirect({ match }) {
unitId,
} = match.params;
const unit = useModel('units', unitId) || {};
const coursewareUrl = unit.lmsWebUrl || `${getConfig().LMS_BASE_URL}/courses/${courseId}/courseware/`;
const coursewareUrl = unit.legacyWebUrl || `${getConfig().LMS_BASE_URL}/courses/${courseId}/courseware/`;
global.location.assign(coursewareUrl);
return null;
}

View File

@@ -38,7 +38,8 @@ export function normalizeBlocks(courseId, blocks) {
effortTime: block.effort_time,
id: block.id,
title: block.display_name,
lmsWebUrl: block.lms_web_url,
// Fall back to `lms_web_url` until `legacy_web_url` is added to API (TNL-7796).
legacyWebUrl: block.legacy_web_url || block.lms_web_url,
unitIds: block.children || [],
};
break;
@@ -47,7 +48,8 @@ export function normalizeBlocks(courseId, blocks) {
graded: block.graded,
id: block.id,
title: block.display_name,
lmsWebUrl: block.lms_web_url,
// Fall back to `lms_web_url` until `legacy_web_url` is added to API (TNL-7796).
legacyWebUrl: block.legacy_web_url || block.lms_web_url,
};
break;
default: