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: [AXIMST-719] Course unit - Xblock problems #213

Merged
merged 5 commits into from
Mar 29, 2024

Conversation

@PKulkoRaccoonGang PKulkoRaccoonGang changed the title Peter kulko/xblock problems DRAFT: [AXIMST-719] Course unit - Xblock problems Mar 26, 2024
@PKulkoRaccoonGang PKulkoRaccoonGang self-assigned this Mar 26, 2024
@PKulkoRaccoonGang PKulkoRaccoonGang marked this pull request as draft March 26, 2024 11:16
@PKulkoRaccoonGang PKulkoRaccoonGang force-pushed the Peter_Kulko/xblock-problems branch 2 times, most recently from ff9c1dd to 249cd15 Compare March 28, 2024 11:17
@PKulkoRaccoonGang PKulkoRaccoonGang marked this pull request as ready for review March 28, 2024 11:20
@PKulkoRaccoonGang PKulkoRaccoonGang force-pushed the Peter_Kulko/xblock-problems branch from 249cd15 to 3aba303 Compare March 28, 2024 11:22
@PKulkoRaccoonGang PKulkoRaccoonGang force-pushed the Peter_Kulko/xblock-problems branch from 3aba303 to 4aee493 Compare March 28, 2024 11:38
@PKulkoRaccoonGang PKulkoRaccoonGang changed the title DRAFT: [AXIMST-719] Course unit - Xblock problems fix: [AXIMST-719] Course unit - Xblock problems Mar 28, 2024
const resources = normalizeResources(sourceResources);

/* Extract CSS resources. */
const cssUrls = filterAndExtractResources(resources, 'url', 'text/css');
const sheets = filterAndExtractResources(resources, 'text', 'text/css');

let additionalCSSTags = '';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
let additionalCSSTags = '';
let additionalCssTags = '';

[nit] I remember on the Paragon we had a linter that didn't like when we did something like CSS in the middle of a variable name. The idea is to follow camelCase when it is possible. When we do CSS it is kind of small camelCase violation.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, corrected

Comment on lines 36 to 43
additionalCSSTags += stylesWithContent
.map(sheet => {
if (Array.isArray(sheet)) {
return sheet.map(subSheet => `<style>${subSheet}</style>`).join('\n');
}
return `<style>${sheet}</style>`;
})
.join('\n');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
additionalCSSTags += stylesWithContent
.map(sheet => {
if (Array.isArray(sheet)) {
return sheet.map(subSheet => `<style>${subSheet}</style>`).join('\n');
}
return `<style>${sheet}</style>`;
})
.join('\n');
const additionalCSSTags = stylesWithContent.flatMap(sheet => `<style>${sheet}</style>`).join('\n');

In JavaScript, strings are immutable. Every time you use += or concatenation, a new string is created in memory, and the old one is potentially discarded. This can lead to excessive memory usage if you do it often in a loop.

By the way flatMap can help with nested arrays to make it flat and map it at the same time.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, good catch! flatMap is very good to apply here!

Comment on lines 269 to 280
modifiedHtml = modifiedHtml.replaceAll('url(&#39;/asset', `url('${studioBaseUrl}/asset`);
modifiedHtml = modifiedHtml.replaceAll('src="/asset', `src="${studioBaseUrl}/asset`);
modifiedHtml = modifiedHtml.replaceAll('src=&#34;/asset', `src=&#34;${studioBaseUrl}/asset`);
modifiedHtml = modifiedHtml.replaceAll('href="/asset', `href="${studioBaseUrl}/asset`);
modifiedHtml = modifiedHtml.replaceAll('src=&#34;/static', `src=&#34;${studioBaseUrl}/static`);
modifiedHtml = modifiedHtml.replaceAll('src="/static', `src="${studioBaseUrl}/static`);
modifiedHtml = modifiedHtml.replaceAll('data-target="/preview', `data-target="${studioBaseUrl}/preview`);
modifiedHtml = modifiedHtml.replaceAll('data-url="/preview', `data-url="${studioBaseUrl}/preview`);
modifiedHtml = modifiedHtml.replaceAll('src="/preview', `src="${studioBaseUrl}/preview`);
modifiedHtml = modifiedHtml.replaceAll('src="/media', `src="${studioBaseUrl}/media`);
modifiedHtml = modifiedHtml.replaceAll(': "/asset', `: "${studioBaseUrl}/asset`);
modifiedHtml = modifiedHtml.replaceAll(': "/xblock', `: "${studioBaseUrl}/xblock`);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since it is growing in size we can make an object with key as a first argument of replaceAll and value as a second. Put it somewhere before the string HTML string and do something like

// Block that replaces relative urls with absolute urls
Object.entries(relativeToAbosluteXBlocksUrls).forEach(([key, value]) => {
    modifiedHtml = modifiedHtml.replaceAll(key, value);
});

Copy link
Author

Choose a reason for hiding this comment

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

Done

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 10.52632% with 17 lines in your changes are missing coverage. Please review.

❗ No coverage uploaded for pull request base (ts-develop@6509cc7). Click here to learn what that means.

Files Patch % Lines
src/course-unit/course-xblock/utils.js 0.00% 7 Missing ⚠️
...ck/xblock-content/iframe-wrapper/iframe-wrapper.js 0.00% 6 Missing ⚠️
src/course-unit/course-xblock/CourseXBlock.jsx 33.33% 2 Missing ⚠️
...nit/course-xblock/xblock-content/XBlockContent.jsx 0.00% 1 Missing ⚠️
src/course-unit/data/api.js 0.00% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@              Coverage Diff              @@
##             ts-develop     #213   +/-   ##
=============================================
  Coverage              ?   88.38%           
=============================================
  Files                 ?      689           
  Lines                 ?    11894           
  Branches              ?     2539           
=============================================
  Hits                  ?    10512           
  Misses                ?     1322           
  Partials              ?       60           

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

@monteri monteri merged commit 0a2bb22 into ts-develop Mar 29, 2024
3 checks passed
monteri pushed a commit that referenced this pull request Apr 1, 2024
* fix: [AXIMST-719] fixed xblock problems

* fix: added asset and static replacer

* feat: added style extractor

* refactor: code refactoring

* refactor: after review
ihor-romaniuk pushed a commit that referenced this pull request Apr 25, 2024
* fix: [AXIMST-719] fixed xblock problems

* fix: added asset and static replacer

* feat: added style extractor

* refactor: code refactoring

* refactor: after review
monteri pushed a commit that referenced this pull request Apr 29, 2024
* fix: [AXIMST-719] fixed xblock problems

* fix: added asset and static replacer

* feat: added style extractor

* refactor: code refactoring

* refactor: after review
PKulkoRaccoonGang added a commit that referenced this pull request Apr 30, 2024
* fix: [AXIMST-719] fixed xblock problems

* fix: added asset and static replacer

* feat: added style extractor

* refactor: code refactoring

* refactor: after review
PKulkoRaccoonGang pushed a commit that referenced this pull request Apr 30, 2024
fix: [AXIMST-27] Unit page - change iframe pararm for display xblock content (#151)

feat: [AXIMST-52] display unit and xblock render errors (#191)

* feat: [AXIMST-52] display unit and xblock render errors

* fix: after discussion

* fix: after review

feat: Course unit - Rendering xblocks in iframes (#201)

* feat: added xblock render engine

* feat: connected iframe template

* feat: CSS and JS transfering

* feat: show video xblock

* feat: added multiply xblocks

* feat: rendering advanced components

* fix: add solution for request from within the iframe

* feat: iframe height

* refactor: code refactoring

* fix: fixed platform ajax prefix

* refactor: global refactoring

* refactor: show LTI xblock

* refactor: removed old xblock-content

* refactor: code refactoring

* refactor: some refactoring

* refactor: refactoring

* refactor: code refactoring

* refactor: refactoring after review

---------

Co-authored-by: monteri <lansevermore>

feat: [AXIMST-739] added xblock actions (#218)

* feat: [AXIMST-739] added xblock actions

* refactor: code refactoring

* refactor: refactoring after review

fix: after cherru-pick

fix: after cherry-pick

refactor: removed canEdit mock (#224)

fix: [AXIMST-655] fixed position of the view-port after loading the unit page (#217)

fix: [AXIMST-719] Course unit - Xblock problems (#213)

* fix: [AXIMST-719] fixed xblock problems

* fix: added asset and static replacer

* feat: added style extractor

* refactor: code refactoring

* refactor: after review

fix: [AXIMST-718] Course unit - Created logic for getting CSRF token (#226)

* fix: created logic for getting csrf token

* fix: usage of csrfTokenData

* refactor: code refactoring

---------

Co-authored-by: monteri <lansevermore>

fix: [AXIMST-745] added studioBaseUrl for static paths (#228)

refactor: [AXIMST-746] Unit page performance refactoring (#229)

Co-authored-by: Kyrylo Hudym-Levkovych <[email protected]>

fix: [AXIMST-785] fixed discard logic (#232)

feat: [AXIMST-800] Course unit - Added Collapse and Expand all buttons for xblocks (#234)

* feat: [AXIMST-800] added Collapse and Expand all buttons for xblocks

* feat: added tests

refactor: code refactoring
monteri pushed a commit that referenced this pull request May 3, 2024
* fix: [AXIMST-719] fixed xblock problems

* fix: added asset and static replacer

* feat: added style extractor

* refactor: code refactoring

* refactor: after review
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants