Skip to content

Commit

Permalink
Add a function to get the public widget options for an iframe widget (#…
Browse files Browse the repository at this point in the history
…2188)

## Summary:
IFrame does not have private options to remove, so all widget options are public. The IFrame get public widget options function is an identity function.

Issue: LEMS-2760

## Test plan:
- Confirm all checks pass
- Confirm widget acts as expected

Author: Myranae

Reviewers: benchristel, jeremywiebe, handeyeco

Required Reviewers:

Approved By: benchristel

Checks: ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Cypress (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), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x)

Pull Request URL: #2188
  • Loading branch information
Myranae authored Feb 4, 2025
1 parent 3ba74d1 commit 163dd67
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/twenty-masks-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@khanacademy/perseus": minor
"@khanacademy/perseus-core": minor
---

Implement a widget export function to retrieve public widget options for the IFrame widget
1 change: 1 addition & 0 deletions packages/perseus-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,4 @@ export {default as getNumericInputPublicWidgetOptions} from "./widgets/numeric-i
export {default as getNumberLinePublicWidgetOptions} from "./widgets/number-line/number-line-util";
export {default as getRadioPublicWidgetOptions} from "./widgets/radio/radio-util";
export {default as getTablePublicWidgetOptions} from "./widgets/table/table-util";
export {default as getIFramePublicWidgetOptions} from "./widgets/iframe/iframe-util";
7 changes: 7 additions & 0 deletions packages/perseus-core/src/widgets/iframe/iframe-util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type {PerseusIFrameWidgetOptions} from "../../data-schema";

export default function getIFramePublicWidgetOptions(
options: PerseusIFrameWidgetOptions,
): PerseusIFrameWidgetOptions {
return options;
}
2 changes: 2 additions & 0 deletions packages/perseus/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type {
getNumberLinePublicWidgetOptions,
getRadioPublicWidgetOptions,
getTablePublicWidgetOptions,
getIFramePublicWidgetOptions,
} from "@khanacademy/perseus-core";
import type {LinterContextProps} from "@khanacademy/perseus-linter";
import type {
Expand Down Expand Up @@ -518,6 +519,7 @@ export type WidgetTransform = (
* A union type of all the functions that provide public widget options.
*/
export type PublicWidgetOptionsFunction =
| typeof getIFramePublicWidgetOptions
| typeof getRadioPublicWidgetOptions
| typeof getNumericInputPublicWidgetOptions
| typeof getDropdownPublicWidgetOptions
Expand Down
6 changes: 5 additions & 1 deletion packages/perseus/src/widgets/iframe/iframe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
* but could also be used for embedding viz's hosted elsewhere.
*/

import {
type PerseusIFrameWidgetOptions,
getIFramePublicWidgetOptions,
} from "@khanacademy/perseus-core";
import $ from "jquery";
import * as React from "react";
import _ from "underscore";
Expand All @@ -18,7 +22,6 @@ import {getPromptJSON as _getPromptJSON} from "../../widget-ai-utils/iframe/ifra

import type {WidgetExports, WidgetProps, Widget} from "../../types";
import type {UnsupportedWidgetPromptJSON} from "../../widget-ai-utils/unsupported-widget";
import type {PerseusIFrameWidgetOptions} from "@khanacademy/perseus-core";
import type {
PerseusIFrameUserInput,
UserInputStatus,
Expand Down Expand Up @@ -169,4 +172,5 @@ export default {
widget: Iframe,
// Let's not expose it to all content creators yet
hidden: true,
getPublicWidgetOptions: getIFramePublicWidgetOptions,
} satisfies WidgetExports<typeof Iframe>;

0 comments on commit 163dd67

Please sign in to comment.