From f9e071531bee31a5a240454f7100c9cb61615ea4 Mon Sep 17 00:00:00 2001 From: Navin Karkera Date: Thu, 7 Nov 2024 19:29:11 +0530 Subject: [PATCH 1/3] feat: add beta flag to component templates --- cms/djangoapps/contentstore/views/component.py | 5 ++++- cms/static/js/models/component_template.js | 4 +++- cms/static/js/views/components/add_xblock_button.js | 3 ++- cms/templates/js/add-xblock-component-button.underscore | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/cms/djangoapps/contentstore/views/component.py b/cms/djangoapps/contentstore/views/component.py index 6767467e20f4..a983309b3287 100644 --- a/cms/djangoapps/contentstore/views/component.py +++ b/cms/djangoapps/contentstore/views/component.py @@ -60,6 +60,8 @@ 'drag-and-drop-v2', ] +BETA_COMPONENT_TYPES = ['library_v2', 'itembank'] + ADVANCED_COMPONENT_TYPES = sorted({name for name, class_ in XBlock.load_classes()} - set(COMPONENT_TYPES)) ADVANCED_PROBLEM_TYPES = settings.ADVANCED_PROBLEM_TYPES @@ -419,7 +421,8 @@ def create_support_legend_dict(): "type": category, "templates": templates_for_category, "display_name": component_display_names[category], - "support_legend": create_support_legend_dict() + "support_legend": create_support_legend_dict(), + "beta": category in BETA_COMPONENT_TYPES, }) # Libraries do not support advanced components at this time. diff --git a/cms/static/js/models/component_template.js b/cms/static/js/models/component_template.js index b2306d40e9c8..358b7b2f3433 100644 --- a/cms/static/js/models/component_template.js +++ b/cms/static/js/models/component_template.js @@ -11,7 +11,8 @@ define(['backbone'], function(Backbone) { // boilerplate_name (may be null) // is_common (only used for problems) templates: [], - support_legend: {} + support_legend: {}, + beta: false, }, parse: function(response) { // Returns true only for templates that both have no boilerplate and are of @@ -26,6 +27,7 @@ define(['backbone'], function(Backbone) { this.templates = response.templates; this.display_name = response.display_name; this.support_legend = response.support_legend; + this.beta = response.beta; // Sort the templates. this.templates.sort(function(a, b) { diff --git a/cms/static/js/views/components/add_xblock_button.js b/cms/static/js/views/components/add_xblock_button.js index 36b420a61068..4fa4d2effeff 100644 --- a/cms/static/js/views/components/add_xblock_button.js +++ b/cms/static/js/views/components/add_xblock_button.js @@ -8,7 +8,8 @@ define(['js/views/baseview', 'edx-ui-toolkit/js/utils/html-utils'], var attributes = { type: this.model.type, templates: this.model.templates, - display_name: this.model.display_name + display_name: this.model.display_name, + beta: this.model.beta, }; BaseView.prototype.initialize.call(this); this.template = this.loadTemplate('add-xblock-component-button'); diff --git a/cms/templates/js/add-xblock-component-button.underscore b/cms/templates/js/add-xblock-component-button.underscore index b591c336938c..df100d6dfcd1 100644 --- a/cms/templates/js/add-xblock-component-button.underscore +++ b/cms/templates/js/add-xblock-component-button.underscore @@ -6,7 +6,7 @@ <%- gettext("Add Component:") %> <%- display_name %> - <% if (type === 'library_v2' || type === 'itembank') { %> + <% if (beta) { %> <%- gettext("Beta") %> <% } %> From a8d5aede7a8e503dd6b05178af93a23b38cb3b59 Mon Sep 17 00:00:00 2001 From: Navin Karkera Date: Mon, 11 Nov 2024 15:58:12 +0530 Subject: [PATCH 2/3] feat: update component order --- cms/djangoapps/contentstore/views/component.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cms/djangoapps/contentstore/views/component.py b/cms/djangoapps/contentstore/views/component.py index a983309b3287..4fd4fd66960b 100644 --- a/cms/djangoapps/contentstore/views/component.py +++ b/cms/djangoapps/contentstore/views/component.py @@ -49,14 +49,14 @@ # NOTE: This list is disjoint from ADVANCED_COMPONENT_TYPES COMPONENT_TYPES = [ - 'discussion', - 'library', - 'library_v2', # Not an XBlock - 'itembank', 'html', - 'openassessment', - 'problem', 'video', + 'problem', + 'itembank', + 'library_v2', # Not an XBlock + 'library', + 'discussion', + 'openassessment', 'drag-and-drop-v2', ] @@ -472,7 +472,7 @@ def create_support_legend_dict(): course_advanced_keys ) if advanced_component_templates['templates']: - component_templates.insert(0, advanced_component_templates) + component_templates.append(advanced_component_templates) return component_templates From f3e6bbb072a88a7ca604dee01df312b7be596681 Mon Sep 17 00:00:00 2001 From: Navin Karkera Date: Tue, 12 Nov 2024 16:05:07 +0530 Subject: [PATCH 3/3] test: fix test to match new component order --- cms/djangoapps/contentstore/views/tests/test_block.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cms/djangoapps/contentstore/views/tests/test_block.py b/cms/djangoapps/contentstore/views/tests/test_block.py index f3e20b45b2ea..a6fefe5f554c 100644 --- a/cms/djangoapps/contentstore/views/tests/test_block.py +++ b/cms/djangoapps/contentstore/views/tests/test_block.py @@ -3184,13 +3184,13 @@ def _verify_advanced_xblocks(self, expected_xblocks, expected_support_levels): templates = get_component_templates(self.course) button_names = [template["display_name"] for template in templates] self.assertIn("Advanced", button_names) - self.assertEqual(len(templates[0]["templates"]), len(expected_xblocks)) + self.assertEqual(len(templates[-1]["templates"]), len(expected_xblocks)) template_display_names = [ - template["display_name"] for template in templates[0]["templates"] + template["display_name"] for template in templates[-1]["templates"] ] self.assertEqual(template_display_names, expected_xblocks) template_support_levels = [ - template["support_level"] for template in templates[0]["templates"] + template["support_level"] for template in templates[-1]["templates"] ] self.assertEqual(template_support_levels, expected_support_levels)