-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
ff9c1dd
to
249cd15
Compare
249cd15
to
3aba303
Compare
3aba303
to
4aee493
Compare
const resources = normalizeResources(sourceResources); | ||
|
||
/* Extract CSS resources. */ | ||
const cssUrls = filterAndExtractResources(resources, 'url', 'text/css'); | ||
const sheets = filterAndExtractResources(resources, 'text', 'text/css'); | ||
|
||
let additionalCSSTags = ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, corrected
additionalCSSTags += stylesWithContent | ||
.map(sheet => { | ||
if (Array.isArray(sheet)) { | ||
return sheet.map(subSheet => `<style>${subSheet}</style>`).join('\n'); | ||
} | ||
return `<style>${sheet}</style>`; | ||
}) | ||
.join('\n'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
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!
modifiedHtml = modifiedHtml.replaceAll('url('/asset', `url('${studioBaseUrl}/asset`); | ||
modifiedHtml = modifiedHtml.replaceAll('src="/asset', `src="${studioBaseUrl}/asset`); | ||
modifiedHtml = modifiedHtml.replaceAll('src="/asset', `src="${studioBaseUrl}/asset`); | ||
modifiedHtml = modifiedHtml.replaceAll('href="/asset', `href="${studioBaseUrl}/asset`); | ||
modifiedHtml = modifiedHtml.replaceAll('src="/static', `src="${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`); |
There was a problem hiding this comment.
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);
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Codecov ReportAttention: Patch coverage is
❗ 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. |
* fix: [AXIMST-719] fixed xblock problems * fix: added asset and static replacer * feat: added style extractor * refactor: code refactoring * refactor: after review
* fix: [AXIMST-719] fixed xblock problems * fix: added asset and static replacer * feat: added style extractor * refactor: code refactoring * refactor: after review
* fix: [AXIMST-719] fixed xblock problems * fix: added asset and static replacer * feat: added style extractor * refactor: code refactoring * refactor: after review
* fix: [AXIMST-719] fixed xblock problems * fix: added asset and static replacer * feat: added style extractor * refactor: code refactoring * refactor: after review
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
* fix: [AXIMST-719] fixed xblock problems * fix: added asset and static replacer * feat: added style extractor * refactor: code refactoring * refactor: after review
YouTrack tickets: