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

Make values optional on PerseusCategorizerWidgetOptions type #2123

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

benchristel
Copy link
Member

This is a proof of concept of how we might change the WidgetOptions types so we
can avoid sending "private data" like hints and answers to the client.

Issue: LEMS-2562

Test plan:

yarn test

const values = categorizer.options?.values;
const categories = categorizer.options.categories;
const items = categorizer.options.items;
const values = categorizer.options.values;
Copy link
Member Author

Choose a reason for hiding this comment

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

These ?. nullish coalescing operators were not needed, since we check the nullishness of each of these fields above.

@@ -28,13 +28,13 @@ import type {CategorizerPromptJSON} from "../../widget-ai-utils/categorizer/cate
import type {PerseusCategorizerWidgetOptions} from "@khanacademy/perseus-core";

type Props = WidgetProps<RenderProps, PerseusCategorizerScoringData> & {
values: ReadonlyArray<string>;
values: ReadonlyArray<number>;
Copy link
Member Author

Choose a reason for hiding this comment

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

This should have been ReadonlyArray<number> all along. Fixing this let me remove the @ts-expect-error below.

Copy link
Contributor

npm Snapshot: Published

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

Example:

yarn add @khanacademy/perseus@PR2123

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

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

Copy link
Contributor

Size Change: -59 B (0%)

Total Size: 1.47 MB

Filename Size Change
packages/perseus/dist/es/index.js 412 kB -59 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 83.1 kB
packages/math-input/dist/es/index.js 78 kB
packages/math-input/dist/es/strings.js 1.79 kB
packages/perseus-core/dist/es/index.js 23.1 kB
packages/perseus-editor/dist/es/index.js 689 kB
packages/perseus-linter/dist/es/index.js 22.2 kB
packages/perseus-score/dist/es/index.js 103 kB
packages/perseus/dist/es/strings.js 5.04 kB
packages/pure-markdown/dist/es/index.js 3.66 kB
packages/simple-markdown/dist/es/index.js 12.5 kB

compressed-size-action

@@ -423,7 +423,7 @@ export type PerseusCategorizerWidgetOptions = {
// Whether this widget is displayed with the results and immutable
static: boolean;
// The correct answers where index relates to the items and value relates to the category. e.g. [0, 1, 0, 1, 2]
values: ReadonlyArray<number>;
values?: ReadonlyArray<number>;
Copy link
Member Author

Choose a reason for hiding this comment

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

Potential concern here: with this change, the data-schema types no longer represent the JSON that actually gets persisted. The JSON should always have the values field, but the client won't always receive it.

If we wanted to fix this, we would have to decouple the widget prop types from these data-schema types. Though I think maybe they are already pretty much decoupled (in theory) by the transform and staticTransform functions. transform renders the widget with public-only data and staticTransform renders with public+private data.

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.

1 participant