Skip to content

Commit

Permalink
Add save warnings to PhET widget editor and unhide widget (#1582)
Browse files Browse the repository at this point in the history
## Summary:
* Add `getSaveWarnings()` function to PhET widget editor so that a widget cannot be saved with a non-PhET URL
* Unhide the widget from the content editor

<img width="1465" alt="A save warning popup, Are you sure you want to save your changes with errors? phet-simulation 1: Please enter a URL from the PhET domain." src="https://github.com/user-attachments/assets/34ac2131-5237-4aa3-9f63-91d379d8e12c">

Issue: LEMS-2292

## Test plan:
* `yarn jest packages/perseus/src/widgets/__tests__/phet-simulation.test.ts`
* `yarn jest packages/perseus-editor/src/widgets/__tests__/phet-simulation-editor.test.tsx`
* Verify that the widget and editor still show up in Storybook
* Verify that the editor displays an error when a non-PhET URL is typed into the PhET widget content editor

Author: aemandine

Reviewers: SonicScrewdriver, aemandine

Required Reviewers:

Approved By: SonicScrewdriver

Checks: ❌ codecov/project, ✅ codecov/patch, ✅ Upload Coverage (ubuntu-latest, 20.x), ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (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), ✅ Jest Coverage (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ gerald

Pull Request URL: #1582
  • Loading branch information
aemandine authored Sep 4, 2024
1 parent c875acd commit 377b7ce
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/thirty-pans-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@khanacademy/perseus": minor
"@khanacademy/perseus-editor": minor
---

Add save warnings to PhET widget editor and un-hide widget from content editor widget dropdown
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable @khanacademy/ts-no-error-suppressions */
import {makeSafeUrl} from "@khanacademy/perseus";
import {LabeledTextField} from "@khanacademy/wonder-blocks-form";
import * as React from "react";

Expand Down Expand Up @@ -31,6 +32,13 @@ class PhetSimulationEditor extends React.Component<Props> {
};
}

getSaveWarnings: () => ReadonlyArray<string> = () => {
if (makeSafeUrl(this.props.url, "en") === null) {
return ["Please enter a URL from the PhET domain."];
}
return [];
};

render(): React.ReactNode {
return (
<div>
Expand Down
2 changes: 2 additions & 0 deletions packages/perseus/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ export {
getAngleCoords,
} from "./widgets/interactive-graphs/reducer/initialize-graph-state";

export {makeSafeUrl} from "./widgets/phet-simulation";

/**
* Mixins
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus/src/widgets/phet-simulation/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export {default} from "./phet-simulation";
export {default, makeSafeUrl} from "./phet-simulation";
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,5 @@ export default {
name: "phet-simulation",
displayName: "PhET Simulation",
widget: PhetSimulation,
// Hides widget from content creators until full release
hidden: true,
isLintable: true,
} as WidgetExports<typeof PhetSimulation>;

0 comments on commit 377b7ce

Please sign in to comment.