Skip to content

Commit

Permalink
fix: xblock error mfe unit preview (openedx#1508)
Browse files Browse the repository at this point in the history
* feat: add functionality to see unit draft preview

* fix: course redirect unit to sequnce unit redirect

* fix: not showing preview when masquerading

* feat: in preview fetch draft branch of sequence metadata
  • Loading branch information
KristinAoki authored Nov 1, 2024
1 parent 6534347 commit e337a36
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/courseware/CoursewareContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class CoursewareContainer extends Component {

checkFetchSequence = memoize((sequenceId) => {
if (sequenceId) {
this.props.fetchSequence(sequenceId);
this.props.fetchSequence(sequenceId, this.props.isPreview);
}
});

Expand Down
3 changes: 2 additions & 1 deletion src/courseware/course/Course.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const Course = ({
celebrations,
isStaff,
isNewDiscussionSidebarViewEnabled,
originalUserIsStaff,
} = useModel('courseHomeMeta', courseId);
const sequence = useModel('sequences', sequenceId);
const section = useModel('sections', sequence ? sequence.sectionId : null);
Expand All @@ -42,7 +43,7 @@ const Course = ({
const navigate = useNavigate();
const { pathname } = useLocation();

if (!isStaff && pathname.startsWith('/preview')) {
if (!originalUserIsStaff && pathname.startsWith('/preview')) {
const courseUrl = pathname.replace('/preview', '');
navigate(courseUrl, { replace: true });
}
Expand Down
2 changes: 1 addition & 1 deletion src/courseware/course/sequence/Sequence.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ const Sequence = ({
sequenceId={sequenceId}
unitId={unitId}
unitLoadedHandler={handleUnitLoaded}
isStaff={isStaff}
isOriginalUserStaff={originalUserIsStaff}
/>
{unitHasLoaded && renderUnitNavigation(false)}
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/courseware/course/sequence/SequenceContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const SequenceContent = ({
sequenceId,
unitId,
unitLoadedHandler,
isStaff,
isOriginalUserStaff,
}) => {
const intl = useIntl();
const sequence = useModel('sequences', sequenceId);
Expand Down Expand Up @@ -60,7 +60,7 @@ const SequenceContent = ({
key={unitId}
id={unitId}
onLoaded={unitLoadedHandler}
isStaff={isStaff}
isOriginalUserStaff={isOriginalUserStaff}
/>
);
};
Expand All @@ -71,7 +71,7 @@ SequenceContent.propTypes = {
sequenceId: PropTypes.string.isRequired,
unitId: PropTypes.string,
unitLoadedHandler: PropTypes.func.isRequired,
isStaff: PropTypes.bool.isRequired,
isOriginalUserStaff: PropTypes.bool.isRequired,
};

SequenceContent.defaultProps = {
Expand Down
6 changes: 3 additions & 3 deletions src/courseware/course/sequence/Unit/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const Unit = ({
format,
onLoaded,
id,
isStaff,
isOriginalUserStaff,
}) => {
const { formatMessage } = useIntl();
const [searchParams] = useSearchParams();
Expand All @@ -33,7 +33,7 @@ const Unit = ({
const unit = useModel(modelKeys.units, id);
const isProcessing = unit.bookmarkedUpdateState === 'loading';
const view = authenticatedUser ? views.student : views.public;
const shouldDisplayUnitPreview = pathname.startsWith('/preview') && isStaff;
const shouldDisplayUnitPreview = pathname.startsWith('/preview') && isOriginalUserStaff;

const getUrl = usePluginsCallback('getIFrameUrl', () => getIFrameUrl({
id,
Expand Down Expand Up @@ -78,7 +78,7 @@ Unit.propTypes = {
format: PropTypes.string,
id: PropTypes.string.isRequired,
onLoaded: PropTypes.func,
isStaff: PropTypes.bool.isRequired,
isOriginalUserStaff: PropTypes.bool.isRequired,
};

Unit.defaultProps = {
Expand Down
4 changes: 2 additions & 2 deletions src/courseware/data/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export async function getCourseMetadata(courseId) {
return normalizeMetadata(metadata);
}

export async function getSequenceMetadata(sequenceId) {
export async function getSequenceMetadata(sequenceId, params) {
const { data } = await getAuthenticatedHttpClient()
.get(`${getConfig().LMS_BASE_URL}/api/courseware/sequence/${sequenceId}`, {});
.get(`${getConfig().LMS_BASE_URL}/api/courseware/sequence/${sequenceId}`, { params });

return normalizeSequenceMetadata(data);
}
Expand Down
4 changes: 2 additions & 2 deletions src/courseware/data/thunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ export function fetchCourse(courseId) {
};
}

export function fetchSequence(sequenceId) {
export function fetchSequence(sequenceId, isPreview) {
return async (dispatch) => {
dispatch(fetchSequenceRequest({ sequenceId }));
try {
const { sequence, units } = await getSequenceMetadata(sequenceId);
const { sequence, units } = await getSequenceMetadata(sequenceId, { preview: isPreview ? '1' : '0' });
if (sequence.blockType !== 'sequential') {
// Some other block types (particularly 'chapter') can be returned
// by this API. We want to error in that case, since downstream
Expand Down

0 comments on commit e337a36

Please sign in to comment.