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 helper to build public widget options for Sorter #2154

Merged
merged 11 commits into from
Jan 30, 2025

Conversation

Myranae
Copy link
Contributor

@Myranae Myranae commented Jan 24, 2025

Summary:

Adds a function that takes Sorter's full widget options and filters out answer data. It also adds this function to Sorter's widget export and adds a test confirming the function does what is expected.

Issue: LEMS-2765

Test plan:

  • Confirm all checks pass
  • Confirm Sorter still works as expected

@Myranae Myranae self-assigned this Jan 24, 2025
Copy link
Contributor

github-actions bot commented Jan 24, 2025

npm Snapshot: Published

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

Example:

yarn add @khanacademy/perseus@PR2154

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

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

Copy link
Contributor

github-actions bot commented Jan 24, 2025

Size Change: +179 B (+0.01%)

Total Size: 1.48 MB

Filename Size Change
packages/perseus-core/dist/es/index.js 43.3 kB +153 B (+0.35%)
packages/perseus/dist/es/index.js 382 kB +26 B (+0.01%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 39 kB
packages/keypad-context/dist/es/index.js 760 B
packages/kmath/dist/es/index.js 86.8 kB
packages/math-input/dist/es/index.js 77.6 kB
packages/math-input/dist/es/strings.js 1.79 kB
packages/perseus-editor/dist/es/index.js 688 kB
packages/perseus-linter/dist/es/index.js 22.2 kB
packages/perseus-score/dist/es/index.js 113 kB
packages/perseus/dist/es/strings.js 5.82 kB
packages/pure-markdown/dist/es/index.js 3.66 kB
packages/simple-markdown/dist/es/index.js 12.5 kB

compressed-size-action

@Myranae Myranae marked this pull request as ready for review January 24, 2025 16:37
Comment on lines 9 to 11
correct: ["$0.005$ kilograms", "$15$ grams", "$55$ grams"],
layout: "horizontal",
padding: true,
Copy link
Contributor Author

@Myranae Myranae Jan 24, 2025

Choose a reason for hiding this comment

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

@benchristel It seems like correct is the source of the card information in this widget, since there are no other fields with that data. Maybe sorting here would work as well? It looks like the first thing the widget does to render is shuffle the correct options anyway:

    render(): React.ReactNode {
        const options = shuffle(
            this.props.correct,
            this.props.problemNum as number,
            /* ensurePermuted */ true,
        );

I wonder if changing the type (to not Readonly to allow for modifying) so that it has the same field as widget options but with a different type makes it so that it won't work as a subtype of widget options though 🤔

ex. correct: ReadonlyArray vs Array

This can be seen in the PR for Matcher

Copy link
Member

Choose a reason for hiding this comment

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

+1 for sorting. Could we also use ReadonlyArray in the public options type? I think that should work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, you're right! Looks like it does. Probably because we do the slice and I just didn't update it. Will fix that, and then there's no issue. Though I was planning on changing the "correct" key to "cards" in the public type; would that be an issue for backwards compatibility between the types?

Copy link
Member

Choose a reason for hiding this comment

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

If we change correct to cards, then the widget will have to be updated to use the correct prop when the answer has been revealed and the cards prop when it hasn't been. So it would complicate things.

This might be a good excuse to test out the migration facilities in the new perseus JSON parser. That would let us rename correct to cards on the PerseusSorterWidgetOptions type while remaining backwards-compatible with existing data. However, we can't do that until we have confirmed that the parsers are actually working in webapp, and it might be a sprint or two before that's done.

I would also support just adding a comment to the correct field to explain the situation.

Copy link
Contributor

@handeyeco handeyeco Jan 27, 2025

Choose a reason for hiding this comment

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

This might be a good excuse to test out the migration facilities in the new perseus JSON parser.

I'm fine if we decide to hold on this specific PR to wait until the parser is in place. Another (short-term) option is to bump the widget version and add a propUpgrades which is being renamed to widgetOptionsUpgrades. Only a couple of widgets do this right now and it will likely be deprecated in favor of the parser (I think???)

What would need to happen:

  1. We bump the widget version (version in WidgetExports) to a new major version
  2. We update the editor to have both correct (correct order) and cards (some arbitrary order) when it saves new Sorter widgets
  3. We add a propUpgrades that takes old versions of the widget and transforms them into the correct/cards format
  4. We update the widget to handle the correct/cards format

Obviously this will only work while we're sending the full JSON to the FE, but it will at least set us up for future changes. Once we only send the split JSON to the FE, we'll need to either:

  1. Run a backfill to upgrade all old Sorters
  2. Parse/upgrade widgets before sending them to the FE (maybe just the first time we find an old version and then we can rewrite the widget in GCS)

This also makes me realize we need to be sure to upgrade JSON before splitting it.

I'm thankful you all found this - it's exactly the kind of thing we need to know about! Since it has wider implications I'll CC @jeremywiebe

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is something that doesn't need to be figured out now. We can shuffle the data for the public widget options, but keep it named correct (and document it clearly as Ben suggests).

This means that in different types, correct will mean different things (in the public widget options, it's the initial state, in the rubric (full) type, it's the correct answer).

This isn't great, but I think results in the least churn/uncertainty right now (no logic changes needed).

I've noted this issue in the Content Issues for Backfill doc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good! I'll leave it as correct with a note, and we can come back to it later. Thanks so much, everyone!

Comment on lines 9 to 11
correct: ["$0.005$ kilograms", "$15$ grams", "$55$ grams"],
layout: "horizontal",
padding: true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is something that doesn't need to be figured out now. We can shuffle the data for the public widget options, but keep it named correct (and document it clearly as Ben suggests).

This means that in different types, correct will mean different things (in the public widget options, it's the initial state, in the rubric (full) type, it's the correct answer).

This isn't great, but I think results in the least churn/uncertainty right now (no logic changes needed).

I've noted this issue in the Content Issues for Backfill doc.

@Myranae Myranae merged commit a21fd90 into main Jan 30, 2025
8 checks passed
@Myranae Myranae deleted the tb/LEMS-2765/sorter-split branch January 30, 2025 13:49
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.

4 participants