-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
feat: adds Library Content button to Studio Unit page [FC-0062] #35670
Changes from all commits
926d75e
b38cfb2
38d6ea6
6fbf75b
3ca4afd
bc27ba3
d6e0852
c631a35
0da35c1
d7a627c
58abdfc
6957789
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* Provides utilities to open and close the library content picker. | ||
* | ||
*/ | ||
define(['jquery', 'underscore', 'gettext', 'js/views/modals/base_modal'], | ||
function($, _, gettext, BaseModal) { | ||
'use strict'; | ||
|
||
var AddLibraryContent = BaseModal.extend({ | ||
options: $.extend({}, BaseModal.prototype.options, { | ||
modalName: 'add-component-from-library', | ||
modalSize: 'lg', | ||
view: 'studio_view', | ||
viewSpecificClasses: 'modal-add-component-picker confirm', | ||
// Translators: "title" is the name of the current component being edited. | ||
titleFormat: gettext('Add library content'), | ||
addPrimaryActionButton: false, | ||
}), | ||
|
||
initialize: function() { | ||
BaseModal.prototype.initialize.call(this); | ||
// Add event listen to close picker when the iframe tells us to | ||
const handleMessage = (event) => { | ||
if (event.data?.type === 'pickerComponentSelected') { | ||
var requestData = { | ||
library_content_key: event.data.usageKey, | ||
category: event.data.category, | ||
} | ||
this.refreshFunction(requestData); | ||
this.hide(); | ||
} | ||
}; | ||
this.messageListener = window.addEventListener("message", handleMessage); | ||
this.cleanupListener = () => { window.removeEventListener("message", handleMessage) }; | ||
}, | ||
|
||
hide: function() { | ||
BaseModal.prototype.hide.call(this); | ||
this.cleanupListener(); | ||
}, | ||
|
||
/** | ||
* Adds the action buttons to the modal. | ||
*/ | ||
addActionButtons: function() { | ||
this.addActionButton('cancel', gettext('Cancel')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be fixed in a fast-follow PR (because I'm eager to get this into testing ASAP), but it's not a great UX that the "Next" button is sometimes hidden until you scroll, and the Next + Cancel buttons are in totally different places. I think they need to either be both inside the modal or both in the legy UI actions bar. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, do we even need a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed next button and updated it to go to component selection on library selection. vokoscreenNG-2024-10-21_11-16-03.mp4There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense to me! |
||
}, | ||
|
||
/** | ||
* Show a component picker modal from library. | ||
* @param contentPickerUrl Url for component picker | ||
* @param refreshFunction A function to refresh the block after it has been updated | ||
*/ | ||
showComponentPicker: function(contentPickerUrl, refreshFunction) { | ||
this.contentPickerUrl = contentPickerUrl; | ||
this.refreshFunction = refreshFunction; | ||
|
||
this.render(); | ||
this.show(); | ||
}, | ||
|
||
getContentHtml: function() { | ||
return `<iframe src="${this.contentPickerUrl}" onload="this.contentWindow.focus()" frameborder="0" style="width: 100%; height: 100%;"/>`; | ||
}, | ||
}); | ||
|
||
return AddLibraryContent; | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -214,7 +214,8 @@ function($, _, Backbone, gettext, BasePage, | |
var component = new AddXBlockComponent({ | ||
el: element, | ||
createComponent: _.bind(self.createComponent, self), | ||
collection: self.options.templates | ||
collection: self.options.templates, | ||
libraryContentPickerUrl: self.options.libraryContentPickerUrl, | ||
}); | ||
component.render(); | ||
}); | ||
|
@@ -224,7 +225,7 @@ function($, _, Backbone, gettext, BasePage, | |
}, | ||
|
||
initializePasteButton() { | ||
if (this.options.canEdit && !self.options.isIframeEmbed) { | ||
if (this.options.canEdit && !this.options.isIframeEmbed) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixes a typo/bug introduced in #35587 |
||
// We should have the user's clipboard status. | ||
const data = this.options.clipboardData; | ||
this.refreshPasteButton(data); | ||
|
@@ -241,7 +242,7 @@ function($, _, Backbone, gettext, BasePage, | |
refreshPasteButton(data) { | ||
// Do not perform any changes on paste button since they are not | ||
// rendered on Library or LibraryContent pages | ||
if (!this.isLibraryPage && !this.isLibraryContentPage && !self.options.isIframeEmbed) { | ||
if (!this.isLibraryPage && !this.isLibraryContentPage && !this.options.isIframeEmbed) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixes a typo/bug introduced in #35587 |
||
// 'data' is the same data returned by the "get clipboard status" API endpoint | ||
// i.e. /api/content-staging/v1/clipboard/ | ||
if (this.options.canEdit && data.content) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having this POST arg will be nice, so that we don't have to follow up the request with a PUT 👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kdmccormick Yes, called upstream sync after creating the block in a single call, simplified the js part. bc27ba3