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: Course selection bug followup #22289

Merged
merged 8 commits into from May 15, 2018
Merged

Conversation

Erin007
Copy link
Contributor

@Erin007 Erin007 commented May 9, 2018

Follow up to #22248. Change default script from Accelerated to Express, update tests to match and only show the default script in the dropdown if the dropdown would otherwise be empty.

@Erin007 Erin007 changed the base branch from staging to multi-script-course-selection May 10, 2018 00:34
@Erin007 Erin007 changed the base branch from multi-script-course-selection to course-selection-bug May 10, 2018 00:36
@Erin007 Erin007 changed the base branch from course-selection-bug to staging May 10, 2018 00:36
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.

LGTM after addressing comments (though not necessary to do the extractions now). apologies that some of these comments relate to stuff from previous PRs and the extraction comments even refer to some code that I initially added 😳 it just seems like that section is getting big enough that it's time to clean it up a bit.

@@ -204,9 +202,11 @@ export default function sectionProgress(state=initialState, action) {
if (action.type === SET_VALID_SCRIPTS) {

let validScripts = action.validScripts;
// Set defaultScript to Express Course to use if there are no validScripts
let defaultScript = action.validScripts.filter(script => script.name === "Express Course")[0];
Copy link
Member

Choose a reason for hiding this comment

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

style nits:

  • let validScripts --> const validScripts (on previous line)
  • .filter(...)[0] --> .find(...)
  • let defaultScript --> const defaultScript
  • action.validScripts --> validScripts
  • var --> let (line 227)

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 on dave's comment. we end up using "Express Course" in a few places now, so i would also pull this out into a constant called DEFAULT_SCRIPT_NAME (or something along those lines)

// Use the default script (currently Express Course) so we don't have
// an empty dropdown.
scriptId = defaultScript.id;
validScripts.push(defaultScript);
Copy link
Member

Choose a reason for hiding this comment

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

this is starting to get a bit confusing, because now the part of the function that determines the scriptId is also modifying validScripts. As a first step, I would recommend moving the logic for if (validScripts.length === 0) {validScripts.push(defaultScript)} to line 226 and replacing the default and last case statement here with just

default:
  scriptId = validScripts[0].id

and also adding a comment explaining that one section computes validScripts and the other computes scriptId.

Ideally you would extract 1 or 2 self-documenting functions like this:

if (action.type === SET_VALID_SCRIPTS) {
  const validScripts = computeValidScripts(...)
  const scriptId = getDefaultScriptId(...)
}

but given the time constraints it seems ok not to do that now.

@@ -50,7 +50,6 @@ export default class ScriptSelector extends Component {
onChange={event => onChange(parseInt(event.target.value))}
style={styles.dropdown}
>
<option key="default" value={''}/>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed this because clicking on the empty string option would cause all kinds of problems because it didn't set a scriptId, and the default script is now "Express Course"

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for doing this @Erin007 ! FYI @poorvasingal that there should no longer be an empty option in the progress tab's script selector.

@Erin007 Erin007 merged commit 938bd8a into staging May 15, 2018
@Erin007 Erin007 deleted the course-selection-bug-followup branch May 15, 2018 19:18
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.

Nice updates, Erin!

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

3 participants