From 0a44d468dd127bf15dc32e720b9b0301af41a572 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 3 Dec 2024 13:57:03 -0600 Subject: [PATCH 1/3] Expose a way to get user input from ServerItemRenderer (#1910) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary: This is a repeat of PR https://github.com/Khan/perseus/pull/1753 (which was reverted in https://github.com/Khan/perseus/pull/1905) While this PR is essentially the same as the previous one, I added prop upgrading to the scoring logic and the empty widget logic (along with some tests). --- I'm trying to tread lightly, maybe being overly cautious at the expense of keeping too much old code around. I tried to make everything we can get rid of after the move with `@deprecated`. Basically this should expose everything we need to move the actual scoring process out of ServerItemRenderer and the React tree. We now have `getUserInput` on `ServerItemRenderer` and `scorePerseusItem` which is a non-React, pure function that returns a score. Next step is to replace uses of `scoreInput` in Webapp with `scorePerseusItem`; then we can come back and delete a lot of this legacy code 🤞 Issue: [LEMS-2665](https://khanacademy.atlassian.net/browse/LEMS-2665) ## Test plan: After the swap in Webapp, we should be able to complete an exercise with `scorePerseusItem` and everything else will work the same. [LEMS-2665]: https://khanacademy.atlassian.net/browse/LEMS-2665?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ Author: handeyeco Reviewers: jeremywiebe, handeyeco Required Reviewers: Approved By: jeremywiebe 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), ✅ gerald, ✅ .github/dependabot.yml Pull Request URL: https://github.com/Khan/perseus/pull/1910 --- .changeset/honest-tables-impress.md | 6 + dev/flipbook.tsx | 11 +- .../src/components/__tests__/sorter.test.tsx | 12 +- packages/perseus/src/index.ts | 2 + .../perseus/src/interactive2/objective_.ts | 4 +- packages/perseus/src/renderer-util.test.ts | 375 ++++++++++++++++-- packages/perseus/src/renderer-util.ts | 71 +++- packages/perseus/src/renderer.tsx | 71 ++-- packages/perseus/src/server-item-renderer.tsx | 64 ++- packages/perseus/src/types.ts | 5 + .../widgets/categorizer/categorizer.test.ts | 18 +- .../src/widgets/definition/definition.test.ts | 7 +- .../__tests__/deprecated-standin.test.ts | 7 +- .../widgets/expression/expression.test.tsx | 18 +- .../perseus/src/widgets/group/group.test.tsx | 8 +- packages/perseus/src/widgets/group/group.tsx | 2 + .../src/widgets/matcher/matcher.test.tsx | 12 +- .../perseus/src/widgets/matrix/matrix.test.ts | 4 - .../passage/__tests__/passage.test.tsx | 9 +- testing/renderer-with-debug-ui.tsx | 11 +- 20 files changed, 571 insertions(+), 146 deletions(-) create mode 100644 .changeset/honest-tables-impress.md diff --git a/.changeset/honest-tables-impress.md b/.changeset/honest-tables-impress.md new file mode 100644 index 0000000000..29dd4efe54 --- /dev/null +++ b/.changeset/honest-tables-impress.md @@ -0,0 +1,6 @@ +--- +"@khanacademy/perseus": major +"@khanacademy/perseus-dev-ui": patch +--- + +Change ServerItemRenderer scoring APIs to externalize scoring diff --git a/dev/flipbook.tsx b/dev/flipbook.tsx index f6dde1281c..ea05772598 100644 --- a/dev/flipbook.tsx +++ b/dev/flipbook.tsx @@ -18,6 +18,7 @@ import {useEffect, useMemo, useReducer, useRef, useState} from "react"; import {Renderer} from "../packages/perseus/src"; import {SvgImage} from "../packages/perseus/src/components"; +import {scorePerseusItem} from "../packages/perseus/src/renderer-util"; import {mockStrings} from "../packages/perseus/src/strings"; import {isCorrect} from "../packages/perseus/src/util"; import {trueForAllMafsSupportedGraphTypes} from "../packages/perseus/src/widgets/interactive-graphs/mafs-supported-graph-types"; @@ -319,7 +320,15 @@ function GradableRenderer(props: QuestionRendererProps) { leftContent={