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
Progress: fix script selector bugs #22248
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,6 +90,8 @@ export const ViewType = { | |
DETAIL: "detail", | ||
}; | ||
|
||
export const ACCELERATED_SCRIPT_ID = 1; | ||
|
||
/** | ||
* Shape for the section | ||
* The section we get directly from angular right now. This gives us a | ||
|
@@ -200,15 +202,13 @@ export default function sectionProgress(state=initialState, action) { | |
}; | ||
} | ||
if (action.type === SET_VALID_SCRIPTS) { | ||
// If no scriptId is assigned, use the first valid script. | ||
const defaultScriptId = state.scriptId || action.validScripts[0].id; | ||
|
||
let validScripts = action.validScripts; | ||
if (action.studentScriptIds && action.validCourses) { | ||
|
||
// Include the id for the Accelerated Course so that there will always be // at least one validScript and we don't end up with an empty dropdown. | ||
const idMap = {ACCELERATED_SCRIPT_ID: true}; | ||
// First, construct an id map consisting only of script ids which a | ||
// student has participated in. | ||
const idMap = {}; | ||
action.studentScriptIds.forEach(id => idMap[id] = true); | ||
|
||
// If the student has participated in a script which is a unit in a | ||
|
@@ -222,14 +222,35 @@ export default function sectionProgress(state=initialState, action) { | |
course.script_ids.forEach(id => idMap[id] = true); | ||
} | ||
}); | ||
|
||
validScripts = validScripts.filter(script => idMap[script.id]); | ||
|
||
var scriptId; | ||
switch (true) { | ||
// When there is a scriptId already in state. | ||
case !!state.scriptId: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice, I had not seen the |
||
scriptId = state.scriptId; | ||
break; | ||
// When there is an assigned course, set scriptId to the first script in the assigned course. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there is an assigned script, it will already have been set in state.scriptId, because the setSection action is currently called before setValidScripts. It seems confusing to have this logic spread out between setSection and setValidScripts. I would recommend passing in the whole section here, then using both section.course_id and section.script.id to determine which section to assign. If you don't have time to do this now, please add a comment indicating that (1) the logic is split between these two redux actions, and (2) it is required that setSection is called before setValidScripts in order for the right thing to happen in the case where a section has both a course and a script assigned. |
||
case !!action.assignedCourseId: | ||
action.validCourses.forEach(course => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not necessary to do right now, but you can return early from the |
||
if (course.id === action.assignedCourseId) { | ||
scriptId = course.script_ids[0]; | ||
} | ||
}); | ||
break; | ||
// If there are validScripts, set scriptId to the first valid script. | ||
case validScripts.length > 0: | ||
scriptId = validScripts[0].id; | ||
break; | ||
default: | ||
scriptId = ACCELERATED_SCRIPT_ID; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it should be safe to remove this default case, because validScripts will never be empty (always contains the accelerated course). |
||
} | ||
} | ||
|
||
return { | ||
...state, | ||
validScripts, | ||
scriptId: defaultScriptId, | ||
scriptId: scriptId, | ||
}; | ||
} | ||
if (action.type === ADD_SCRIPT_DATA) { | ||
|
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.
I'm not sure this will be popular from a product perspective. In the next PR, let's find a way to only add the accelerated course if the list would otherwise be empty.