Make lesson extras flag match bubble choice behavior#39733
Conversation
1c4a4b4 to
c561625
Compare
9948d37 to
f28d882
Compare
f28d882 to
0d2bf2b
Compare
jamescodeorg
left a comment
There was a problem hiding this comment.
Thanks for the detailed PR description!
| const {isLessonExtras, levels, currentLevelId} = this.props; | ||
| return ( | ||
| isLessonExtras || | ||
| !!levels.find(level => level.id === currentLevelId && level.bonus) |
There was a problem hiding this comment.
Is there always at most 1 bonus level per lesson?
There was a problem hiding this comment.
no. why do you ask? this is checking that we're on the level select page (isLessonExtras), or that the current level is a bonus level (level.id === currentLevelId && level.bonus). i can add a comment to explain that.
There was a problem hiding this comment.
Never mind, I think I just misread this.
There was a problem hiding this comment.
!!levels.find could also be written as levels.some here
| script_data = script.summarize_header | ||
| lesson_group_data = script.lesson_groups.map(&:summarize) | ||
| stage_data = (@stage || script_level.lesson).summarize | ||
| stage_data = (@stage || script_level.lesson).summarize(true) |
There was a problem hiding this comment.
Why is this change needed?
Also, very minor, including the param name here might help readability.
There was a problem hiding this comment.
that true is for the include_bonus_levels param, but i couldn't figure out how to include the param name. i figured it out now, and imo summarize(include_bonus_levels = true) explains the need for the change, but lmk if you think i should also add a comment.
There was a problem hiding this comment.
Sorry, I'm still not clear what's going on here, probably because I don't have a clear picture of where stage_data ends up getting used. Where does the information about the bonus levels eventually get used? What happened before when we didn't have this information?
There was a problem hiding this comment.
that data is passed down to the LessonProgress component used in the header. previously, since we didn't indicate user progress for bonus levels in the header, we didn't need any level-specific data. the flag was conditionally displayed based on the presence of lessonExtrasUrl (still true), and it was colored green if isLessonExtras (now that value is only used to determine if lesson extras is "selected"). to enable the flag to be colored based on user progress, we now need to include the level-specific data for the bonus levels. this is handled in LessonProgress.isOnBonusLevel() and LessonProgress.isBonusComplete()
| user_level = UserLevel.find_by( | ||
| level_id: level_summary[:level_id], user_id: user.id, script: @script | ||
| ) | ||
| level_summary[:perfect] = user_level ? true : false |
There was a problem hiding this comment.
Not sure if this change was intentional or not, but the true case used to return user_level&.perfect?
There was a problem hiding this comment.
that call is redundant because user_level != nil === user_level.perfect? == true, but level_summary[:perfect] = user_level&.perfect? seems clearer, so i will update
| @script = @stage.script | ||
| script_bonus_levels_by_stage = @script.get_bonus_script_levels(@stage) | ||
|
|
||
| # get user progress for bonus levels |
There was a problem hiding this comment.
I think it'd be good to elaborate on this comment a bit and indicate why we're doing this here. Also, this loop now also sets the localized display name so may want to move/adjust this comment.
| } | ||
|
|
||
| isBonusComplete() { | ||
| return !!this.props.levels.find( |
There was a problem hiding this comment.
This could also be written as return this.props.levels.some(level => level.bonus && level.status === LevelStatus.perfect)
while investigating LP-1512, i found four distinct bugs around our lesson extras flag.
1
currently, the "lesson extras flag" in the header on our level pages does not update its appearance based on student progress. rather, it simply displays as green on the lesson extras (bonus) level selection page, and grey everywhere else. this PR updates it to more closely match the behavior of the header bubble for a bubble choice level.
the new behavior is that when there is no progress, it displays as small and grey when on another level in the lesson, and large and charcoal when on the bonus level select page and on the actual level page for a bonus level. when there is progress, it displays as small and green when on another level, and large and green on the level select / bonus level pages.
before:



other level
level select
bonus level
after:




other level -- no progress
level select / bonus level -- no progress
other level -- with progress
level select / bonus level -- with progress
2
currently, we cache bonus level summaries on a script instance, and when summarizing the bonus levels, we pass in the current user to get a user-specific summary. however, our script instances are cached per EC2 instance, which means that when we retrieve bonus level summaries, they include user-specific data for whatever user first viewed those bonus levels on that EC2 instance! consequently, every time the page is reloaded it will show the data cached on the EC2 instance that our load balancer routed to.
this results in very unexpected behavior, because each page reload will potentially show different progress, and occasionally even a different language!
this PR updates it so we don't include user data in the cached summaries, and instead add it per request.
3
currently, we pass
current_userinto the level summarization method instead of the user id included in the request. consequently we would always show a teacher's progress even when they're viewing as a student. this bug was obscured by bug 2 on production, and is fixed by the solution to same. however, this PR still updates our calls tonext_level_number_for_lesson_extrasandnext_level_path_for_lesson_extrasto pass the correct user.4
our
LessonExtrasProgressBubblecomponent appends any current query params to the url to preserve section and user selection. however, the route for a specific bonus level page includes the level id in the params, which means that the flag icon in the header will start to preserve the level selection once the user has navigated to a specific level, making it impossible to get back to the level select page (without modifying the url). this PR updates that component to remove the level id from the query params that it appends.Links
there are links to four related zendesk tickets in the jira ticket.