Skip to content

Commit 5d8e17f

Browse files
authored
Merge pull request #2 from open-craft/open-release-palm.1/CefBoud/fix_course_update_show_more
fix: course update iframe
2 parents b5e8ae2 + 0991083 commit 5d8e17f

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

src/course-home/outline-tab/LmsHtmlFragment.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const LmsHtmlFragment = ({
2929
const iframe = useRef(null);
3030
function resetIframeHeight() {
3131
if (iframe?.current?.contentWindow?.document?.body) {
32-
iframe.current.height = iframe.current.contentWindow.document.body.scrollHeight;
32+
iframe.current.height = iframe.current.contentWindow.document.body.parentNode.scrollHeight;
3333
}
3434
}
3535

src/course-home/outline-tab/OutlineTab.test.jsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,22 @@ describe('Outline Tab', () => {
289289
});
290290
});
291291

292+
it('ignores comments and misformatted HTML', async () => {
293+
setTabData({
294+
welcome_message_html: '<p class="additional-spaces-in-tag" >'
295+
+ '<!-- Even if the welcome_message_html length is above the limit because of comments, we hope it will not be shortened. -->'
296+
+ '<!-- Even if the welcome_message_html length is above the limit because of comments, we hope it will not be shortened. -->'
297+
+ 'Test welcome message that happens to be longer than one hundred words because of comments but displayed content is less.'
298+
+ 'It should not be shortened.'
299+
+ '<!-- Even if the welcome_message_html length is above the limit because of comments, we hope it will not be shortened. -->'
300+
+ '<!-- Even if the welcome_message_html length is above the limit because of comments, we hope it will not be shortened. -->'
301+
+ '</p>',
302+
});
303+
await fetchAndRender();
304+
const showMoreButton = screen.queryByRole('button', { name: 'Show More' });
305+
expect(showMoreButton).not.toBeInTheDocument();
306+
});
307+
292308
it('does not display if no update available', async () => {
293309
setTabData({ welcome_message_html: null });
294310
await fetchAndRender();

src/course-home/outline-tab/widgets/WelcomeMessage.jsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react';
1+
import React, { useState, useMemo } from 'react';
22
import PropTypes from 'prop-types';
33

44
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
@@ -18,8 +18,22 @@ const WelcomeMessage = ({ courseId, intl }) => {
1818

1919
const [display, setDisplay] = useState(true);
2020

21-
const shortWelcomeMessageHtml = truncate(welcomeMessageHtml, 100, { byWords: true, keepWhitespaces: true });
22-
const messageCanBeShortened = shortWelcomeMessageHtml.length < welcomeMessageHtml.length;
21+
// welcomeMessageHtml can contain comments or malformatted HTML which can impact the length that determines
22+
// messageCanBeShortened. We clean it by calling truncate with a length of welcomeMessageHtml.length which
23+
// will not result in a truncation but a formatting into 'truncate-html' canonical format.
24+
const cleanedWelcomeMessageHtml = useMemo(
25+
() => truncate(welcomeMessageHtml, welcomeMessageHtml.length, { keepWhitespaces: true }),
26+
[welcomeMessageHtml],
27+
);
28+
const shortWelcomeMessageHtml = useMemo(
29+
() => truncate(cleanedWelcomeMessageHtml, 100, { byWords: true, keepWhitespaces: true }),
30+
[cleanedWelcomeMessageHtml],
31+
);
32+
const messageCanBeShortened = useMemo(
33+
() => (shortWelcomeMessageHtml.length < cleanedWelcomeMessageHtml.length),
34+
[cleanedWelcomeMessageHtml, shortWelcomeMessageHtml],
35+
);
36+
2337
const [showShortMessage, setShowShortMessage] = useState(messageCanBeShortened);
2438
const dispatch = useDispatch();
2539

@@ -63,7 +77,7 @@ const WelcomeMessage = ({ courseId, intl }) => {
6377
className="inline-link"
6478
data-testid="long-welcome-message-iframe"
6579
key="full-html"
66-
html={welcomeMessageHtml}
80+
html={cleanedWelcomeMessageHtml}
6781
title={intl.formatMessage(messages.welcomeMessage)}
6882
/>
6983
)}

0 commit comments

Comments
 (0)