Skip to content

Commit 8aeaaf4

Browse files
feat: [FC-0070] add message events and styles to the library content page (#35785)
This introduces improvements for XBlock interactions within iframes: * Add default styles for Library Content that renders in the iframe in the new Studio unit page * When the `isIframeEmbed` option is enabled, the XBlock sends a `postMessage` to the parent window. When sending such a message, the standard link transition is cancelled and the transition is carried out in the MFE.
1 parent b885618 commit 8aeaaf4

File tree

5 files changed

+111
-26
lines changed

5 files changed

+111
-26
lines changed

cms/djangoapps/contentstore/views/tests/test_block.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,10 @@ def test_get_container_nested_container_fragment(self):
265265
html,
266266
# The instance of the wrapper class will have an auto-generated ID. Allow any
267267
# characters after wrapper.
268-
'"/container/{}" class="action-button">\\s*<span class="action-button-text">View</span>'.format(
269-
re.escape(str(wrapper_usage_key))
270-
),
268+
(
269+
'"/container/{}" class="action-button xblock-view-action-button">'
270+
'\\s*<span class="action-button-text">View</span>'
271+
).format(re.escape(str(wrapper_usage_key))),
271272
)
272273

273274
@patch("cms.djangoapps.contentstore.xblock_storage_handlers.xblock_helpers.get_object_tag_counts")

cms/static/js/views/pages/container.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ function($, _, Backbone, gettext, BasePage,
3939
'click .manage-tags-button': 'openManageTags',
4040
'change .header-library-checkbox': 'toggleLibraryComponent',
4141
'click .collapse-button': 'collapseXBlock',
42+
'click .xblock-view-action-button': 'viewXBlockContent',
4243
},
4344

4445
options: {
@@ -808,10 +809,6 @@ function($, _, Backbone, gettext, BasePage,
808809
this.deleteComponent(this.findXBlockElement(event.target));
809810
},
810811

811-
createPlaceholderElement: function() {
812-
return $('<div/>', {class: 'studio-xblock-wrapper'});
813-
},
814-
815812
createComponent: function(template, target) {
816813
// A placeholder element is created in the correct location for the new xblock
817814
// and then onNewXBlock will replace it with a rendering of the xblock. Note that
@@ -905,6 +902,26 @@ function($, _, Backbone, gettext, BasePage,
905902
}
906903
},
907904

905+
viewXBlockContent: function(event) {
906+
try {
907+
if (this.options.isIframeEmbed) {
908+
event.preventDefault();
909+
var usageId = event.currentTarget.href.split('/').pop() || '';
910+
window.parent.postMessage(
911+
{
912+
type: 'handleViewXBlockContent',
913+
payload: {
914+
usageId: usageId,
915+
},
916+
}, document.referrer
917+
);
918+
return true;
919+
}
920+
} catch (e) {
921+
console.error(e);
922+
}
923+
},
924+
908925
toggleSaveButton: function() {
909926
var $saveButton = $('.nav-actions .save-button');
910927
if (JSON.stringify(this.selectedLibraryComponents.sort()) === JSON.stringify(this.storedSelectedLibraryComponents.sort())) {

cms/static/sass/course-unit-mfe-iframe-bundle.scss

Lines changed: 80 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
@import 'cms/theme/variables-v1';
22
@import 'elements/course-unit-mfe-iframe';
33

4+
body {
5+
min-width: 800px;
6+
}
7+
48
.wrapper {
9+
.inner-wrapper {
10+
max-width: 100%;
11+
}
12+
513
.wrapper-xblock {
614
background-color: $transparent;
715
border-radius: 6px;
816
border: none;
917

1018
&:hover {
11-
border-color: none;
19+
border-color: transparent;
1220
}
1321

1422
.xblock-header-primary {
@@ -23,6 +31,54 @@
2331
}
2432
}
2533

34+
.xblock-header-secondary {
35+
border-radius: 0 0 4px 4px;
36+
37+
.actions-list .action-item .action-button {
38+
border-radius: 4px;
39+
40+
&:hover {
41+
background-color: $primary;
42+
color: $white;
43+
}
44+
}
45+
}
46+
47+
&.level-page .xblock-message {
48+
padding: ($baseline * .75) ($baseline * 1.2);
49+
border-radius: 0 0 4px 4px;
50+
51+
&.information {
52+
color: $text-color;
53+
background-color: $xblock-message-info-bg;
54+
border-color: $xblock-message-info-border-color;
55+
}
56+
57+
&.validation.has-warnings {
58+
color: $black;
59+
background-color: $xblock-message-warning-bg;
60+
border-color: $xblock-message-warning-border-color;
61+
border-top-width: 1px;
62+
63+
.icon {
64+
color: $xblock-message-warning-border-color;
65+
}
66+
}
67+
68+
a {
69+
color: $primary;
70+
}
71+
}
72+
73+
.xblock-author_view-library_content > .wrapper-xblock-message .xblock-message {
74+
font-size: 16px;
75+
line-height: 22px;
76+
border-radius: 4px;
77+
padding: ($baseline * 1.2);
78+
box-shadow: 0 1px 2px rgba(0, 0, 0, .15), 0 1px 4px rgba(0, 0, 0, .15);
79+
margin-bottom: ($baseline * 1.4);
80+
}
81+
2682
&.level-element {
2783
box-shadow: 0 2px 4px rgba(0, 0, 0, .15), 0 2px 8px rgba(0, 0, 0, .15);
2884
margin: 0 0 ($baseline * 1.4) 0;
@@ -40,28 +96,34 @@
4096
border-bottom-right-radius: 6px;
4197
}
4298

43-
.wrapper-xblock .header-actions .actions-list .action-item .action-button {
44-
@extend %button-styles;
99+
.wrapper-xblock .header-actions .actions-list {
100+
.action-actions-menu:last-of-type .nav-sub {
101+
right: 120px;
102+
}
45103

46-
color: $primary;
104+
.action-item .action-button {
105+
@extend %button-styles;
47106

48-
.fa-ellipsis-v {
49-
font-size: $base-font-size;
50-
}
107+
color: $primary;
51108

52-
&:hover {
53-
background-color: $primary;
54-
color: $white;
55-
border-color: $transparent;
109+
.fa-ellipsis-v {
110+
font-size: $base-font-size;
111+
}
112+
113+
&:hover {
114+
background-color: $primary;
115+
color: $white;
116+
border-color: $transparent;
56117
color: $white;
57118
}
58119

59-
&:focus {
60-
outline: 2px $transparent;
61-
background-color: $transparent;
62-
box-shadow: inset 0 0 0 2px $primary;
63-
color: $primary;
64-
border-color: $transparent;
120+
&:focus {
121+
outline: 2px $transparent;
122+
background-color: $transparent;
123+
box-shadow: inset 0 0 0 2px $primary;
124+
color: $primary;
125+
border-color: $transparent;
126+
}
65127
}
66128
}
67129

@@ -631,7 +693,7 @@ select {
631693
}
632694
}
633695

634-
.xblock-header-primary {
696+
.xblock-header:not(.xblock-header-library_content, .xblock-header-split_test) .xblock-header-primary {
635697
position: relative;
636698

637699
&::before {

cms/static/sass/partials/cms/theme/_variables-v1.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,3 +315,8 @@ $base-font-size: 18px !default;
315315
$dark: #212529;
316316

317317
$zindex-dropdown: 100;
318+
319+
$xblock-message-info-bg: #eff8fa;
320+
$xblock-message-info-border-color: #9cd2e6;
321+
$xblock-message-warning-bg: #fffdf0;
322+
$xblock-message-warning-border-color: #fff6bf;

cms/templates/studio_xblock_wrapper.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@
229229
<div class="meta-info">${_('This block contains multiple components.')}</div>
230230
<ul class="actions-list">
231231
<li class="action-item action-view">
232-
<a href="${xblock_url}" class="action-button">
232+
<a href="${xblock_url}" class="action-button xblock-view-action-button">
233233
## Translators: this is a verb describing the action of viewing more details
234234
<span class="action-button-text">${('View')}</span>
235235
<span class="icon fa fa-arrow-right" aria-hidden="true"></span>

0 commit comments

Comments
 (0)