From dc0fdfc7248674a303f3750ea5e5547d93fdc536 Mon Sep 17 00:00:00 2001 From: Muhammad Anas Date: Mon, 17 Aug 2026 15:29:32 +0500 Subject: [PATCH] fix: restore add-component buttons for content experiment groups --- cms/static/js/spec/views/pages/container_spec.js | 15 +++++++++++++++ cms/static/js/views/pages/container.js | 11 +++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/cms/static/js/spec/views/pages/container_spec.js b/cms/static/js/spec/views/pages/container_spec.js index d1bf0cdd9ea9..12694edf8127 100644 --- a/cms/static/js/spec/views/pages/container_spec.js +++ b/cms/static/js/spec/views/pages/container_spec.js @@ -160,6 +160,21 @@ function parameterized_suite(label, globalPageOptions) { }); }); + describe('Add component buttons when embedded in the authoring MFE', function() { + it('removes the buttons for a unit, since the MFE renders its own', function() { + renderContainerPage(this, mockContainerXBlockHtml, {isIframeEmbed: true}); + expect(containerPage.$('.add-xblock-component').length).toBe(0); + }); + + it('keeps the buttons for a content experiment, where the MFE renders none', function() { + model.set('category', 'split_test'); + renderContainerPage(this, mockContainerXBlockHtml, {isIframeEmbed: true}); + // One panel per experiment group, each with its own component buttons. + expect(containerPage.$('.add-xblock-component').length).toBe(2); + expect(containerPage.$('.add-xblock-component-button').length).toBeGreaterThan(0); + }); + }); + describe('Editing the container', function() { var updatedDisplayName = 'Updated Test Container', getDisplayNameWrapper; diff --git a/cms/static/js/views/pages/container.js b/cms/static/js/views/pages/container.js index d7cc7e95ec3d..d4afa4cab692 100644 --- a/cms/static/js/views/pages/container.js +++ b/cms/static/js/views/pages/container.js @@ -313,10 +313,13 @@ function($, _, Backbone, gettext, BasePage, renderAddXBlockComponents: function() { var self = this; - // When rendered inside the authoring MFE iframe, add buttons are always rendered - // natively by the MFE (for every container type, not just verticals), so the - // legacy add-button widgets must never be initialised here. - if (self.options.canEdit && !self.options.isIframeEmbed) { + // When rendered inside the authoring MFE iframe, add buttons are normally rendered + // natively by the MFE, so the legacy add-button widgets must not be initialised here. + // Content experiments (split_test) are the exception: the MFE renders no add buttons + // for them, because each group needs its own set of buttons next to its children, + // which only this page can place. The rest of that flow is already iframe-aware -- + // see the split_test branches in createComponent() and in add_xblock.js. + if (self.options.canEdit && (!self.options.isIframeEmbed || self.isSplitTestContentPage)) { this.$('.add-xblock-component').each(function(index, element) { var component = new AddXBlockComponent({ el: element,