feat!: Change the way tabs are ordered [BD-38] [TNL-9174] [BB-5076] (#29262)

* feat!: Change the way tabs are ordered
The change imposes a new ordering for tabs based on their new priority. When reordering tabs, this ordering will be maintained.

* fix: Apply suggestions from code review

Co-authored-by: Farhaan Bukhsh <farhaan@opencraft.com>

* fix: review feedback

Co-authored-by: Farhaan Bukhsh <farhaan@opencraft.com>
This commit is contained in:
Kshitij Sobti
2021-11-22 06:17:30 +00:00
committed by GitHub
parent 2e2701d82a
commit e8e8f4acbe
16 changed files with 115 additions and 140 deletions

View File

@@ -302,6 +302,7 @@ class StaticTab(CourseTab):
type = 'static_tab'
is_default = False # A static tab is never added to a course by default
allow_multiple = True
priority = 100
def __init__(self, tab_dict=None, name=None, url_slug=None):
def link_func(course, reverse_func):
@@ -381,14 +382,14 @@ class CourseTabList(List):
within the course.
"""
course.tabs.extend([
course_tabs = [
CourseTab.load('course_info'),
CourseTab.load('courseware')
])
]
# Presence of syllabus tab is indicated by a course attribute
if hasattr(course, 'syllabus_present') and course.syllabus_present:
course.tabs.append(CourseTab.load('syllabus'))
course_tabs.append(CourseTab.load('syllabus'))
# If the course has a discussion link specified, use that even if we feature
# flag discussions off. Disabling that is mostly a server safety feature
@@ -400,12 +401,16 @@ class CourseTabList(List):
else:
discussion_tab = CourseTab.load('discussion')
course.tabs.extend([
course_tabs.extend([
CourseTab.load('textbooks'),
discussion_tab,
CourseTab.load('wiki'),
CourseTab.load('progress'),
])
# While you should be able to do `tab.priority`, a lot of tests mock tabs to be a dict
# which causes them to throw an error on this line
course_tabs.sort(key=lambda tab: getattr(tab, 'priority', None) or float('inf'))
course.tabs.extend(course_tabs)
@staticmethod
def get_discussion(course):