From 9a00cd740f9c906def4c9baf75572b51e01e29d5 Mon Sep 17 00:00:00 2001 From: Sarah Third Date: Fri, 22 Nov 2024 10:45:47 -0800 Subject: [PATCH 1/9] Revert "Fixing issue with Input Numbers that have a value of 0 (#1888)" This reverts commit d0e7a0383002414d874297ccc88bf5c9863b4ea5. --- .../server-item-renderer.stories.tsx | 5 --- .../server-item-renderer.testdata.ts | 32 ------------------- .../widgets/numeric-input/numeric-input.tsx | 4 +-- 3 files changed, 2 insertions(+), 39 deletions(-) diff --git a/packages/perseus/src/__stories__/server-item-renderer.stories.tsx b/packages/perseus/src/__stories__/server-item-renderer.stories.tsx index b4077ec2bb..e3fd9ecd96 100644 --- a/packages/perseus/src/__stories__/server-item-renderer.stories.tsx +++ b/packages/perseus/src/__stories__/server-item-renderer.stories.tsx @@ -5,7 +5,6 @@ import {ServerItemRendererWithDebugUI} from "../../../../testing/server-item-ren import {storybookDependenciesV2} from "../../../../testing/test-dependencies"; import { itemWithInput, - itemWithInputNumber, itemWithLintingError, labelImageItem, itemWithImages, @@ -28,10 +27,6 @@ export const NumericInputItem = (args: StoryArgs): React.ReactElement => { return ; }; -export const InputNumberItem = (args: StoryArgs): React.ReactElement => { - return ; -}; - export const LabelImageItem = (args: StoryArgs): React.ReactElement => { return ; }; diff --git a/packages/perseus/src/__testdata__/server-item-renderer.testdata.ts b/packages/perseus/src/__testdata__/server-item-renderer.testdata.ts index 9ad1b366c5..d9c74cb6e8 100644 --- a/packages/perseus/src/__testdata__/server-item-renderer.testdata.ts +++ b/packages/perseus/src/__testdata__/server-item-renderer.testdata.ts @@ -7,7 +7,6 @@ import { type ExpressionWidget, type RadioWidget, type NumericInputWidget, - type InputNumberWidget, } from "../perseus-types"; export const itemWithInput: PerseusItem = { @@ -49,37 +48,6 @@ export const itemWithInput: PerseusItem = { answer: null, }; -export const itemWithInputNumber: PerseusItem = { - question: { - content: - "Enter the number $$-42$$ in the box: [[\u2603 input-number 1]]", - images: {}, - widgets: { - "input-number 1": { - type: "input-number", - graded: true, - options: { - static: false, - value: 0, - simplify: "required", - maxError: 0.1, - inexact: false, - answerType: "number", - size: "small", - }, - } as InputNumberWidget, - }, - }, - hints: [ - {content: "Hint #1", images: {}, widgets: {}}, - {content: "Hint #2", images: {}, widgets: {}}, - {content: "Hint #3", images: {}, widgets: {}}, - ], - answerArea: null, - itemDataVersion: {major: 0, minor: 0}, - answer: null, -}; - export const itemWithMultipleNumericInputs: PerseusItem = { question: { content: diff --git a/packages/perseus/src/widgets/numeric-input/numeric-input.tsx b/packages/perseus/src/widgets/numeric-input/numeric-input.tsx index d8dafd5557..367db27d89 100644 --- a/packages/perseus/src/widgets/numeric-input/numeric-input.tsx +++ b/packages/perseus/src/widgets/numeric-input/numeric-input.tsx @@ -345,10 +345,10 @@ const propsTransform = function ( const propUpgrades = { /* c8 ignore next */ "1": (initialProps: any): PerseusNumericInputWidgetOptions => { - // If the initialProps has simplify, it means we're upgrading from + // If the initialProps has a value, it means we're upgrading from // input-number to numeric-input. In this case, we need to upgrade // the widget options accordingly. - if (initialProps.simplify !== undefined) { + if (initialProps.value) { // If the answerType is not number or percent, we need to provide // the answer form for the numeric-input widget const provideAnswerForm = From 21e494f318e2bf514017cef661afaef444345c2a Mon Sep 17 00:00:00 2001 From: Sarah Third Date: Fri, 22 Nov 2024 10:46:35 -0800 Subject: [PATCH 2/9] Revert "Ensuring UserInput and Rubric widget keys match (#1884)" This reverts commit b4cf444e962b5e4c152cad6507ddb63515fc305e. --- packages/perseus/src/renderer-util.ts | 18 +++++++--------- .../util/deprecated-widgets/input-number.ts | 21 ++----------------- .../modernize-widgets-utils.ts | 18 +++++++--------- 3 files changed, 17 insertions(+), 40 deletions(-) diff --git a/packages/perseus/src/renderer-util.ts b/packages/perseus/src/renderer-util.ts index ddd4965da2..55e7c6b809 100644 --- a/packages/perseus/src/renderer-util.ts +++ b/packages/perseus/src/renderer-util.ts @@ -1,7 +1,8 @@ import Util from "./util"; import { conversionRequired, - convertDeprecatedWidgetsForScoring, + convertDeprecatedWidgets, + convertUserInputData, } from "./util/deprecated-widgets/modernize-widgets-utils"; import {getWidgetIdsFromContent} from "./widget-type-utils"; import {getWidgetScorer} from "./widgets"; @@ -65,17 +66,14 @@ export function scorePerseusItem( strings: PerseusStrings, locale: string, ): PerseusScore { - let convertedRenderData = perseusRenderData; - let convertedUserInputMap = userInputMap; - // Check if the PerseusRenderer object contains any deprecated widgets that need to be converted const mustConvertData = conversionRequired(perseusRenderData); - if (mustConvertData) { - const {convertedRubric, convertedUserData} = - convertDeprecatedWidgetsForScoring(perseusRenderData, userInputMap); - convertedRenderData = convertedRubric; - convertedUserInputMap = convertedUserData; - } + const convertedRenderData = mustConvertData + ? convertDeprecatedWidgets(perseusRenderData) // Convert deprecated widgets to their modern equivalents + : perseusRenderData; + const convertedUserInputMap = mustConvertData + ? convertUserInputData(userInputMap) // Convert deprecated user input data keys to their modern equivalents + : userInputMap; // There seems to be a chance that PerseusRenderer.widgets might include // widget data for widgets that are not in PerseusRenderer.content, diff --git a/packages/perseus/src/util/deprecated-widgets/input-number.ts b/packages/perseus/src/util/deprecated-widgets/input-number.ts index c0d0b3342d..53070befe7 100644 --- a/packages/perseus/src/util/deprecated-widgets/input-number.ts +++ b/packages/perseus/src/util/deprecated-widgets/input-number.ts @@ -1,4 +1,5 @@ // Methods to convert input-number widgets to numeric-input widgets + import type { NumericInputWidget, PerseusRenderer, @@ -161,13 +162,12 @@ export const getInputNumberRenameMap = ( // Convert the user input data keys from input-number to numeric-input export const convertUserInputNumberData = ( userInputMap: UserInputMap, - renameMap: WidgetRenameMap, ): UserInputMap => { const updatedUserInputMap = {...userInputMap}; for (const key of Object.keys(userInputMap)) { if (key.includes("input-number")) { - const updatedKey = renameMap[key]; + const updatedKey = key.replace("input-number", "numeric-input"); updatedUserInputMap[updatedKey] = userInputMap[key]; delete updatedUserInputMap[key]; } @@ -175,20 +175,3 @@ export const convertUserInputNumberData = ( return updatedUserInputMap; }; - -// Used to convert InputNumber widgets to NumericInput widgets for scoring -export const convertInputNumberForScoring = ( - rubric: PerseusRenderer, - userInputMap: UserInputMap, -): {convertedRubric: PerseusRenderer; convertedUserData: UserInputMap} => { - // First we need to create a map of the old input-number keys to the new numeric-input keys - // so that we can ensure we update the content, widgets, AND userInput accordingly - const renameMap = getInputNumberRenameMap(rubric); - const convertedRubric = convertInputNumberJson(rubric, renameMap); - const convertedUserData = convertUserInputNumberData( - userInputMap, - renameMap, - ); - - return {convertedRubric, convertedUserData}; -}; diff --git a/packages/perseus/src/util/deprecated-widgets/modernize-widgets-utils.ts b/packages/perseus/src/util/deprecated-widgets/modernize-widgets-utils.ts index f44cf4246f..8d0e2ff3f8 100644 --- a/packages/perseus/src/util/deprecated-widgets/modernize-widgets-utils.ts +++ b/packages/perseus/src/util/deprecated-widgets/modernize-widgets-utils.ts @@ -1,6 +1,6 @@ import { inputNumberToNumericInput, - convertInputNumberForScoring, + convertUserInputNumberData, } from "./input-number"; import type {PerseusRenderer, UserInputMap} from "@khanacademy/perseus"; @@ -12,7 +12,6 @@ const widgetRegExes = [/input-number \d+/]; // We can add more regexes here in t // content creators use the Editor Page to update content containing these widgets. // Currently, we're only converting input-number to numeric-input, // but we can add more conversions here in the future. - // Modernize the json content of a PerseusRenderer object // by converting deprecated widgets to their modern equivalents export const convertDeprecatedWidgets = ( @@ -46,14 +45,11 @@ export const conversionRequired = (json: PerseusRenderer): boolean => { return false; }; -/** - * Convert the deprecated widgets in the rubric and user data to their - * modern equivalents for scoring. These need to be updated together - * in order to ensure that the widgetKeys match between the rubric and user data. - */ -export const convertDeprecatedWidgetsForScoring = ( - rubric: PerseusRenderer, +// Convert the user input data keys for deprecated widgets to their modern equivalents +export const convertUserInputData = ( userInputMap: UserInputMap, -): {convertedRubric: PerseusRenderer; convertedUserData: UserInputMap} => { - return convertInputNumberForScoring(rubric, userInputMap); +): UserInputMap => { + // Currently we're only converting input-number to numeric-input, + // But we can add more conversions here in the future + return convertUserInputNumberData(userInputMap); }; From 37cc5e6f81edb713fe6717b3426589196158f63e Mon Sep 17 00:00:00 2001 From: Sarah Third Date: Fri, 22 Nov 2024 10:46:53 -0800 Subject: [PATCH 3/9] Revert "Fixing conflicts that arose from Input Number Conversion and Server Side Scoring projects (#1879)" This reverts commit 04d6e60de2b9176f546a7058038a10689e52f9ac. --- .../perseus-editor/src/article-editor.tsx | 12 +++++------ packages/perseus-editor/src/editor-page.tsx | 12 +++++------ .../util/deprecated-widgets/input-number.ts | 18 ----------------- .../modernize-widgets-utils.test.ts | 0 .../modernize-widgets-utils.testdata.ts | 0 .../modernize-widgets-utils.ts | 16 ++------------- packages/perseus/src/index.ts | 4 ---- packages/perseus/src/renderer-util.ts | 20 +++---------------- 8 files changed, 15 insertions(+), 67 deletions(-) rename packages/{perseus => perseus-editor}/src/util/deprecated-widgets/input-number.ts (91%) rename packages/{perseus => perseus-editor}/src/util/deprecated-widgets/modernize-widgets-utils.test.ts (100%) rename packages/{perseus => perseus-editor}/src/util/deprecated-widgets/modernize-widgets-utils.testdata.ts (100%) rename packages/{perseus => perseus-editor}/src/util/deprecated-widgets/modernize-widgets-utils.ts (74%) diff --git a/packages/perseus-editor/src/article-editor.tsx b/packages/perseus-editor/src/article-editor.tsx index 7cd233e8e3..9342ef6639 100644 --- a/packages/perseus-editor/src/article-editor.tsx +++ b/packages/perseus-editor/src/article-editor.tsx @@ -4,13 +4,7 @@ * multiple (Renderer) sections concatenated together. */ -import { - components, - ApiOptions, - iconTrash, - conversionRequired, - convertDeprecatedWidgets, -} from "@khanacademy/perseus"; +import {components, ApiOptions, iconTrash} from "@khanacademy/perseus"; import {Errors, PerseusError} from "@khanacademy/perseus-core"; import Banner from "@khanacademy/wonder-blocks-banner"; import * as React from "react"; @@ -26,6 +20,10 @@ import { iconCircleArrowUp, iconPlus, } from "./styles/icon-paths"; +import { + convertDeprecatedWidgets, + conversionRequired, +} from "./util/deprecated-widgets/modernize-widgets-utils"; import type { APIOptions, diff --git a/packages/perseus-editor/src/editor-page.tsx b/packages/perseus-editor/src/editor-page.tsx index 3a782b531c..8d069f5c62 100644 --- a/packages/perseus-editor/src/editor-page.tsx +++ b/packages/perseus-editor/src/editor-page.tsx @@ -1,10 +1,4 @@ -import { - components, - ApiOptions, - ClassNames, - conversionRequired, - convertDeprecatedWidgets, -} from "@khanacademy/perseus"; +import {components, ApiOptions, ClassNames} from "@khanacademy/perseus"; import Banner from "@khanacademy/wonder-blocks-banner"; import * as React from "react"; import _ from "underscore"; @@ -13,6 +7,10 @@ import JsonEditor from "./components/json-editor"; import ViewportResizer from "./components/viewport-resizer"; import CombinedHintsEditor from "./hint-editor"; import ItemEditor from "./item-editor"; +import { + convertDeprecatedWidgets, + conversionRequired, +} from "./util/deprecated-widgets/modernize-widgets-utils"; import type { APIOptions, diff --git a/packages/perseus/src/util/deprecated-widgets/input-number.ts b/packages/perseus-editor/src/util/deprecated-widgets/input-number.ts similarity index 91% rename from packages/perseus/src/util/deprecated-widgets/input-number.ts rename to packages/perseus-editor/src/util/deprecated-widgets/input-number.ts index 53070befe7..a753b51966 100644 --- a/packages/perseus/src/util/deprecated-widgets/input-number.ts +++ b/packages/perseus-editor/src/util/deprecated-widgets/input-number.ts @@ -4,7 +4,6 @@ import type { NumericInputWidget, PerseusRenderer, PerseusWidgetsMap, - UserInputMap, } from "@khanacademy/perseus"; type WidgetRenameMap = { @@ -158,20 +157,3 @@ export const getInputNumberRenameMap = ( return renameMap; }; - -// Convert the user input data keys from input-number to numeric-input -export const convertUserInputNumberData = ( - userInputMap: UserInputMap, -): UserInputMap => { - const updatedUserInputMap = {...userInputMap}; - - for (const key of Object.keys(userInputMap)) { - if (key.includes("input-number")) { - const updatedKey = key.replace("input-number", "numeric-input"); - updatedUserInputMap[updatedKey] = userInputMap[key]; - delete updatedUserInputMap[key]; - } - } - - return updatedUserInputMap; -}; diff --git a/packages/perseus/src/util/deprecated-widgets/modernize-widgets-utils.test.ts b/packages/perseus-editor/src/util/deprecated-widgets/modernize-widgets-utils.test.ts similarity index 100% rename from packages/perseus/src/util/deprecated-widgets/modernize-widgets-utils.test.ts rename to packages/perseus-editor/src/util/deprecated-widgets/modernize-widgets-utils.test.ts diff --git a/packages/perseus/src/util/deprecated-widgets/modernize-widgets-utils.testdata.ts b/packages/perseus-editor/src/util/deprecated-widgets/modernize-widgets-utils.testdata.ts similarity index 100% rename from packages/perseus/src/util/deprecated-widgets/modernize-widgets-utils.testdata.ts rename to packages/perseus-editor/src/util/deprecated-widgets/modernize-widgets-utils.testdata.ts diff --git a/packages/perseus/src/util/deprecated-widgets/modernize-widgets-utils.ts b/packages/perseus-editor/src/util/deprecated-widgets/modernize-widgets-utils.ts similarity index 74% rename from packages/perseus/src/util/deprecated-widgets/modernize-widgets-utils.ts rename to packages/perseus-editor/src/util/deprecated-widgets/modernize-widgets-utils.ts index 8d0e2ff3f8..6459695403 100644 --- a/packages/perseus/src/util/deprecated-widgets/modernize-widgets-utils.ts +++ b/packages/perseus-editor/src/util/deprecated-widgets/modernize-widgets-utils.ts @@ -1,9 +1,6 @@ -import { - inputNumberToNumericInput, - convertUserInputNumberData, -} from "./input-number"; +import {inputNumberToNumericInput} from "./input-number"; -import type {PerseusRenderer, UserInputMap} from "@khanacademy/perseus"; +import type {PerseusRenderer} from "@khanacademy/perseus"; const widgetRegExes = [/input-number \d+/]; // We can add more regexes here in the future @@ -44,12 +41,3 @@ export const conversionRequired = (json: PerseusRenderer): boolean => { return false; }; - -// Convert the user input data keys for deprecated widgets to their modern equivalents -export const convertUserInputData = ( - userInputMap: UserInputMap, -): UserInputMap => { - // Currently we're only converting input-number to numeric-input, - // But we can add more conversions here in the future - return convertUserInputNumberData(userInputMap); -}; diff --git a/packages/perseus/src/index.ts b/packages/perseus/src/index.ts index fcb40a1451..35600885ae 100644 --- a/packages/perseus/src/index.ts +++ b/packages/perseus/src/index.ts @@ -82,10 +82,6 @@ export {isItemRenderableByVersion} from "./renderability"; export {violatingWidgets} from "./a11y"; export {interactiveSizes} from "./styles/constants"; export {displaySigFigs} from "./sigfigs"; -export { - conversionRequired, - convertDeprecatedWidgets, -} from "./util/deprecated-widgets/modernize-widgets-utils"; // Context for managing i18n export { diff --git a/packages/perseus/src/renderer-util.ts b/packages/perseus/src/renderer-util.ts index 55e7c6b809..36b18db795 100644 --- a/packages/perseus/src/renderer-util.ts +++ b/packages/perseus/src/renderer-util.ts @@ -1,9 +1,4 @@ import Util from "./util"; -import { - conversionRequired, - convertDeprecatedWidgets, - convertUserInputData, -} from "./util/deprecated-widgets/modernize-widgets-utils"; import {getWidgetIdsFromContent} from "./widget-type-utils"; import {getWidgetScorer} from "./widgets"; @@ -66,23 +61,14 @@ export function scorePerseusItem( strings: PerseusStrings, locale: string, ): PerseusScore { - // Check if the PerseusRenderer object contains any deprecated widgets that need to be converted - const mustConvertData = conversionRequired(perseusRenderData); - const convertedRenderData = mustConvertData - ? convertDeprecatedWidgets(perseusRenderData) // Convert deprecated widgets to their modern equivalents - : perseusRenderData; - const convertedUserInputMap = mustConvertData - ? convertUserInputData(userInputMap) // Convert deprecated user input data keys to their modern equivalents - : userInputMap; - // There seems to be a chance that PerseusRenderer.widgets might include // widget data for widgets that are not in PerseusRenderer.content, // so this checks that the widgets are being used before scoring them - const usedWidgetIds = getWidgetIdsFromContent(convertedRenderData.content); + const usedWidgetIds = getWidgetIdsFromContent(perseusRenderData.content); const scores = scoreWidgetsFunctional( - convertedRenderData.widgets, + perseusRenderData.widgets, usedWidgetIds, - convertedUserInputMap, + userInputMap, strings, locale, ); From d7d4833852b417857cee226d319438497fd68f14 Mon Sep 17 00:00:00 2001 From: Sarah Third Date: Fri, 22 Nov 2024 10:47:20 -0800 Subject: [PATCH 4/9] Revert "Expose a way to get user input from ServerItemRenderer (#1753)" This reverts commit c1ba55fc0247e16d9a78558721969382ee6992f8. --- dev/flipbook.tsx | 11 +--- .../src/components/__tests__/sorter.test.tsx | 12 ++-- packages/perseus/src/index.ts | 2 - packages/perseus/src/renderer-util.test.ts | 51 +-------------- packages/perseus/src/renderer-util.ts | 31 +-------- packages/perseus/src/renderer.tsx | 38 ++++++----- 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 +--- 18 files changed, 76 insertions(+), 234 deletions(-) diff --git a/dev/flipbook.tsx b/dev/flipbook.tsx index ea05772598..f6dde1281c 100644 --- a/dev/flipbook.tsx +++ b/dev/flipbook.tsx @@ -18,7 +18,6 @@ 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"; @@ -320,15 +319,7 @@ function GradableRenderer(props: QuestionRendererProps) { leftContent={