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

Migrate PerseusItem.answerArea, removing unused fields #1895

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

Conversation

benchristel
Copy link
Member

answerArea sometimes includes options and type fields. type always
seems to be set to multiple if it's present. I couldn't find evidence in
Perseus or webapp that this data is used anywhere, so I am removing it used
anywhere, so I am removing it. This is necessary to make parsePerseusItem
return a valid PerseusItem while still being able to handle existing data
that has the extra fields.

Issue: https://khanacademy.atlassian.net/browse/LEMS-2582

Test plan:

yarn test

@khan-actions-bot
Copy link
Contributor

Gerald

Required Reviewers
  • @Khan/perseus for changes to packages/perseus/src/util/parse-perseus-json/general-purpose-parsers/index.ts, packages/perseus/src/util/parse-perseus-json/general-purpose-parsers/pair.test.ts, packages/perseus/src/util/parse-perseus-json/general-purpose-parsers/pipe-parsers.test.ts, packages/perseus/src/util/parse-perseus-json/general-purpose-parsers/pipe-parsers.ts, packages/perseus/src/util/parse-perseus-json/general-purpose-parsers/pipe-parsers.typetest.ts, packages/perseus/src/util/parse-perseus-json/general-purpose-parsers/trio.test.ts, packages/perseus/src/util/parse-perseus-json/general-purpose-parsers/unknown.ts, packages/perseus/src/util/parse-perseus-json/perseus-parsers/perseus-item.test.ts, packages/perseus/src/util/parse-perseus-json/perseus-parsers/perseus-item.ts, packages/perseus/src/util/parse-perseus-json/perseus-parsers/perseus-renderer.ts, packages/perseus/src/util/parse-perseus-json/regression-tests/__snapshots__/parse-perseus-json-snapshot.test.ts.snap, packages/perseus/src/util/parse-perseus-json/regression-tests/data/orderer-option-missing-widgets.json

Don't want to be involved in this pull request? Comment #removeme and we won't notify you of further changes.

Copy link
Contributor

npm Snapshot: Published

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

Example:

yarn add @khanacademy/perseus@PR1895

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

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

Copy link
Contributor

Size Change: +368 B (+0.03%)

Total Size: 1.29 MB

Filename Size Change
packages/perseus/dist/es/index.js 425 kB +368 B (+0.09%)
ℹ️ 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 4.27 kB
packages/math-input/dist/es/index.js 77.9 kB
packages/math-input/dist/es/strings.js 1.79 kB
packages/perseus-core/dist/es/index.js 1.48 kB
packages/perseus-editor/dist/es/index.js 698 kB
packages/perseus-linter/dist/es/index.js 22.2 kB
packages/perseus/dist/es/strings.js 3.57 kB
packages/pure-markdown/dist/es/index.js 3.66 kB
packages/simple-markdown/dist/es/index.js 12.5 kB

compressed-size-action


import type {Parser, PartialParser} from "../parser-types";

const stringToNumber = summon<PartialParser<string, number>>();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Well that's a neat way to generate fakes for type testing. :) TIL

Comment on lines +44 to +45
// The "type" and "options" fields don't seem to be used anywhere. This
// migration function removes them.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep! My guess is that these were written by a buggy editor at some point.

Comment on lines +23 to +24
.then(migrateAnswerArea)
.then(record(enumeration(...ItemExtras), boolean)).parser,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just so I understand, without migrateAnswerArea the enumeration() parser tries to parse type: string and/or options: object and fails parsing?

Copy link
Member

@catandthemachines catandthemachines left a comment

Choose a reason for hiding this comment

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

Had a few questions about the implementation.

@@ -9,7 +9,9 @@ export * from "./number";
export * from "./object";
export * from "./optional";
export * from "./pair";
export * from "./pipe-parsers";
Copy link
Member

Choose a reason for hiding this comment

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

This appears to be a barrel file, in that case I would encourage you not to add more content to this file and instead reference the file it's self when referencing resources in pipe.parsers.
This is s a hard as as I don't believe we've reached a consensus on this. But for reference here's the doc presented at the Frontend Guild Meeting.
https://docs.google.com/document/d/1uNV1mX4GpVsxTLwmt7GeBx8M43gemMjxqTiQv5u5L5k/edit?usp=sharing

Copy link
Member

Choose a reason for hiding this comment

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

Yay more tests!

} from "../parser-types";

export function composeParsers<
export function pipeParsers<T>(p: Parser<T>): ParserPipeline<T> {
Copy link
Member

Choose a reason for hiding this comment

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

I am not familiar with these files, so forgive me if this is a newbie question. What is the purpose of adding this function and class to pipe-parsers for the Migration answerArea and removing unused fields. This looks like your cleaning up something else on top of this work, which isn't bad. But just curious how this loops back to the issue you're trying to fix.

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