From d910d09e00cd39fc805362f39c43ac6c0c0492f3 Mon Sep 17 00:00:00 2001 From: "Dave St.Germain" Date: Wed, 19 Aug 2020 13:08:13 -0400 Subject: [PATCH] Allow units to create a modal in the parent window (#184) This is used by LTI blocks configured to launch in a modal window. Instead of opening a modal in our unit iframe, the component will send a message to the parent window (the courseware mfe) requesting it to open its own modal, containing a URL to launch the LTI tool. --- src/courseware/course/sequence/Unit.jsx | 26 +++++++++++++++++++++++++ src/index.scss | 15 ++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/courseware/course/sequence/Unit.jsx b/src/courseware/course/sequence/Unit.jsx index e17a0b59..3dae0419 100644 --- a/src/courseware/course/sequence/Unit.jsx +++ b/src/courseware/course/sequence/Unit.jsx @@ -9,6 +9,7 @@ import { useDispatch } from 'react-redux'; import PropTypes from 'prop-types'; import { getConfig } from '@edx/frontend-platform'; import { injectIntl, intlShape } from '@edx/frontend-platform/i18n'; +import { Modal } from '@edx/paragon'; import messages from './messages'; import BookmarkButton from '../bookmark/BookmarkButton'; import { useModel } from '../../../generic/model-store'; @@ -64,6 +65,7 @@ function Unit({ const [iframeHeight, setIframeHeight] = useState(0); const [hasLoaded, setHasLoaded] = useState(false); + const [modalOptions, setModalOptions] = useState({ open: false }); const unit = useModel('units', id); const course = useModel('courses', courseId); @@ -89,6 +91,9 @@ function Unit({ onLoaded(); } } + } else if (type === 'plugin.modal') { + payload.open = true; + setModalOptions(payload); } } // If we currently have an event listener, remove it. @@ -130,6 +135,27 @@ function Unit({ srMessage={intl.formatMessage(messages['learn.loading.learning.sequence'])} /> )} + {modalOptions.open && ( + + {modalOptions.body + ?
{ modalOptions.body }
+ : ( +