-
Notifications
You must be signed in to change notification settings - Fork 479
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
Changes from 4 commits
6c152a7
67a22d9
6aa7e1b
b73c234
75c6484
e59f290
955f680
bc632a7
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,8 +90,6 @@ 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 | ||
|
@@ -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]; | ||
|
||
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}; | ||
const idMap = {}; | ||
// First, construct an id map consisting only of script ids which a | ||
// student has participated in. | ||
action.studentScriptIds.forEach(id => idMap[id] = true); | ||
|
@@ -243,7 +243,10 @@ export default function sectionProgress(state=initialState, action) { | |
scriptId = validScripts[0].id; | ||
break; | ||
default: | ||
scriptId = ACCELERATED_SCRIPT_ID; | ||
// Use the default script (currently Express Course) so we don't have | ||
// an empty dropdown. | ||
scriptId = defaultScript.id; | ||
validScripts.push(defaultScript); | ||
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. this is starting to get a bit confusing, because now the part of the function that determines the 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. |
||
} | ||
} | ||
|
||
|
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.
style nits:
let validScripts
-->const validScripts
(on previous line).filter(...)[0]
-->.find(...)
let defaultScript
-->const defaultScript
action.validScripts
-->validScripts
var
-->let
(line 227)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.
+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)