Skip to content
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

fix: course update iframe #1204

Conversation

CefBoud
Copy link
Contributor

@CefBoud CefBoud commented Oct 6, 2023

Intro

This PR addresses a bug that emerges in course updates displayed in the LmsHtmlFragment component. Currently, we rely on the body's scrollHeight to set the iframe 's height. This poses a problem in case the body node's height is inferior to the html node's height resulting in hidden content. (cf. example below)

This PR also deals with another issue regarding the Show More button and whether the message can be shortened. Presently, we compare the original update's length with a truncated version's length to determine if the message can be shortened. We rely on truncate-html module to truncate the message. This module parses the content before the truncating and can change its length even if there is no need for truncating.

const truncate = require("truncate-html")
let a = "<h1  >Test</h1>"  // notice the additional spaces
let b = truncate(a, 100, { byWords: true, keepWhitespaces: true })
console.log("a:", a, "    ", "a.length:", a.length, "    ", "b:", b, "    ", "b.length:", b.length)
// a: <h1  >Test</h1>      a.length: 15      b: <h1>Test</h1>      b.length: 13

In addition, truncate-html strips comments regardless of truncating and this results in a length change. That's why this PR introduces a "cleaning" step that aims to format the update into a canonical format before truncating it.

useMemo is also used to avoid recomputing the truncate at every render.

Reproducing insufficient height issue

1- head to studio Course Update section e.g. http://localhost:18010/course_info/course-v1:edX+DemoX+Demo_Course
2- Create a course update containing the following HTML:

<h3><img src="" width="117" height="117" align="left" /></h3>
<p></p>
<p></p>
<hr />
<p></p>
<p></p>
<h3><strong>Test Test Test Test!</strong></h3>
<p><strong>-Test Test Test Test Test Test Test Test, Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test <a href="#" target="_blank" rel="noopener">Test Test Test Test Test Test Test Test</a>. </strong></p>
<p><strong>-Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test.</strong></p>
<p>Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test--&gt; Home Page</p>
<p>-Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test</p>

3 - Head to the course http://localhost:2000/course/course-v1:edX+DemoX+Demo_Course/home and notice that the lower part of the update is not fully displayed after clicking on Show More

demo_course_update.mp4

Reproducing unnecessary "Show More"

1- head to studio Course Update section e.g. http://localhost:18010/course_info/course-v1:edX+DemoX+Demo_Course
2- Create a course update containing the following HTML:

<p > I am short</p>

3 - Head to the course http://localhost:2000/course/course-v1:edX+DemoX+Demo_Course/home
4 - The Show More button is displayed.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Oct 6, 2023
@openedx-webhooks
Copy link

openedx-webhooks commented Oct 6, 2023

Thanks for the pull request, @CefBoud! Please note that it may take us up to several weeks or months to complete a review and merge your PR.

Feel free to add as much of the following information to the ticket as you can:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here.

Please let us know once your PR is ready for our review and all tests are green.

@CefBoud CefBoud marked this pull request as draft October 6, 2023 12:57
@CefBoud CefBoud marked this pull request as ready for review October 9, 2023 09:13
@itsjeyd
Copy link

itsjeyd commented Oct 10, 2023

Hi @CefBoud, thanks for these changes! I'm lining them up for a test run now.

@itsjeyd itsjeyd added the needs test run Author's first PR to this repository, awaiting test authorization from Axim label Oct 10, 2023
@e0d
Copy link

e0d commented Oct 10, 2023

@CefBoud there are some failed checks that require attention.

@e0d e0d removed the needs test run Author's first PR to this repository, awaiting test authorization from Axim label Oct 10, 2023
@CefBoud CefBoud force-pushed the CefBoud/fix_course_update_show_more branch from ae9c8a8 to 657b146 Compare October 10, 2023 19:32
@CefBoud
Copy link
Contributor Author

CefBoud commented Oct 10, 2023

@e0d Thank you for the heads up. I just pushed a fix.

@codecov
Copy link

codecov bot commented Oct 10, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (5604def) 88.04% compared to head (657b146) 88.08%.
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1204      +/-   ##
==========================================
+ Coverage   88.04%   88.08%   +0.03%     
==========================================
  Files         266      268       +2     
  Lines        4518     4565      +47     
  Branches     1142     1149       +7     
==========================================
+ Hits         3978     4021      +43     
- Misses        526      529       +3     
- Partials       14       15       +1     
Files Coverage Δ
src/course-home/outline-tab/LmsHtmlFragment.jsx 76.47% <100.00%> (ø)
...course-home/outline-tab/widgets/WelcomeMessage.jsx 88.46% <100.00%> (+2.09%) ⬆️

... and 6 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@e0d
Copy link

e0d commented Oct 10, 2023

@CefBoud thanks, all 🟢 @mphilbrick211 I've moved to ready for review.

@mphilbrick211
Copy link

@itsjeyd - flagging for you!

@itsjeyd
Copy link

itsjeyd commented Oct 13, 2023

@mphilbrick211 @e0d Thanks!

@itsjeyd itsjeyd added the waiting for eng review PR is ready for review. Review and merge it, or suggest changes. label Oct 13, 2023
@CefBoud CefBoud closed this Oct 13, 2023
@CefBoud CefBoud deleted the CefBoud/fix_course_update_show_more branch October 13, 2023 15:36
@CefBoud CefBoud restored the CefBoud/fix_course_update_show_more branch October 13, 2023 15:36
@CefBoud CefBoud reopened this Oct 13, 2023
@CefBoud
Copy link
Contributor Author

CefBoud commented Oct 13, 2023

I closed the PR by mistake. I am sorry for the confusion.

@itsjeyd
Copy link

itsjeyd commented Oct 17, 2023

@CefBoud I'm lining this up for another test run.

Who is your OpenCraft reviewer for this PR?

@itsjeyd itsjeyd added needs test run Author's first PR to this repository, awaiting test authorization from Axim and removed waiting for eng review PR is ready for review. Review and merge it, or suggest changes. labels Oct 17, 2023
@CefBoud
Copy link
Contributor Author

CefBoud commented Oct 17, 2023

@itsjeyd Ok, thanks.

Who is your OpenCraft reviewer for this PR?

@viadanna is.

@e0d e0d removed the needs test run Author's first PR to this repository, awaiting test authorization from Axim label Oct 17, 2023
@itsjeyd
Copy link

itsjeyd commented Oct 18, 2023

@CefBoud OK, let me know when you get approval from him so we can line this up for upstream engineering review :)

@CefBoud
Copy link
Contributor Author

CefBoud commented Oct 18, 2023

@itsjeyd It has been approved. 🙂

@itsjeyd
Copy link

itsjeyd commented Oct 24, 2023

@CefBoud Great!

@viadanna Could you please drop a formal 👍 here when you get a minute?

Copy link

@viadanna viadanna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved 👍

  • I tested this on a sandbox
  • I read through the code
  • Includes tests

@itsjeyd @CefBoud

@itsjeyd itsjeyd added the waiting for eng review PR is ready for review. Review and merge it, or suggest changes. label Nov 2, 2023
@itsjeyd itsjeyd requested a review from mattcarter November 2, 2023 10:10
@itsjeyd
Copy link

itsjeyd commented Nov 2, 2023

@mattcarter This PR is ready for engineering review by Aurora.

@itsjeyd
Copy link

itsjeyd commented Nov 17, 2023

Hey @mattcarter, a friendly reminder to line this PR up for engineering review.

@itsjeyd
Copy link

itsjeyd commented Nov 29, 2023

@CefBoud Just to keep you in the loop, we're still working on getting this PR unblocked.

CC @mphilbrick211

@itsjeyd
Copy link

itsjeyd commented Feb 8, 2024

@BbrSofiane A similar question here: Would you be able to review this PR as a CC?

@itsjeyd
Copy link

itsjeyd commented Mar 22, 2024

Calling remaining CCs for frontend-app-learning:

@brian-smith-tcril
@arbrandes
@viktorrusakov

Would one of you have bandwidth for reviewing and merging this PR?

@brian-smith-tcril brian-smith-tcril merged commit d4e7b41 into openedx:master Mar 29, 2024
8 checks passed
@openedx-webhooks
Copy link

@CefBoud 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future.

@itsjeyd itsjeyd removed the waiting for eng review PR is ready for review. Review and merge it, or suggest changes. label Apr 10, 2024
@0x29a 0x29a deleted the CefBoud/fix_course_update_show_more branch April 11, 2024 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

7 participants