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

[LEMS-2852] Answerless Expression #2226

Merged
merged 30 commits into from
Mar 5, 2025
Merged

Conversation

handeyeco
Copy link
Contributor

@handeyeco handeyeco commented Feb 11, 2025

Summary:

So the main thing with the Expression widget is that it was using answer data to determine which extraKeys to show in the MathInput keypad. For instance if a possible answer was 42i, it would show i in the Extra tab on the keypad.

This PR sets us up for removing answers by adding extraKeys to the data schema so it can be determined at publish time rather than read time. We simulate this by upgrading the widget to provide extraKeys when not present on the data.

Issue: LEMS-2852

Test plan:

  • Go to an Expression widget that has a constant/variable in the answer
  • It should render the same, including having the constant/variable in the keypad
  • It should be answerable/scorable

@handeyeco handeyeco self-assigned this Feb 11, 2025
Copy link
Contributor

github-actions bot commented Feb 11, 2025

Size Change: +205 B (+0.02%)

Total Size: 875 kB

Filename Size Change
packages/math-input/dist/es/index.js 77.7 kB -498 B (-0.64%)
packages/perseus-core/dist/es/index.js 31.9 kB +1.32 kB (+4.31%)
packages/perseus-editor/dist/es/index.js 276 kB +92 B (+0.03%)
packages/perseus/dist/es/index.js 368 kB -707 B (-0.19%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 39.7 kB
packages/keypad-context/dist/es/index.js 760 B
packages/kmath/dist/es/index.js 11.1 kB
packages/math-input/dist/es/strings.js 1.79 kB
packages/perseus-linter/dist/es/index.js 22.8 kB
packages/perseus-score/dist/es/index.js 20.6 kB
packages/perseus/dist/es/strings.js 6.73 kB
packages/pure-markdown/dist/es/index.js 4.14 kB
packages/simple-markdown/dist/es/index.js 13.1 kB

compressed-size-action

@handeyeco handeyeco changed the title [LEMS-2852/expression-answerless] make transform work with both forms of data LEMS-2852 Answerless Expression Feb 11, 2025
@handeyeco handeyeco changed the title LEMS-2852 Answerless Expression [LEMS-2852] Answerless Expression Feb 11, 2025
Comment on lines 842 to 844
"extraKeys": [
"PI",
],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe instead of having deriveExtraKeys default to ["PI"] it should just be empty and the props can default to ["PI"] when rendering...

expect(score).toHaveBeenAnsweredCorrectly();
});

it("is interactive with answerless widget options", async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the important one. Without answer data we:

  • Render
  • Answer
  • Send the input off for scoring

* to be included as keys on the keypad. These are scraped from the answer
* forms.
*/
export const keypadConfigurationForProps = (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most of this logic was for deriving extra keys, so I just transformed this into deriveExtraKeys.

buttonsVisible: v0options.buttonsVisible,
visibleLabel: v0options.visibleLabel,
ariaLabel: v0options.ariaLabel,
extraKeys: v0options.extraKeys,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Remove this

extraKeys: v1options.extraKeys || deriveExtraKeys(v1options),
};
},
"1": (v0options: any): PerseusExpressionWidgetOptions => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This probably shouldn't return PerseusExpressionWidgetOptions

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed. I believe long-term we won't be keeping this widget upgrade system (in favour of the new parsing system). I had a comment in the test file for this file that we could add a v1 widget options type. That's some extra work but keeps it explicit what these functions are accepting/returning. 🤷‍♂️

Copy link
Contributor

github-actions bot commented Feb 24, 2025

npm Snapshot: Published

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

Example:

pnpm add @khanacademy/perseus@PR2226

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

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

@handeyeco handeyeco force-pushed the LEMS-2852/expression-answerless branch from 40246a0 to 8e08204 Compare February 25, 2025 14:30
@handeyeco handeyeco marked this pull request as ready for review February 25, 2025 15:14
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.

A bunch of thoughts and nits... but I think this makes sense as it is!

// What extra keys need to be displayed on the keypad so that the
// question can be answerable without a keyboard (ie mobile)
// TODO: this is really ReadonlyArray<Key>
extraKeys?: ReadonlyArray<string>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this be updated now that the types have been moved to perseus-core?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll make the change, but I was still a little unsure because this would be the only import into data-schema I think.

});

// Assert
expect(result.keypadConfiguration.extraKeys).toEqual(["x"]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Guessing this is existing logic, but I'm surprised it doesn't merge them.

@handeyeco handeyeco merged commit 909148c into main Mar 5, 2025
8 checks passed
@handeyeco handeyeco deleted the LEMS-2852/expression-answerless branch March 5, 2025 18:44
handeyeco pushed a commit that referenced this pull request Mar 5, 2025
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/math-input@23.0.0

### Major Changes

- [#2226](#2226)
[`909148cdc`](909148c)
Thanks [@handeyeco](https://github.com/handeyeco)! - Answerless
Expression: Expression can render and is interactive with answerless
data

### Patch Changes

- Updated dependencies
\[[`a0aee41b6`](a0aee41),
[`909148cdc`](909148c)]:
    -   @khanacademy/perseus-core@5.0.0
    -   @khanacademy/keypad-context@1.1.1

## @khanacademy/perseus@56.0.0

### Major Changes

- [#2233](#2233)
[`a0aee41b6`](a0aee41)
Thanks [@handeyeco](https://github.com/handeyeco)! - RadioWidget v2 in
support of answerless Radio

### Patch Changes

- [#2279](#2279)
[`e02cc4109`](e02cc41)
Thanks [@nishasy](https://github.com/nishasy)! - [SR] Tweak strings for
Segment and Angle graphs


- [#2270](#2270)
[`941343ee3`](941343e)
Thanks [@catandthemachines](https://github.com/catandthemachines)! -
Fixing side snapping within polygons to be keyboard accessible.


- [#2226](#2226)
[`909148cdc`](909148c)
Thanks [@handeyeco](https://github.com/handeyeco)! - Answerless
Expression: Expression can render and is interactive with answerless
data

- Updated dependencies
\[[`a0aee41b6`](a0aee41),
[`909148cdc`](909148c)]:
    -   @khanacademy/perseus-core@5.0.0
    -   @khanacademy/math-input@23.0.0
    -   @khanacademy/keypad-context@1.1.1
    -   @khanacademy/kmath@0.4.1
    -   @khanacademy/perseus-linter@1.3.1
    -   @khanacademy/perseus-score@2.3.1

## @khanacademy/perseus-core@5.0.0

### Major Changes

- [#2233](#2233)
[`a0aee41b6`](a0aee41)
Thanks [@handeyeco](https://github.com/handeyeco)! - RadioWidget v2 in
support of answerless Radio


- [#2226](#2226)
[`909148cdc`](909148c)
Thanks [@handeyeco](https://github.com/handeyeco)! - Answerless
Expression: Expression can render and is interactive with answerless
data

## @khanacademy/perseus-editor@17.9.0

### Minor Changes

- [#2226](#2226)
[`909148cdc`](909148c)
Thanks [@handeyeco](https://github.com/handeyeco)! - Answerless
Expression: Expression can render and is interactive with answerless
data

### Patch Changes

- [#2233](#2233)
[`a0aee41b6`](a0aee41)
Thanks [@handeyeco](https://github.com/handeyeco)! - RadioWidget v2 in
support of answerless Radio

- Updated dependencies
\[[`e02cc4109`](e02cc41),
[`941343ee3`](941343e),
[`a0aee41b6`](a0aee41),
[`909148cdc`](909148c)]:
    -   @khanacademy/perseus@56.0.0
    -   @khanacademy/perseus-core@5.0.0
    -   @khanacademy/math-input@23.0.0
    -   @khanacademy/keypad-context@1.1.1
    -   @khanacademy/kmath@0.4.1
    -   @khanacademy/perseus-linter@1.3.1
    -   @khanacademy/perseus-score@2.3.1

## @khanacademy/keypad-context@1.1.1

### Patch Changes

- Updated dependencies
\[[`a0aee41b6`](a0aee41),
[`909148cdc`](909148c)]:
    -   @khanacademy/perseus-core@5.0.0

## @khanacademy/kmath@0.4.1

### Patch Changes

- Updated dependencies
\[[`a0aee41b6`](a0aee41),
[`909148cdc`](909148c)]:
    -   @khanacademy/perseus-core@5.0.0

## @khanacademy/perseus-linter@1.3.1

### Patch Changes

- Updated dependencies
\[[`a0aee41b6`](a0aee41),
[`909148cdc`](909148c)]:
    -   @khanacademy/perseus-core@5.0.0

## @khanacademy/perseus-score@2.3.1

### Patch Changes

- Updated dependencies
\[[`a0aee41b6`](a0aee41),
[`909148cdc`](909148c)]:
    -   @khanacademy/perseus-core@5.0.0
    -   @khanacademy/kmath@0.4.1

## @khanacademy/perseus-dev-ui@5.3.1

### Patch Changes

- Updated dependencies
\[[`a0aee41b6`](a0aee41),
[`909148cdc`](909148c)]:
    -   @khanacademy/perseus-core@5.0.0
    -   @khanacademy/math-input@23.0.0
    -   @khanacademy/kmath@0.4.1
    -   @khanacademy/perseus-linter@1.3.1

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
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.

2 participants