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

Move validation types from perseus to perseus-score #2101

Merged
merged 9 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/perseus-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ export type {
KEScore,
KeypadContextRendererInterface,
RendererInterface,
MarkerType,
InteractiveMarkerType,
Relationship,
} from "./types";
export type {ErrorKind} from "./error/errors";

Expand Down
26 changes: 26 additions & 0 deletions packages/perseus-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,29 @@ export type KEScore = {
guess: any;
state: any;
};

// TODO: should these be part of data-schema?
// Base marker, with the props that are set by the editor.
export type MarkerType = {
// The list of correct answers expected for the marker.
answers: ReadonlyArray<string>;
// The marker title or description.
label: string;
// The marker coordinates on the question image as percent of image size.
x: number;
y: number;
};

// TODO: should these be part of data-schema?
// Additional props that are set when user interacts with the marker.
export type InteractiveMarkerType = MarkerType & {
handeyeco marked this conversation as resolved.
Show resolved Hide resolved
// The user selected list of answers, used to grade the question.
selected?: ReadonlyArray<string>;
// Reveal the correctness state of the user selected answers for the marker.
showCorrectness?: "correct" | "incorrect";
focused?: boolean;
};

// TODO: should these be part of data-schema?
// Used for NumberLine
export type Relationship = "lt" | "gt" | "le" | "ge";
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 so, yes. Looks like correctRel on the NumberLineWidgetOptions should actually be using this also.

correctRel: string | null | undefined;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm 🤔 But correctRel also has "eq"

    // The correct relative value. default: "eq". options: "eq", "lt", "gt", "le", "ge"
    correctRel: string | null | undefined;

Whereas Relationship doesn't include that. I'm just going to update my TODO to be about investigating merging the two.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as React from "react";

import LabelImageEditor from "../label-image-editor";

import type {MarkerType} from "@khanacademy/perseus";
import type {MarkerType} from "@khanacademy/perseus-core";

type StoryArgs = Record<any, any>;

Expand Down
2 changes: 1 addition & 1 deletion packages/perseus-editor/src/widgets/label-image-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Behavior from "./label-image/behavior";
import QuestionMarkers from "./label-image/question-markers";
import SelectImage from "./label-image/select-image";

import type {MarkerType} from "@khanacademy/perseus";
import type {MarkerType} from "@khanacademy/perseus-core";

type Props = {
// List of answer choices to label question image with.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as React from "react";

import QuestionMarkers from "../question-markers";

import type {MarkerType} from "@khanacademy/perseus";
import type {MarkerType} from "@khanacademy/perseus-core";

type StoryArgs = Record<any, any>;

Expand Down
2 changes: 1 addition & 1 deletion packages/perseus-editor/src/widgets/label-image/marker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Option, {OptionGroup} from "../../components/dropdown-option";
import FormWrappedTextField from "../../components/form-wrapped-text-field";
import {gray17, gray85, gray98} from "../../styles/global-colors";

import type {MarkerType} from "@khanacademy/perseus";
import type {MarkerType} from "@khanacademy/perseus-core";

type Props = MarkerType & {
// The list of possible answer choices.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {gray17, gray68} from "../../styles/global-colors";

import Marker from "./marker";

import type {MarkerType} from "@khanacademy/perseus";
import type {MarkerType} from "@khanacademy/perseus-core";

type Props = {
// The list of possible answers in a specific order.
Expand Down
1 change: 1 addition & 0 deletions packages/perseus-score/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export {default as KhanAnswerTypes} from "./util/answer-types";
export type {Score} from "./util/answer-types";
export {default as ErrorCodes} from "./error-codes";
export type * from "./validation.types";
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
* ```
*/

import type {InteractiveMarkerType} from "./widgets/label-image/types";
import type {Relationship} from "./widgets/number-line/number-line";
import type {
GrapherAnswerTypes,
PerseusDropdownChoice,
Expand All @@ -44,6 +42,8 @@ import type {
PerseusOrdererWidgetOptions,
PerseusRadioChoice,
PerseusGraphCorrectType,
InteractiveMarkerType,
Relationship,
} from "@khanacademy/perseus-core";

export type UserInputStatus = "correct" | "incorrect" | "incomplete";
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus/src/__tests__/renderer-api.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import mockWidget1Item from "./test-items/mock-widget-1-item";
import mockWidget2Item from "./test-items/mock-widget-2-item";
import tableItem from "./test-items/table-item";

import type {PerseusMockWidgetUserInput} from "../validation.types";
import type {PerseusMockWidgetUserInput} from "@khanacademy/perseus-score";
import type {UserEvent} from "@testing-library/user-event";

const itemWidget = mockWidget1Item;
Expand Down
2 changes: 0 additions & 2 deletions packages/perseus/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,8 @@ export type {
} from "./types";
export type {ParsedValue} from "./util";
export type {Result, Success, Failure} from "./util/parse-perseus-json/result";
export type {UserInputMap} from "./validation.types";
export type {Coord} from "./interactive2/types";
export type {Coords} from "./widgets/grapher/grapher-types";
export type {MarkerType} from "./widgets/label-image/types";
export type {
RendererPromptJSON,
WidgetPromptJSON,
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus/src/renderer-util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import {registerAllWidgetsForTesting} from "./util/register-all-widgets-for-test
import {renderQuestion} from "./widgets/__testutils__/renderQuestion";
import {question1} from "./widgets/group/group.testdata";

import type {UserInputMap} from "./validation.types";
import type {
DropdownWidget,
ExpressionWidget,
PerseusWidgetsMap,
} from "@khanacademy/perseus-core";
import type {UserInputMap} from "@khanacademy/perseus-score";
import type {UserEvent} from "@testing-library/user-event";

function getTestDropdownWidget(): DropdownWidget {
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus/src/renderer-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import {getWidgetScorer, upgradeWidgetInfoToLatestVersion} from "./widgets";

import type {PerseusStrings} from "./strings";
import type {PerseusScore} from "./types";
import type {UserInput, UserInputMap} from "./validation.types";
import type {
PerseusRenderer,
PerseusWidgetsMap,
} from "@khanacademy/perseus-core";
import type {UserInput, UserInputMap} from "@khanacademy/perseus-score";

export function getUpgradedWidgetOptions(
oldWidgetOptions: PerseusWidgetsMap,
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus/src/renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import type {
Widget,
WidgetProps,
} from "./types";
import type {UserInputArray, UserInputMap} from "./validation.types";
import type {
GetPromptJSONInterface,
RendererPromptJSON,
Expand All @@ -62,6 +61,7 @@ import type {
ShowSolutions,
} from "@khanacademy/perseus-core";
import type {LinterContextProps} from "@khanacademy/perseus-linter";
import type {UserInputArray, UserInputMap} from "@khanacademy/perseus-score";

import "./styles/perseus-renderer.less";

Expand Down
2 changes: 1 addition & 1 deletion packages/perseus/src/server-item-renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import type {
PerseusDependenciesV2,
SharedRendererProps,
} from "./types";
import type {UserInputArray, UserInputMap} from "./validation.types";
import type {
GetPromptJSONInterface,
RendererPromptJSON,
Expand All @@ -39,6 +38,7 @@ import type {
RendererInterface,
KEScore,
} from "@khanacademy/perseus-core";
import type {UserInputArray, UserInputMap} from "@khanacademy/perseus-score";
import type {PropsFor} from "@khanacademy/wonder-blocks-core";

type OwnProps = {
Expand Down
12 changes: 6 additions & 6 deletions packages/perseus/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import type {ILogger} from "./logging/log";
import type {PerseusStrings} from "./strings";
import type {SizeClass} from "./util/sizing-utils";
import type {
Rubric,
UserInput,
UserInputArray,
UserInputMap,
} from "./validation.types";
import type {WidgetPromptJSON} from "./widget-ai-utils/prompt-types";
import type {KeypadAPI} from "@khanacademy/math-input";
import type {
Expand All @@ -18,6 +12,12 @@ import type {
AnalyticsEventHandlerFn,
} from "@khanacademy/perseus-core";
import type {LinterContextProps} from "@khanacademy/perseus-linter";
import type {
Rubric,
UserInput,
UserInputArray,
UserInputMap,
} from "@khanacademy/perseus-score";
import type {Result} from "@khanacademy/wonder-blocks-data";
import type * as React from "react";

Expand Down
2 changes: 1 addition & 1 deletion packages/perseus/src/util/scoring.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {Errors, PerseusError} from "@khanacademy/perseus-core";

import type {PerseusScore} from "../types";
import type {UserInputArray} from "../validation.types";
import type {KEScore} from "@khanacademy/perseus-core";
import type {UserInputArray} from "@khanacademy/perseus-score";

const noScore: PerseusScore = {
type: "points",
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus/src/util/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {scorePerseusItem} from "../renderer-util";
import {mockStrings} from "../strings";

import type {PerseusScore} from "../types";
import type {UserInputMap} from "../validation.types";
import type {
CategorizerWidget,
ExpressionWidget,
Expand All @@ -12,6 +11,7 @@ import type {
PerseusRenderer,
RadioWidget,
} from "@khanacademy/perseus-core";
import type {UserInputMap} from "@khanacademy/perseus-score";

export const genericPerseusItemData: PerseusItem = {
question: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {renderQuestion} from "../../widgets/__testutils__/renderQuestion";

import {getPromptJSON} from "./categorizer-ai-utils";

import type {PerseusCategorizerUserInput} from "../../validation.types";
import type {PerseusRenderer} from "@khanacademy/perseus-core";
import type {PerseusCategorizerUserInput} from "@khanacademy/perseus-score";
import type {UserEvent} from "@testing-library/user-event";

const randomizedQuestion: PerseusRenderer = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {PerseusCategorizerUserInput} from "../../validation.types";
import type categorizer from "../../widgets/categorizer/categorizer";
import type {PerseusCategorizerUserInput} from "@khanacademy/perseus-score";
import type React from "react";

export type CategorizerPromptJSON = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {renderQuestion} from "../../widgets/__testutils__/renderQuestion";

import {getPromptJSON} from "./dropdown-ai-utils";

import type {PerseusDropdownUserInput} from "../../validation.types";
import type {PerseusRenderer} from "@khanacademy/perseus-core";
import type {PerseusDropdownUserInput} from "@khanacademy/perseus-score";
import type {UserEvent} from "@testing-library/user-event";

const question1: PerseusRenderer = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {PerseusDropdownUserInput} from "../../validation.types";
import type dropdown from "../../widgets/dropdown/dropdown";
import type {PerseusDropdownUserInput} from "@khanacademy/perseus-score";
import type React from "react";

export type DropdownPromptJSON = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {PerseusExpressionUserInput} from "../../validation.types";
import type expression from "../../widgets/expression/expression";
import type {PerseusExpressionUserInput} from "@khanacademy/perseus-score";
import type React from "react";

export type ExpressionPromptJSON = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {PerseusGrapherUserInput} from "../../validation.types";
import type grapher from "../../widgets/grapher/grapher";
import type {GrapherAnswerTypes} from "@khanacademy/perseus-core";
import type {PerseusGrapherUserInput} from "@khanacademy/perseus-score";
import type React from "react";

export type GrapherPromptJSON = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {renderQuestion} from "../../widgets/__testutils__/renderQuestion";

import {getPromptJSON} from "./input-number-ai-utils";

import type {PerseusInputNumberUserInput} from "../../validation.types";
import type {
InputNumberWidget,
PerseusRenderer,
} from "@khanacademy/perseus-core";
import type {PerseusInputNumberUserInput} from "@khanacademy/perseus-score";
import type {UserEvent} from "@testing-library/user-event";

const question: PerseusRenderer = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {PerseusInputNumberUserInput} from "../../validation.types";
import type inputNumber from "../../widgets/input-number/input-number";
import type {PerseusInputNumberUserInput} from "@khanacademy/perseus-score";
import type React from "react";

export type InputNumberPromptJSON = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {PerseusLabelImageUserInput} from "../../validation.types";
import type labelImage from "../../widgets/label-image/label-image";
import type {PerseusLabelImageUserInput} from "@khanacademy/perseus-score";
import type React from "react";

type BaseMarker = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {renderQuestion} from "../../widgets/__testutils__/renderQuestion";

import {getPromptJSON} from "./matcher-ai-utils";

import type {PerseusMatcherUserInput} from "../../validation.types";
import type {PerseusRenderer} from "@khanacademy/perseus-core";
import type {PerseusMatcherUserInput} from "@khanacademy/perseus-score";

const question1: PerseusRenderer = {
content:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {PerseusMatcherUserInput} from "../../validation.types";
import type matcher from "../../widgets/matcher/matcher";
import type {PerseusMatcherUserInput} from "@khanacademy/perseus-score";
import type React from "react";

export type MatcherPromptJSON = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {PerseusMatrixUserInput} from "../../validation.types";
import type matrix from "../../widgets/matrix/matrix";
import type {PerseusMatrixUserInput} from "@khanacademy/perseus-score";
import type React from "react";

export type MatrixPromptJSON = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {getPromptJSON} from "./prompt-utils";

import type {PerseusMockWidgetUserInput} from "../../validation.types";
import type {PerseusMockWidgetUserInput} from "@khanacademy/perseus-score";

describe("InputNumber getPromptJSON", () => {
it("it returns JSON with the expected format and fields", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {PerseusMockWidgetUserInput} from "../../validation.types";
import type mockWidget from "../../widgets/mock-widgets/mock-widget";
import type {PerseusMockWidgetUserInput} from "@khanacademy/perseus-score";
import type React from "react";

export type MockWidgetPromptJSON = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {PerseusNumberLineUserInput} from "../../validation.types";
import type numberLine from "../../widgets/number-line/number-line";
import type {PerseusNumberLineUserInput} from "@khanacademy/perseus-score";
import type React from "react";

export type NumberLinePromptJSON = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {getPromptJSON} from "./prompt-utils";

import type {PerseusNumericInputUserInput} from "../../validation.types";
import type {PerseusNumericInputUserInput} from "@khanacademy/perseus-score";

describe("NumericInput getPromptJSON", () => {
it("it returns JSON with the expected format and fields", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {PerseusNumericInputUserInput} from "../../validation.types";
import type numericInput from "../../widgets/numeric-input/numeric-input";
import type {PerseusNumericInputUserInput} from "@khanacademy/perseus-score";
import type React from "react";

export type NumericInputPromptJSON = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {PerseusOrdererUserInput} from "../../validation.types";
import type orderer from "../../widgets/orderer/orderer";
import type {PerseusOrdererUserInput} from "@khanacademy/perseus-score";
import type React from "react";

export type OrdererPromptJSON = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {renderQuestion} from "../../widgets/__testutils__/renderQuestion";

import {getPromptJSON} from "./radio-ai-utils";

import type {PerseusRadioUserInput} from "../../validation.types";
import type {PerseusRenderer, RadioWidget} from "@khanacademy/perseus-core";
import type {PerseusRadioUserInput} from "@khanacademy/perseus-score";
import type {UserEvent} from "@testing-library/user-event";

const shuffledQuestion: PerseusRenderer = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {PerseusRadioUserInput} from "../../validation.types";
import type radio from "../../widgets/radio/radio";
import type {PerseusRadioUserInput} from "@khanacademy/perseus-score";
import type React from "react";

export type BasicOption = {
Expand Down
Loading
Loading