Skip to content

feat: modernize Problem Block JS to ES6+ syntax#262

Open
irfanuddinahmad wants to merge 4 commits into
openedx:mainfrom
irfanuddinahmad:irfanuddinahmad/modernize-problem-block-js-438
Open

feat: modernize Problem Block JS to ES6+ syntax#262
irfanuddinahmad wants to merge 4 commits into
openedx:mainfrom
irfanuddinahmad:irfanuddinahmad/modernize-problem-block-js-438

Conversation

@irfanuddinahmad

@irfanuddinahmad irfanuddinahmad commented Jun 16, 2026

Copy link
Copy Markdown

Summary

Closes openedx/public-engineering#438

Converts all three capa JavaScript files to ES6+ syntax and removes the legacy imports-loader workarounds.

Source file changes

  • display.js — Removed CoffeeScript IIFE wrapper; added import $ from 'jquery'; replaced 28 prototype method-binding boilerplate blocks with clean .bind(this) calls; removed Array.indexOf polyfill in favour of Array.prototype.includes(); converted all varconst/let; template literals throughout; explicit window.Problem = Problem + ES6 export.
  • imageinput.js — Rewritten as an ES6 class ImageInput with import $ from 'jquery'; const/let; template literals; window.ImageInput = ImageInput + ES6 export.
  • schematic.js — Added import $ from 'jquery'; module-level var cktsim/var schematicconst; added named + default exports; kept window.update_schematics assignment 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 — Added import Problem from '../static/js/display.js' to make the dependency explicit.

Build config changes

  • webpack.config.js — Removed imports-loader (this=>window) entries for display.js, imageinput.js, and schematic.js (no longer needed now that the files use proper ES6 imports/exports). Updated babel-loader exclude regex so these three files are now Babel-processed.

Test plan

  • npm run build passes with no errors
  • npm test — capa Karma tests (display_spec.js, imageinput_spec.js) pass

Local Testing

Prerequisites

  • A local Tutor instance running (tested on Tutor v21 / Indigo)
  • Admin credentials for Studio and LMS

Setup: add problem blocks to a course

  1. Open Studio and log in (http://studio.local.openedx.io)

  2. Open any course (or create one)

  3. In the course outline, navigate to a Section → Subsection and click + New Unit

  4. Inside the unit, click + New Component → Problem and add one of each type below:

    Problem type JS file exercised
    Multiple Choice (default template) display.js
    Checkboxes display.js
    Image Input imageinput.js
    Circuit Schematic Builder schematic.js

    Note: For Checkboxes, Image Input, and Circuit Schematic, use Edit → Advanced editor and paste raw OLX — the authoring MFE's visual editor may not support these types.

  5. Click Publish in the sidebar

  6. 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:

  • Open DevTools → Console — no new JS errors on load (JQMIGRATE deprecation warnings from lms-main_vendor.js are pre-existing and unrelated)
  • Multiple Choice / Checkboxes — select an answer and click Submit; confirm correct/incorrect feedback appears and the score updates
  • Image Input — click on the image to place a marker; confirm the coordinate is captured and submission works
  • Circuit Schematic — confirm the schematic editor renders and is interactive in the browser (server-side grading requires codejail, which may not be configured in all local setups)
  • In DevTools → Sources, search for ProblemBlockDisplay → open the bundle → search for ImageInput; confirm the ES6 class ImageInput declaration is present, confirming the new bundle is served
image image image

🤖 Generated with Claude Code

Converts all three capa JavaScript files to ES6+ syntax and removes
the legacy imports-loader workarounds, satisfying the acceptance
criteria of openedx/public-engineering#438.

- display.js: removed CoffeeScript IIFE wrapper; added `import $ from
  'jquery'`; replaced 28 prototype method-binding blocks with
  `.bind(this)`; removed Array.indexOf polyfill in favour of
  Array.prototype.includes(); converted all var → const/let; template
  literals throughout; explicit `window.Problem = Problem` + ES6 export.
- imageinput.js: rewritten as ES6 class with import/export; const/let;
  template literals; `window.ImageInput = ImageInput` for compat.
- schematic.js: added `import $ from 'jquery'`; module-level var →
  const; added named + default exports; kept `window.update_schematics`
  for backwards compatibility.
- spec/display_spec.js: added `import Problem` for explicit dependency.
- spec/imageinput_spec.js: rewritten to ES6 (import, const/let,
  template literals, no IIFE wrapper).
- webpack.config.js: removed `imports-loader` (this=>window) entries
  for display.js, imageinput.js, schematic.js; updated babel-loader
  exclude so these three files are now Babel-processed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Jun 16, 2026
@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @irfanuddinahmad!

This repository is currently maintained by @openedx/axim-engineering.

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 approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To 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:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where 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:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

Irfan Ahmad and others added 3 commits June 18, 2026 12:59
Converts collapsible.js, javascript_loader.js, and xmodule.js — the three
webpack-bundled files missed in the initial pass — to ES6+ syntax, completing
the full scope of the ticket. Also converts collapsible_spec.js and applies
minor fixes to display.js (runtime param, errorHtml init) and display_spec.js
(removes stale decaffeinate comment).

- Remove IIFE wrappers and `this.X = ...` global assignments
- Replace `var` with `const`/`let` throughout
- Add `import $ from 'jquery'` to each module
- Add `window.X` assignments + ES6 exports for runtime compatibility
- Remove imports-loader/exports-loader rules for all three files in webpack.config.js
- Expand babel-loader exclude regex to include all 6 bundled files

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Karma loads JS files as plain scripts (not ES modules), so import/export
at the top level cause a SyntaxError. Source files already assign to
window.X for global access; webpack's ProvidePlugin handles $ and _
without explicit imports. Spec files relied on those globals anyway.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The Problem constructor takes (runtime, element) per XBlock convention.
The spec was missing mockRuntime as first arg and the declaration,
causing this.element_id to be undefined at runtime.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@irfanuddinahmad irfanuddinahmad force-pushed the irfanuddinahmad/modernize-problem-block-js-438 branch from 31ac4ad to dc7efbe Compare June 18, 2026 08:28
@salman2013

Copy link
Copy Markdown
Contributor

@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.

@irfanuddinahmad irfanuddinahmad added the create-sandbox open-craft-grove should create a sandbox environment from this PR label Jun 22, 2026
@irfanuddinahmad

Copy link
Copy Markdown
Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). create-sandbox open-craft-grove should create a sandbox environment from this PR open-source-contribution PR author is not from Axim or 2U

Projects

Status: Waiting on Author

Development

Successfully merging this pull request may close these issues.

Modernize Problem Block JavaScript

4 participants