Skip to content

feat: implements the student view of flashcards using Paragon - #334

Draft
tecoholic wants to merge 8 commits into
openedx:mainfrom
open-craft:tecoholic/BB-11335-flash-cards-in-react-paragon
Draft

tecoholic wants to merge 8 commits into
openedx:mainfrom
open-craft:tecoholic/BB-11335-flash-cards-in-react-paragon

Conversation

@tecoholic

@tecoholic tecoholic commented Nov 19, 2026 •

Copy link
Copy Markdown

follow up PR after #316

Testing instructions

Prerequisites

Environment setup

  1. Clone and build this branch of xblocks-core (note that the Vite bundle in src/xblock_flashcards/public/flashcards.js is git-ignored and must be built before testing):
cd /path/to/your/tutor/devstack
git clone https://github.com/open-craft/xblocks-core
cd xblocks-core
git checkout tecoholic/BB-11335-flash-cards-in-react-paragon
npm install
npm run build
cd ..
  1. Clone and check out the companion authoring MFE branch from feat: add flashcards and matching block editors frontend-app-authoring#3351:
git clone https://github.com/open-craft/frontend-app-authoring
cd frontend-app-authoring
git checkout samuel/flashcards-and-matching
cd ..
  1. Mount both repositories in Tutor, launch the devstack, and install xblocks-core in editable mode in lms and cms:
tutor mounts add ./xblocks-core
tutor mounts add ./frontend-app-authoring
tutor dev launch -I
tutor dev exec lms -- pip install --no-deps -e /mnt/xblocks-core
tutor dev exec cms -- pip install --no-deps -e /mnt/xblocks-core
tutor dev restart lms cms

(If your devstack already has up-to-date openedx-dev and authoring-dev images, you can use tutor config save && tutor dev start -d instead of tutor dev launch -I.)

Manual verification in Studio and LMS

  1. Open a test course in Studio and add "openedx_flashcards" to Settings -> Advanced Settings -> Advanced Module List.
  2. Open a unit and add an Advanced -> Flashcards component.
  3. Open the Flashcards editor, create multiple cards (including text-only cards and cards with uploaded images on front/back), save, and verify changes persist.
  4. View the block's student view in Studio preview and/or View Live in the LMS (Learning MFE):
    • Verify the start screen renders with the block's display name and Start button (and that Start is disabled if no cards exist).
    • Click Start and verify the card renders with Paragon styling isolated inside the Shadow DOM (no styling regressions on the surrounding Studio/LMS page).
    • Click the card—and test keyboard flipping with Enter and Space—to confirm it flips cleanly between front and back and renders both text and images properly.
    • Navigate through cards using the previous/next buttons and ArrowLeft/ArrowRight keys; verify the current/total counter updates, previous/next buttons disable on the first/last card, and switching cards resets the card face to the front.
    • Hover or focus the ? help icon in the bottom-right corner and verify the Paragon tooltip renders with styling inside the block.
    • Enable shuffling in the editor, save, and verify cards are shuffled in the student view.
    • Resize the viewport to mobile/narrow widths and verify the card layout remains responsive.

Automated tests

  • Frontend (Vitest): cd src/xblock_flashcards/assets && npm test
  • Backend (pytest): pytest src/xblock_flashcards (or make test)

Merge checklist:
Check off if complete or not applicable:

  • Version bumped
  • Changelog record added
  • Documentation updated (not only docstrings)
  • Fixup commits are squashed away
  • Unit tests added/updated
  • Manual testing instructions provided
  • Noted any: Concerns, dependencies, migration issues, deadlines, tickets

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Nov 19, 2026
@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @tecoholic!

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.

🔘 Update the status of your PR

Your PR is currently marked as a draft. After completing the steps above, update its status by clicking "Ready for Review", or removing "WIP" from the title, as appropriate.


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.

@github-project-automation github-project-automation Bot moved this to Needs Triage in Contributions Nov 19, 2026
@tecoholic tecoholic changed the title Tecoholic/bb 11335 flash cards in react paragon feat: implements the student view of flashcards using Paragon Nov 19, 2026
@tecoholic tecoholic self-assigned this Nov 19, 2026
@samuelallan72

samuelallan72 commented Nov 19, 2026 •

Copy link
Copy Markdown

@tecoholic would you mind rebasing on #316 and configuring it on Github as a stacked PR (if it doesn't do it automatically)? That should make it easier to review the changes. :) There has also been some data structure changes yesterday (mostly just renaming).

@samuelallan72 samuelallan72 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@tecoholic I know this is still in draft, but while I was here, I did a bit of a code review pass. :)

Comment thread src/xblock_flashcards/assets/.gitignore Resolved
Comment thread src/xblock_flashcards/assets/README.md Resolved
Comment thread src/xblock_flashcards/flashcards.py Resolved
@tecoholic
tecoholic force-pushed the tecoholic/BB-11335-flash-cards-in-react-paragon branch from 49c67cd to 66c57b5 Compare November 23, 2026 04:39
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Nov 24, 2026
samuelallan72 and others added 2 commits November 26, 2026 09:23
Migrate the XBlock from https://github.com/edx/gamesxblock to this
repository. In the process, split them into two separate xblocks:
matching and flashcards.

Also do some rework on the new blocks to modernise the code, remove
unused functions, etc.

Private-ref: https://tasks.opencraft.com/browse/BB-11332
A Vite dev env is added to the "assets" directory of xblock_flashcards
and is auto-loaded as an npm workspace to existing build pipeline.

The Vite build is configured to emit `public/js/flashcard.js` and
follows the same convention as existing npm build artifacts in the
repository.

The component can also be independently developed and test by using
the vite development server via npm dev.

Internal-ref: https://tasks.opencraft.com/browse/BB-11335
@tecoholic
tecoholic force-pushed the tecoholic/BB-11335-flash-cards-in-react-paragon branch from 66c57b5 to 6767878 Compare November 27, 2026 03:49
@tecoholic

Copy link
Copy Markdown
Author

@tecoholic would you mind rebasing on #316 and configuring it on Github as a stacked PR (if it doesn't do it automatically)? That should make it easier to review the changes. :) There has also been some data structure changes yesterday (mostly just renaming).

@samuelallan72 Unfortunately, Stacked PRs currently work only for the PRs created on the same fork and not across forks. So, this will have to be manually rebased. :(

@samuelallan72 samuelallan72 left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@tecoholic thanks, this is working pretty well for me! I left several comments and requests though, please take a look. :)

Note that the core functionality was working well for me. I know we want to get this shipped for our client asap. The only strong functional blocking issue I found was that the js bundle must be committed to the repo, otherwise a clean install of the block will not have the bundle available. Everything else is general UI tweaks, code quality, improvements for maintainability, etc.

Feel free to resolve my comments from my previous review pass; I don't have permission.

@@ -0,0 +1,57 @@
# Flashcards XBlock frontend

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think this readme can be improved; I found it a little hard to follow.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Update in 1b579b6

Comment thread src/xblock_flashcards/assets/README.md Outdated
npm run format # oxfmt
```

The build output in `../public/` is git-ignored similar to other NPM workspaces.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The build output actually must not be gitignored - it must be committed, because there is currently no clean way to build the bundle when the xblock is installed. cc @Kelketek unless there have been recent developments?

I think here we'll need to:

  • update the gitignores so this public dir is not gitignored
  • build and commit the bundle
  • add a step to the CI workflows that verifies the committed bundle is up to date with the source code.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@samuelallan72 That's needed only for repos that doesn't have PyPI builds. For this repo the JS build files are explicitly ignored and built by the CI during a release.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@tecoholic ah ok that's cool. What about for installing from a git ref though? 🤔

Comment thread src/xblock_flashcards/assets/README.md Outdated

## Development

```sh

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can we add a brief but helpful workflow for development maybe? This is mostly just a list of the available npm scripts, which will be outdated easily.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated in 1b579b6

<div className="flashcards-startpage">
<h3>{formatMessage(messages.startMsg)}</h3>
<Button
variant="brand"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think "primary" variant might work better here, and look closer to the existing games xblock?

</div>
<Row className="flashcards-header">
<Col>
<h1>{titleText}</h1>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The title is quite large compared to the existing games xblock. Can we make it smaller?

Original:

image

New:

image

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Reduced to a h3.


.flashcard-wrapper {
position: relative;
min-height: 24rem;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is this the equivalent to the 385px in App.css? If so, I think the value needs to be standardised and perhaps deduplicated

Comment on lines +61 to +71
expect(container.querySelector('.flashcard-wrapper')).toHaveClass(
'flipped',
);
expect(container.querySelector('.flashcard-front')).toHaveAttribute(
'aria-hidden',
'true',
);
expect(container.querySelector('.flashcard-back')).toHaveAttribute(
'aria-hidden',
'false',
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Rather than query selectors, we should prefer selectors based on visual/textual information, such as what a user would see. Eg. here rather than looking for the "flipped" class or "aria-hidden", look for the absence or presence of expected card text.

Comment on lines +71 to +72
it('falls back to the default title when the display name is empty', () => {
renderApp({ displayName: '' });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

When would the displayname be empty? I think we can just rely on the displayname.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed the test.

@@ -0,0 +1,76 @@
/**

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can we use https://github.com/open-craft/xblock-react-utils for managing the shadow root and such? Then we don't need to hand roll this again.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Replaced the custom implementation with xblock-react-utils.

Comment on lines +21 to +28
* Rewrites a selector written for a document so that it applies inside a
* shadow root: `:root` and `html` become `:host`, `body` becomes the element
* React renders into.
*/
export const scopeSelector = (selector: string): string =>
selector
.replace(/:root(?![\w-])/g, ':host')
.replace(/(^|[\s,>+~(])html(?![\w-])/g, '$1:host')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just noting that this is being addressed in Paragon at openedx/paragon#4282 . https://github.com/open-craft/xblock-react-utils manages a workaround too I believe.

@tecoholic tecoholic Dec 3, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The custom implementation was an experiment for 2 reasons:

  • xblock-react-utils solves only 1 half of the problem - it allows the XBlock specific styles and paragon to be used in the xblock reliability. But it doesn't prevent the xblock using paragon from affecting the other blocks. See these 2 units side by side, the left one has a Keypoints Block and the right one doesn't. That's the only difference.
image
  • the other utilities provided by the xblock-react-utils are focused on the Editor that this block doesn't ship from here.

So, this hand-rolled version was able to accomplish everything needed for this block without adding an external dependency. I have replaced it now with react-utils as I intend to "upstream" the style isolation fix.

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

Status: Waiting on Author

Development

Successfully merging this pull request may close these issues.

3 participants