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

fix(redwood): show correct icons in the sidebar for units with custom XBlocks #726

Open
wants to merge 1 commit into
base: opencraft-release/redwood.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lms/djangoapps/course_api/blocks/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def __init__(
SupportedFieldType('weight'),
SupportedFieldType('show_correctness'),
SupportedFieldType('hide_from_toc'),
SupportedFieldType('icon_class'),
# 'student_view_data'
SupportedFieldType(StudentViewTransformer.STUDENT_VIEW_DATA, StudentViewTransformer),
# 'student_view_multi_device'
Expand Down
10 changes: 9 additions & 1 deletion lms/djangoapps/course_api/blocks/transformers/blocks_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,15 @@ def collect(cls, block_structure):
transform method.
"""
# collect basic xblock fields
block_structure.request_xblock_fields('graded', 'format', 'display_name', 'category', 'due', 'show_correctness')
block_structure.request_xblock_fields(
'graded',
'format',
'display_name',
'category',
'due',
'show_correctness',
'icon_class',
)

# collect data from containing transformers
StudentViewTransformer.collect(block_structure)
Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/course_home_api/outline/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def get_vertical_icon_class(block):
video
"""
children = block.get('children', [])
child_classes = {child.get('type') for child in children}
child_classes = {value for child in children for value in (child.get('type'), child.get('icon_class'))}
if 'problem' in child_classes:
return 'problem'
if 'video' in child_classes:
Expand Down
30 changes: 30 additions & 0 deletions lms/djangoapps/course_home_api/outline/tests/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,3 +796,33 @@ def test_blocks_completion_stat_all_problem_completed(self):
assert vertical_data['complete']
assert sequence_data['completion_stat'] == expected_sequence_completion_stat
assert vertical_data['completion_stat'] == expected_vertical_completion_stat

@ddt.data(
(['html'], 'other'),
(['html', 'video'], 'video'),
(['html', 'video', 'problem'], 'problem'),
)
@ddt.unpack
def test_vertical_icon(self, block_categories, expected_icon):
"""Test that the API checks the children `category` to determine the icon for the unit."""
self.add_blocks_to_course()
CourseEnrollment.enroll(self.user, self.course.id)

for category in block_categories:
BlockFactory.create(parent=self.vertical, category=category)

response = self.client.get(reverse('course-home:course-navigation', args=[self.course.id]))
vertical_data = response.data['blocks'][str(self.vertical.location)]

assert vertical_data['icon'] == expected_icon

@patch('xmodule.html_block.HtmlBlock.icon_class', 'video')
def test_vertical_icon_determined_by_icon_class(self):
"""Test that the API checks the children `icon_class` to determine the icon for the unit."""
self.add_blocks_to_course()
CourseEnrollment.enroll(self.user, self.course.id)

BlockFactory.create(parent=self.vertical, category='html')
response = self.client.get(reverse('course-home:course-navigation', args=[self.course.id]))
vertical_data = response.data['blocks'][str(self.vertical.location)]
assert vertical_data['icon'] == 'video'
1 change: 1 addition & 0 deletions openedx/features/course_experience/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def recurse_mark_auth_denial(block):
'complete',
'resume_block',
'hide_from_toc',
'icon_class',
],
allow_start_dates_in_future=allow_start_dates_in_future,
)
Expand Down
Loading