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

Create PhET simulation widget #1512

Merged
merged 33 commits into from
Aug 19, 2024
Merged

Conversation

aemandine
Copy link
Contributor

@aemandine aemandine commented Aug 13, 2024

Summary:

Create a new Perseus widget for PhET simulations with the following features:

  • Fullscreen mode
  • Only allows URLs from the https://phet.colorado.edu origin
    • If the origin is wrong or the resource is not available, we display an error
  • Displays simulation in your locale (forgot to put this in the demo so I'll attach a screenshot)
    • If the simulation is not available in your locale, we display a warning banner and load the simulation in English
  • Skeleton widget editor
    • This is just to pass a Jest test that expects every widget will have an editor

I have documented the Perseus widget creation process here.

Issue: LEMS-2167

PhET simulation storybook page, contains an iframe with a PhET simulation and a fullscreen button under the bottom right corner of the iframe PhET simulation editor storybook page, contains a URL label with an empty input field

Test plan:

  • Verify that the widget shows up appropriately in Storybook
    • Change this.locale to some nonexistent locale and verify that the warning shows up
    • Change URL to a non-PhET origin and verify that the error shows up
    • Change URL to a non-existent resource from the PhET origin and verify that the error shows up
    • Click the fullscreen button and verify that the iframe goes into fullscreen mode
  • Verify screen reader accessibility
    • Make sure the fullscreen button, iframe, and iframe contents are all tab-focusable
    • Make sure the fullscreen button, iframe, and iframe contents all have appropriate aria labels

@khan-actions-bot khan-actions-bot requested a review from a team August 13, 2024 06:22
@khan-actions-bot
Copy link
Contributor

khan-actions-bot commented Aug 13, 2024

Gerald

Required Reviewers
  • @Khan/perseus for changes to .changeset/empty-seals-worry.md, packages/perseus/package.json, packages/perseus/src/extra-widgets.ts, packages/perseus/src/perseus-types.ts, packages/perseus/src/strings.ts, packages/perseus-editor/src/all-editors.ts, packages/perseus/src/util/widget-enum-utils.ts, packages/perseus/src/widgets/phet-sim.tsx, packages/perseus-editor/src/widgets/phet-sim-editor.tsx, packages/perseus/src/widgets/__stories__/phet-sim.stories.tsx, packages/perseus/src/widgets/__testdata__/phet-sim.testdata.ts, packages/perseus/src/widgets/__tests__/phet-sim.test.ts, packages/perseus-editor/src/widgets/__stories__/phet-sim-editor.stories.tsx

Don't want to be involved in this pull request? Comment #removeme and we won't notify you of further changes.

@aemandine aemandine requested review from SonicScrewdriver and Myranae and removed request for a team August 13, 2024 06:22
Copy link
Contributor

github-actions bot commented Aug 13, 2024

Size Change: +20.9 kB (+2.45%)

Total Size: 877 kB

Filename Size Change
packages/perseus-editor/dist/es/index.js 277 kB +81 B (+0.03%)
packages/perseus/dist/es/index.js 434 kB +20.8 kB (+5.03%) 🔍
packages/perseus/dist/es/strings.js 3.34 kB +53 B (+1.61%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 38.3 kB
packages/keypad-context/dist/es/index.js 760 B
packages/kmath/dist/es/index.js 4.27 kB
packages/math-input/dist/es/index.js 77.7 kB
packages/math-input/dist/es/strings.js 1.79 kB
packages/perseus-core/dist/es/index.js 1.48 kB
packages/perseus-linter/dist/es/index.js 21.8 kB
packages/pure-markdown/dist/es/index.js 3.67 kB
packages/simple-markdown/dist/es/index.js 12.4 kB

compressed-size-action

@khan-actions-bot khan-actions-bot requested a review from a team August 13, 2024 06:50
Copy link
Contributor

github-actions bot commented Aug 13, 2024

npm Snapshot: Published

Good news!! We've packaged up the latest commit from this PR (fbdc96b) and published it to npm. You
can install it using the tag PR1512.

Example:

yarn add @khanacademy/perseus@PR1512

If you are working in Khan Academy's webapp, you can run:

./dev/tools/bump_perseus_version.sh -t PR1512

Copy link

codecov bot commented Aug 13, 2024

Codecov Report

Attention: Patch coverage is 66.19217% with 95 lines in your changes missing coverage. Please review.

Project coverage is 70.92%. Comparing base (2509713) to head (fbdc96b).
Report is 1 commits behind head on phet-widget.

Files Patch % Lines
packages/perseus/src/widgets/phet-sim.tsx 71.36% 63 Missing ⚠️
...ges/perseus-editor/src/widgets/phet-sim-editor.tsx 30.43% 32 Missing ⚠️
Additional details and impacted files
@@               Coverage Diff               @@
##           phet-widget    #1512      +/-   ##
===============================================
+ Coverage        70.14%   70.92%   +0.77%     
===============================================
  Files              516      521       +5     
  Lines           106239   106553     +314     
  Branches          7622    10974    +3352     
===============================================
+ Hits             74526    75577    +1051     
+ Misses           31596    30976     -620     
+ Partials           117        0     -117     

Impacted file tree graph

Files Coverage Δ
packages/perseus-editor/src/all-editors.ts 100.00% <100.00%> (ø)
packages/perseus/src/extra-widgets.ts 100.00% <100.00%> (ø)
packages/perseus/src/strings.ts 99.55% <100.00%> (+<0.01%) ⬆️
packages/perseus/src/util/widget-enum-utils.ts 94.20% <100.00%> (+0.12%) ⬆️
...ges/perseus-editor/src/widgets/phet-sim-editor.tsx 30.43% <30.43%> (ø)
packages/perseus/src/widgets/phet-sim.tsx 71.36% <71.36%> (ø)

... and 129 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2509713...fbdc96b. Read the comment docs.

Copy link
Collaborator

@jeremywiebe jeremywiebe left a comment

Choose a reason for hiding this comment

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

Good stuff. I have some suggestions but overall this looks great.

packages/perseus/src/widgets/phet-sim.tsx Outdated Show resolved Hide resolved
packages/perseus/src/widgets/phet-sim.tsx Outdated Show resolved Hide resolved
packages/perseus/src/widgets/phet-sim.tsx Outdated Show resolved Hide resolved
packages/perseus/src/widgets/phet-sim.tsx Outdated Show resolved Hide resolved
packages/perseus/src/widgets/phet-sim.tsx Outdated Show resolved Hide resolved
packages/perseus/src/widgets/phet-sim.tsx Outdated Show resolved Hide resolved
@aemandine aemandine force-pushed the am/lems-2167/phet-perseus-widget branch from dc1bf73 to b2f4049 Compare August 19, 2024 18:12
@aemandine aemandine changed the base branch from main to phet-widget August 19, 2024 18:13
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unfortunately, we have a mixture of "older style" stories mixed in with a few modern ones. It looks like this story came from one of the older ones.

Could you migrate this to use the format defined here: https://storybook.js.org/docs/get-started/whats-a-story

It will give better typing in these stories especially for the props that the widget supports.

Happy to do a short pairing session to migrate if you like. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Jeremy! Thanks for the note! Should I use the new story style for the PhET sim and the PhET sim editor, or just the PhET sim editor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved! I am doing the new story style for both.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Perfect, that's what I would have suggested! :)

@aemandine aemandine merged commit 4f24be7 into phet-widget Aug 19, 2024
15 of 16 checks passed
@aemandine aemandine deleted the am/lems-2167/phet-perseus-widget branch August 19, 2024 23:38
Comment on lines 1 to 18
import {action} from "@storybook/addon-actions";
import * as React from "react";

import PhetSimEditor from "../phet-sim-editor";

type StoryArgs = Record<any, any>;

type Story = {
title: string;
};

export default {
title: "PerseusEditor/Widgets/PhET Simulation Editor",
} as Story;

export const Default = (args: StoryArgs): React.ReactElement => {
return <PhetSimEditor onChange={action("onChange")} />;
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is an improvement, but you can get closer (and have better typing)! :)

import type { Meta, StoryObj } from '@storybook/react';
 
import PhetSimEditor from "../phet-sim-editor";
 
const meta: Meta<typeof PhetSimEditor > = {
  component: PhetSimEditor,
};
 
export default meta;
type Story = StoryObj<typeof PhetSimEditor >;
 
export const Default: Story = {
  args: {
    onChange: action("onChange"),
  },
};

This means you don't even need a render function for the story, just the data. :)

aemandine added a commit that referenced this pull request Aug 22, 2024
## Summary:
Releases the PhET Simulation widget.

The [PhET Interactive Simulations](https://phet.colorado.edu/) initiative, run by the University of Colorado Boulder, develops interactive simulations for math and science education that are available for free. These simulations, known as PhET sims, are designed based on comprehensive educational research. They provide a game-like, intuitive platform that encourages students to learn by exploring and discovering concepts on their own.  

## Commit history:
This feature branch PR includes the following review branch PRs:
- Create PhET simulation widget (#1512)
- Add PhET simulation content editor (#1532)
- Design updates (#1542)

Issue: LEMS-XXXX

## Test plan:
Confirm all tests pass.

Author: SonicScrewdriver

Reviewers: Myranae, aemandine

Required Reviewers: 

Approved By: Myranae

Checks: ⌛ Upload Coverage (ubuntu-latest, 20.x), ✅ codecov/project, ✅ codecov/patch, ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Jest Coverage (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ gerald, ✅ Upload Coverage (ubuntu-latest, 20.x), ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Jest Coverage (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ gerald

Pull Request URL: #1546
aemandine pushed a commit that referenced this pull request Aug 22, 2024
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.


# Releases
## @khanacademy/[email protected]

### Major Changes

-   [#1546](#1546) [`6cbe4947e`](6cbe494) Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - Release PhET widget

    This PR releases a new PhET simulation widget to Perseus that requires an
    update in order to allow the support of new, upcoming content. Older versions
    of Perseus will be unable to render content that contains this widget.

    PhET simulations come from <https://phet.colorado.edu/>.

### Minor Changes

-   [#1529](#1529) [`0bf2711c0`](0bf2711) Thanks [@nicolecomputer](https://github.com/nicolecomputer)! - Adds unlimited point graph


-   [#1542](#1542) [`a7fc2a3e3`](a7fc2a3) Thanks [@aemandine](https://github.com/aemandine)! - Design update for PhET widget


-   [#1512](#1512) [`4f24be79d`](4f24be7) Thanks [@aemandine](https://github.com/aemandine)! - Add PhET widget


-   [#1532](#1532) [`6e102f9c4`](6e102f9) Thanks [@aemandine](https://github.com/aemandine)! - Add a content editor for the PhET widget


-   [#1533](#1533) [`cc1995daf`](cc1995d) Thanks [@nishasy](https://github.com/nishasy)! - [Locked labels] View locked labels in an Interactive Graph

### Patch Changes

-   [#1539](#1539) [`7805626e1`](7805626) Thanks [@nishasy](https://github.com/nishasy)! - [Locked Labels] Implement adding/editing/deleting a standalone locked label


-   [#1541](#1541) [`36471197c`](3647119) Thanks [@nicolecomputer](https://github.com/nicolecomputer)! - Adds a finite point question to dev gallery

## @khanacademy/[email protected]

### Major Changes

-   [#1546](#1546) [`6cbe4947e`](6cbe494) Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - Release PhET widget

    This PR releases a new PhET simulation widget to Perseus that requires an
    update in order to allow the support of new, upcoming content. Older versions
    of Perseus will be unable to render content that contains this widget.

    PhET simulations come from <https://phet.colorado.edu/>.

### Minor Changes

-   [#1539](#1539) [`7805626e1`](7805626) Thanks [@nishasy](https://github.com/nishasy)! - [Locked Labels] Implement adding/editing/deleting a standalone locked label


-   [#1542](#1542) [`a7fc2a3e3`](a7fc2a3) Thanks [@aemandine](https://github.com/aemandine)! - Design update for PhET widget


-   [#1532](#1532) [`6e102f9c4`](6e102f9) Thanks [@aemandine](https://github.com/aemandine)! - Add a content editor for the PhET widget


-   [#1533](#1533) [`cc1995daf`](cc1995d) Thanks [@nishasy](https://github.com/nishasy)! - [Locked labels] View locked labels in an Interactive Graph

### Patch Changes

-   Updated dependencies \[[`7805626e1`](7805626), [`0bf2711c0`](0bf2711), [`a7fc2a3e3`](a7fc2a3), [`4f24be79d`](4f24be7), [`6cbe4947e`](6cbe494), [`36471197c`](3647119), [`6e102f9c4`](6e102f9), [`cc1995daf`](cc1995d)]:
    -   @khanacademy/[email protected]

## @khanacademy/[email protected]

### Patch Changes

-   [#1541](#1541) [`36471197c`](3647119) Thanks [@nicolecomputer](https://github.com/nicolecomputer)! - Adds a finite point question to dev gallery

Author: khan-actions-bot

Reviewers: aemandine, #perseus

Required Reviewers:

Approved By: aemandine

Checks: ✅ Upload Coverage (ubuntu-latest, 20.x), ⏭️  Publish npm snapshot, ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Jest Coverage (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ gerald

Pull Request URL: #1544
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants