feat: modernize Problem Block JS to ES6+ syntax#262
Conversation
|
Thanks for the pull request, @irfanuddinahmad! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. DetailsWhere can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
31ac4ad to
dc7efbe
Compare
|
@irfanuddinahmad Please do some manual testing on problem xblock as there are changes in js files so to make sure everything is working as expected. |
@salman2013 Done. Tests and Screenshots posted above. |
Removed the old `// [function ...]` / `// [description]` / `// [params]` comment blocks that were carried over verbatim from the original IIFE. Function signatures and inline comments are self-explanatory; the verbose header blocks add noise without adding clarity. Addresses reviewer feedback on PR openedx#262. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
salman2013
left a comment
There was a problem hiding this comment.
The code changes look fine to me, I am relying on @irfanuddinahmad testing results as he has verified the problem block so things look ready to merge.
Replaces the xblocks-contrib==0.17.0 PyPI pin with a direct git reference to the modernize-problem-block-js-438 branch on the fork, so the ES6+ Problem Block JS changes can be tested end-to-end in a running platform instance. PR under review: openedx/xblocks-core#262 Do not merge — this branch will be deleted once the xblocks-core PR is merged and a new xblocks-contrib release is published. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Temporarily un-gitignore the webpack bundle so the axim sandbox (installed via git+https) can serve ProblemBlockDisplay.js/.css. Without the build step, these files are absent and the problem block shows a loading spinner. This commit should be reverted before merge; in production the PyPI packaging runs `npm run build` first. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Convert display.js, imageinput.js, schematic.js, and collapsible.js from CoffeeScript-era IIFE/function patterns to ES6+ class and arrow-function syntax, with explicit jQuery imports via webpack externals instead of implicit globals. Key changes: - display.js: ES6+ module with explicit imports, .bind(this) replaced with arrow functions, named/default exports for Problem constructor - imageinput.js: rewritten as ES6 class ImageInput - schematic.js: added explicit jquery import and named/default exports - collapsible.js: converted to ES6+ syntax, removed CoffeeScript-style bracket doc comments - webpack.config.js: added externals for jQuery, updated ProvidePlugin - Removed ES6 import/export syntax incompatible with the Karma test runner (files loaded as plain <script> tags, not through webpack) - Fix display_spec.js: restored mockRuntime arg in Problem() calls Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
47ffe80 to
d1dc72a
Compare
The test asserted on $.ajaxWithPrefix.calls.mostRecent(), but in Flash mode an analytics event is dispatched after the caption fetch completes, making mostRecent() return the analytics call instead of the transcript call. Fix: find the specific transcript URL call via calls.all().find(), matching the pattern already used in the adjacent HTML5 mode test. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
jasmine.waitUntil(...).done(done) silently swallows rejections — if the player never leaves UNSTARTED state, done is never called and Jasmine reports a timeout for the test that follows. Replace every .done(done) with .always(done) across html5_video_spec, video_bumper_spec, and video_poster_spec so done is always called whether the wait resolves or rejects/times out. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sandbox VerificationTested on an axim sandbox (PR #38846) running the full Open edX stack with this branch installed. Sandbox: What was testedAll four CAPA problem types were set up in a course unit and verified end-to-end in the LMS student view:
No JS console errors ES6 class confirmed in bundle — |
Summary
Closes openedx/public-engineering#438
Converts all three capa JavaScript files to ES6+ syntax and removes the legacy
imports-loaderworkarounds.Source file changes
display.js— Removed CoffeeScript IIFE wrapper; addedimport $ from 'jquery'; replaced 28 prototype method-binding boilerplate blocks with clean.bind(this)calls; removedArray.indexOfpolyfill in favour ofArray.prototype.includes(); converted allvar→const/let; template literals throughout; explicitwindow.Problem = Problem+ ES6 export.imageinput.js— Rewritten as an ES6class ImageInputwithimport $ from 'jquery';const/let; template literals;window.ImageInput = ImageInput+ ES6 export.schematic.js— Addedimport $ from 'jquery'; module-levelvar cktsim/var schematic→const; added named + default exports; keptwindow.update_schematicsassignment for backwards compatibility with callers that reference it as a global.Spec file changes
spec/imageinput_spec.js— Rewritten to ES6:import ImageInput,const/let, template literals, no IIFE wrapper.spec/display_spec.js— Addedimport Problem from '../static/js/display.js'to make the dependency explicit.Build config changes
webpack.config.js— Removedimports-loader(this=>window) entries fordisplay.js,imageinput.js, andschematic.js(no longer needed now that the files use proper ES6 imports/exports). Updatedbabel-loaderexclude regex so these three files are now Babel-processed.Test plan
npm run buildpasses with no errorsnpm test— capa Karma tests (display_spec.js,imageinput_spec.js) passLocal Testing
Prerequisites
Setup: add problem blocks to a course
Open Studio and log in (
http://studio.local.openedx.io)Open any course (or create one)
In the course outline, navigate to a Section → Subsection and click + New Unit
Inside the unit, click + New Component → Problem and add one of each type below:
display.jsdisplay.jsimageinput.jsschematic.jsClick Publish in the sidebar
Enroll your user in the course if not already enrolled
Verification
Open the unit in the learner view (
http://apps.local.openedx.io/learning/course/<course-id>/home) and for each problem type:lms-main_vendor.jsare pre-existing and unrelated)ProblemBlockDisplay→ open the bundle → search forImageInput; confirm the ES6class ImageInputdeclaration is present, confirming the new bundle is servedSandbox Testing
Sandbox: https://pr-38846-4daaca.axim-sandboxes.opencraft.hosting/
🤖 Generated with Claude Code