Skip to content
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

Merged
merged 2 commits into from May 10, 2018
Merged

Progress: fix script selector bugs #22248

merged 2 commits into from May 10, 2018

Conversation

Erin007
Copy link
Contributor

@Erin007 Erin007 commented May 8, 2018

This PR updates the logic for what should be shown in the ScriptSelector dropdown on the progress tab. Currently, with the sectionProgressRedesign experiment on, there is a bug where if a course is assigned to a section, we do not correctly show that course in this dropdown menu. To fix this bug, I exposed some of @davidsbailey course versioning work from behind its flag to access assignedCourseId. In doing so, I exposed a different bug, wherein if there are no assigned courses or scripts and no progress for the section's students, we were filtering every validScript out of the possible options to show in the dropdown. To fix this second bug, I always keep the Accelerated Course (scriptId === 1) in the dropdown.

  • If the section is assigned a course, we should show the first unit of that course by default in the dropdown.

  • If the section is assigned a script, we should show the that script in the dropdown.

  • If there is neither an assigned course nor an assigned script, but any of the section's students have made progress in scripts, we should show the first valid script associated with students in the section.

  • If none of the above, we show the Accelerated Course by default to avoid having an empty dropdown.

sectionProgressRedux tests have been updated accordingly.

Copy link
Member

@davidsbailey davidsbailey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple things to consider changing. That said, I've got a PR coming in right behind this touching the same files, so I'm voting for merging as-is and then doing any updates in a follow-up PR.

case !!state.scriptId:
scriptId = state.scriptId;
break;
// When there is an assigned course, set scriptId to the first script in the assigned course.
Copy link
Member

Choose a reason for hiding this comment

The 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.

var scriptId;
switch (true) {
// When there is a scriptId already in state.
case !!state.scriptId:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, I had not seen the switch (true) pattern before but it looks legit.


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};
Copy link
Member

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.

scriptId = validScripts[0].id;
break;
default:
scriptId = ACCELERATED_SCRIPT_ID;
Copy link
Member

Choose a reason for hiding this comment

The 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).

@caleybrock
Copy link
Contributor

Logic in description makes sense to me 👍

break;
// When there is an assigned course, set scriptId to the first script in the assigned course.
case !!action.assignedCourseId:
action.validCourses.forEach(course => {
Copy link
Contributor

Choose a reason for hiding this comment

The 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 forEach loop once scriptId has been assigned a value

Copy link
Contributor

@maddiedierker maddiedierker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great work! and i second @davidsbailey's comment. there are a couple of test failures around what /v2/sections/valid_scripts is returning (they seem unrelated, i think), but everything on your end looks good

@Erin007 Erin007 merged commit 25d65c7 into staging May 10, 2018
@Erin007 Erin007 deleted the course-selection-bug branch May 10, 2018 05:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants