Skip to content

Commit 98143e6

Browse files
committed
refactor: replace paragon deprecated components
1 parent 4f2e100 commit 98143e6

File tree

3 files changed

+26
-41
lines changed

3 files changed

+26
-41
lines changed

src/courseware/course/sequence/Unit/ContentIFrame.jsx

+15-30
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react';
33

44
import { ErrorPage } from '@edx/frontend-platform/react';
55
import { StrictDict } from '@edx/react-unit-test-utils';
6-
import { ModalDialog, Modal } from '@openedx/paragon';
6+
import { ModalDialog } from '@openedx/paragon';
77
import { PluginSlot } from '@openedx/frontend-plugin-framework';
88

99
import PageLoading from '@src/generic/PageLoading';
@@ -66,21 +66,6 @@ const ContentIFrame = ({
6666
onLoad: handleIFrameLoad,
6767
};
6868

69-
let modalContent;
70-
if (modalOptions.isOpen) {
71-
modalContent = modalOptions.body
72-
? <div className="unit-modal">{ modalOptions.body }</div>
73-
: (
74-
<iframe
75-
title={modalOptions.title}
76-
allow={IFRAME_FEATURE_POLICY}
77-
frameBorder="0"
78-
src={modalOptions.url}
79-
style={{ width: '100%', height: modalOptions.height }}
80-
/>
81-
);
82-
}
83-
8469
return (
8570
<>
8671
{(shouldShowContent && !hasLoaded) && (
@@ -101,28 +86,28 @@ const ContentIFrame = ({
10186
<iframe title={title} {...contentIFrameProps} data-testid={testIDs.contentIFrame} />
10287
</div>
10388
)}
104-
{modalOptions.isOpen && (modalOptions.isFullscreen
105-
? (
106-
<ModalDialog
89+
{modalOptions.isOpen &&
90+
(<ModalDialog
10791
dialogClassName="modal-lti"
10892
onClose={handleModalClose}
109-
size="fullscreen"
93+
size={ modalOptions.isFullscreen ? 'fullscreen': 'md'}
11094
isOpen
11195
hasCloseButton={false}
11296
>
11397
<ModalDialog.Body className={modalOptions.modalBodyClassName}>
114-
{modalContent}
98+
{modalOptions.body
99+
? <div className="unit-modal">{ modalOptions.body }</div>
100+
: (
101+
<iframe
102+
title={modalOptions.title}
103+
allow={IFRAME_FEATURE_POLICY}
104+
frameBorder="0"
105+
src={modalOptions.url}
106+
style={{ width: '100%', height: modalOptions.height }}
107+
/>
108+
)}
115109
</ModalDialog.Body>
116110
</ModalDialog>
117-
118-
) : (
119-
<Modal
120-
body={modalContent}
121-
dialogClassName="modal-lti"
122-
onClose={handleModalClose}
123-
open
124-
/>
125-
)
126111
)}
127112
</>
128113
);

src/courseware/course/sequence/Unit/ContentIFrame.test.jsx

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22

33
import { ErrorPage } from '@edx/frontend-platform/react';
4-
import { ModalDialog, Modal } from '@openedx/paragon';
4+
import { ModalDialog } from '@openedx/paragon';
55
import { shallow } from '@edx/react-unit-test-utils';
66

77
import PageLoading from '@src/generic/PageLoading';
@@ -13,7 +13,6 @@ jest.mock('@edx/frontend-platform/react', () => ({ ErrorPage: 'ErrorPage' }));
1313

1414
jest.mock('@openedx/paragon', () => jest.requireActual('@edx/react-unit-test-utils')
1515
.mockComponents({
16-
Modal: 'Modal',
1716
ModalDialog: {
1817
Body: 'ModalDialog.Body',
1918
},
@@ -138,7 +137,7 @@ describe('ContentIFrame Component', () => {
138137
});
139138
it('does not display modal if modalOptions returns isOpen: false', () => {
140139
el = shallow(<ContentIFrame {...props} />);
141-
expect(el.instance.findByType(Modal).length).toEqual(0);
140+
expect(el.instance.findByType(ModalDialog).length).toEqual(0);
142141
});
143142
describe('if modalOptions.isOpen', () => {
144143
const testModalOpenAndHandleClose = () => {
@@ -193,30 +192,32 @@ describe('ContentIFrame Component', () => {
193192
beforeEach(() => {
194193
hooks.useModalIFrameData.mockReturnValueOnce({ ...modalIFrameData, modalOptions: modalOptions.withBody });
195194
el = shallow(<ContentIFrame {...props} />);
196-
[component] = el.instance.findByType(Modal);
195+
[component] = el.instance.findByType(ModalDialog);
197196
});
198197
it('displays Modal with div wrapping provided body content if modal.body is provided', () => {
199-
expect(component.props.body).toEqual(<div className="unit-modal">{modalOptions.withBody.body}</div>);
198+
const content = component.findByType(ModalDialog.Body)[0].children[0];
199+
expect(content.matches(shallow(<div className="unit-modal">{modalOptions.withBody.body}</div>))).toEqual(true);
200200
});
201201
testModalOpenAndHandleClose();
202202
});
203203
describe('url modal', () => {
204204
beforeEach(() => {
205205
hooks.useModalIFrameData.mockReturnValueOnce({ ...modalIFrameData, modalOptions: modalOptions.withUrl });
206206
el = shallow(<ContentIFrame {...props} />);
207-
[component] = el.instance.findByType(Modal);
207+
[component] = el.instance.findByType(ModalDialog);
208208
});
209209
testModalOpenAndHandleClose();
210210
it('displays Modal with iframe to provided url if modal.body is not provided', () => {
211-
expect(component.props.body).toEqual(
211+
const content = component.findByType(ModalDialog.Body)[0].children[0];
212+
expect(content.matches(shallow(
212213
<iframe
213214
title={modalOptions.withUrl.title}
214215
allow={IFRAME_FEATURE_POLICY}
215216
frameBorder="0"
216217
src={modalOptions.withUrl.url}
217218
style={{ width: '100%', height: modalOptions.withUrl.height }}
218219
/>,
219-
);
220+
))).toEqual(true);
220221
});
221222
});
222223
});

src/instructor-toolbar/masquerade-widget/MasqueradeUserNameInput.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { useIntl } from '@edx/frontend-platform/i18n';
3-
import { Input } from '@openedx/paragon';
3+
import { Form } from '@openedx/paragon';
44

55
import { MasqueradeStatus, Payload } from './data/api';
66
import messages from './messages';
@@ -40,11 +40,10 @@ export const MasqueradeUserNameInput: React.FC<Props> = ({ onSubmit, onError, ..
4040
}, [handleSubmit]);
4141

4242
return (
43-
<Input
43+
<Form.Control
4444
aria-labelledby="masquerade-search-label"
4545
label={intl.formatMessage(messages.userNameLabel)}
4646
onKeyPress={handleKeyPress}
47-
type="text"
4847
{...otherProps}
4948
/>
5049
);

0 commit comments

Comments
 (0)