Skip to content

fix: sidebar unitid undefined #1743

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

Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/courseware/course/sidebar/sidebars/course-outline/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,15 @@

const handleUnitClick = ({ sequenceId, activeUnitId, id }) => {
const logEvent = (eventName, widgetPlacement) => {
const findSequenceByUnitId = () => Object.values(sequences).find(seq => seq.unitIds.includes(activeUnitId));
const findSequenceByUnitId = (unitId) => {

Check failure on line 77 in src/courseware/course/sidebar/sidebars/course-outline/hooks.js

View workflow job for this annotation

GitHub Actions / tests

'unitId' is already declared in the upper scope on line 44 column 5
if (!unitId) return null;

Check failure on line 78 in src/courseware/course/sidebar/sidebars/course-outline/hooks.js

View workflow job for this annotation

GitHub Actions / tests

Expected { after 'if' condition
return Object.values(sequences).find(seq => seq.unitIds.includes(unitId));
};
const activeSequence = findSequenceByUnitId(activeUnitId);
const targetSequence = findSequenceByUnitId(id);
if (!activeSequence || !targetSequence) {
return;
}
const payload = {
id: activeUnitId,
current_tab: activeSequence.unitIds.indexOf(activeUnitId) + 1,
Expand All @@ -95,7 +101,9 @@
};

logEvent('edx.ui.lms.sequence.tab_selected', 'left');
dispatch(checkBlockCompletion(courseId, sequenceId, activeUnitId));
if (activeUnitId) {
dispatch(checkBlockCompletion(courseId, sequenceId, activeUnitId));
}

// Hide the sidebar after selecting a unit on a mobile device.
if (shouldDisplayFullScreen) {
Expand Down
4 changes: 4 additions & 0 deletions src/courseware/data/thunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ export function fetchSequence(sequenceId, isPreview) {

export function checkBlockCompletion(courseId, sequenceId, unitId) {
return async (dispatch, getState) => {
if (!unitId) {
return {};
}

const { models } = getState();
if (models.units[unitId]?.complete) {
return {}; // do nothing. Things don't get uncompleted after they are completed.
Expand Down
Loading