Skip to content

Commit

Permalink
Batch 2 of simple default widget option transfers (#2145)
Browse files Browse the repository at this point in the history
## Summary:
I couldn't justify doing a PR per widget because all of these are really straight-forward; there's no prop upgrades or versions or anything. It's just moving "default props" from editors into "default widget options" in core so we can do minor upgrades on the server.

[LEMS-2737/default-collection-2] video
[LEMS-2737/default-collection-2] sorter
[LEMS-2737/default-collection-2] phet
[LEMS-2737/default-collection-2] orderer
[LEMS-2737/default-collection-2] numeric-input
[LEMS-2737/default-collection-2] matrix

Issue: LEMS-2737

## Test plan:
Nothing should change, just moving code

Author: handeyeco

Reviewers: jeremywiebe

Required Reviewers:

Approved By: jeremywiebe

Checks: ✅ Cypress (ubuntu-latest, 20.x), ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x)

Pull Request URL: #2145
  • Loading branch information
handeyeco authored Jan 24, 2025
1 parent dc8118a commit 8a48960
Show file tree
Hide file tree
Showing 18 changed files with 221 additions and 57 deletions.
6 changes: 6 additions & 0 deletions .changeset/dull-cats-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@khanacademy/perseus-core": minor
"@khanacademy/perseus-editor": patch
---

Move simple widget upgrade logic to Perseus Core (pt 2)
16 changes: 15 additions & 1 deletion packages/perseus-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export {pluck, mapObject} from "./utils/objective_";

export {default as categorizerLogic} from "./widgets/categorizer";
export type {CategorizerDefaultWidgetOptions} from "./widgets/categorizer";
export {default as csPropgramWidgetLogic} from "./widgets/cs-program";
export {default as csProgramLogic} from "./widgets/cs-program";
export type {CSProgramDefaultWidgetOptions} from "./widgets/cs-program";
export {default as definitionLogic} from "./widgets/definition";
export type {DefinitionDefaultWidgetOptions} from "./widgets/definition";
Expand Down Expand Up @@ -62,16 +62,30 @@ export {default as labelImageLogic} from "./widgets/label-image";
export type {LabelImageDefaultWidgetOptions} from "./widgets/label-image";
export {default as matcherLogic} from "./widgets/matcher";
export type {MatcherDefaultWidgetOptions} from "./widgets/matcher";
export {default as matrixLogic} from "./widgets/matrix";
export type {MatrixDefaultWidgetOptions} from "./widgets/matrix";
export {default as measurerLogic} from "./widgets/measurer";
export type {MeasurerDefaultWidgetOptions} from "./widgets/measurer";
export {default as numericInputLogic} from "./widgets/numeric-input";
export type {NumericInputDefaultWidgetOptions} from "./widgets/numeric-input";
export {default as ordererLogic} from "./widgets/orderer";
export type {OrdererDefaultWidgetOptions} from "./widgets/orderer";
export {default as passageLogic} from "./widgets/passage";
export type {PassageDefaultWidgetOptions} from "./widgets/passage";
export {default as passageRefLogic} from "./widgets/passage-ref";
export type {PassageRefDefaultWidgetOptions} from "./widgets/passage-ref";
export {default as passageRefTargetLogic} from "./widgets/passage-ref-target";
export type {PassageRefTargetDefaultWidgetOptions} from "./widgets/passage-ref-target";
export {default as phetSimulationLogic} from "./widgets/phet-simulation";
export type {PhetSimulationDefaultWidgetOptions} from "./widgets/phet-simulation";
export {default as pythonProgramLogic} from "./widgets/python-program";
export type {PythonProgramDefaultWidgetOptions} from "./widgets/python-program";
export {default as radioLogic} from "./widgets/radio";
export type {RadioDefaultWidgetOptions} from "./widgets/radio";
export {default as sorterLogic} from "./widgets/sorter";
export type {SorterDefaultWidgetOptions} from "./widgets/sorter";
export {default as videoLogic} from "./widgets/video";
export type {VideoDefaultWidgetOptions} from "./widgets/video";

export type * from "./widgets/logic-export.types";

Expand Down
4 changes: 2 additions & 2 deletions packages/perseus-core/src/widgets/cs-program/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ const defaultWidgetOptions: CSProgramDefaultWidgetOptions = {
height: DEFAULT_HEIGHT,
};

const csPropgramWidgetLogic: WidgetLogic = {
const csProgramWidgetLogic: WidgetLogic = {
name: "cs-program",
defaultWidgetOptions,
};

export default csPropgramWidgetLogic;
export default csProgramWidgetLogic;
22 changes: 22 additions & 0 deletions packages/perseus-core/src/widgets/matrix/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type {PerseusMatrixWidgetOptions} from "../../data-schema";
import type {WidgetLogic} from "../logic-export.types";

export type MatrixDefaultWidgetOptions = Pick<
PerseusMatrixWidgetOptions,
"matrixBoardSize" | "answers" | "prefix" | "suffix" | "cursorPosition"
>;

const defaultWidgetOptions: MatrixDefaultWidgetOptions = {
matrixBoardSize: [3, 3],
answers: [[]],
prefix: "",
suffix: "",
cursorPosition: [0, 0],
};

const matrixWidgetLogic: WidgetLogic = {
name: "matrix",
defaultWidgetOptions,
};

export default matrixWidgetLogic;
32 changes: 32 additions & 0 deletions packages/perseus-core/src/widgets/numeric-input/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type {PerseusNumericInputWidgetOptions} from "../../data-schema";
import type {WidgetLogic} from "../logic-export.types";

export type NumericInputDefaultWidgetOptions = Pick<
PerseusNumericInputWidgetOptions,
"answers" | "size" | "coefficient" | "labelText" | "rightAlign"
>;

const defaultWidgetOptions: NumericInputDefaultWidgetOptions = {
answers: [
{
value: null,
status: "correct",
message: "",
simplify: "required",
answerForms: [],
strict: false,
maxError: null,
},
],
size: "normal",
coefficient: false,
labelText: "",
rightAlign: false,
};

const numericInputWidgetLogic: WidgetLogic = {
name: "numeric-input",
defaultWidgetOptions,
};

export default numericInputWidgetLogic;
21 changes: 21 additions & 0 deletions packages/perseus-core/src/widgets/orderer/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type {PerseusOrdererWidgetOptions} from "../../data-schema";
import type {WidgetLogic} from "../logic-export.types";

export type OrdererDefaultWidgetOptions = Pick<
PerseusOrdererWidgetOptions,
"correctOptions" | "otherOptions" | "height" | "layout"
>;

const defaultWidgetOptions: OrdererDefaultWidgetOptions = {
correctOptions: [{content: "$x$"}] as any,
otherOptions: [{content: "$y$"}] as any,
height: "normal",
layout: "horizontal",
};

const ordererWidgetLogic: WidgetLogic = {
name: "orderer",
defaultWidgetOptions,
};

export default ordererWidgetLogic;
19 changes: 19 additions & 0 deletions packages/perseus-core/src/widgets/phet-simulation/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type {PerseusPhetSimulationWidgetOptions} from "../../data-schema";
import type {WidgetLogic} from "../logic-export.types";

export type PhetSimulationDefaultWidgetOptions = Pick<
PerseusPhetSimulationWidgetOptions,
"url" | "description"
>;

const defaultWidgetOptions: PhetSimulationDefaultWidgetOptions = {
url: "",
description: "",
};

const PhetSimulationWidgetLogic: WidgetLogic = {
name: "phet-simulation",
defaultWidgetOptions,
};

export default PhetSimulationWidgetLogic;
19 changes: 19 additions & 0 deletions packages/perseus-core/src/widgets/python-program/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type {PerseusPythonProgramWidgetOptions} from "../../data-schema";
import type {WidgetLogic} from "../logic-export.types";

export type PythonProgramDefaultWidgetOptions = Pick<
PerseusPythonProgramWidgetOptions,
"programID" | "height"
>;

const defaultWidgetOptions: PythonProgramDefaultWidgetOptions = {
programID: "",
height: 400,
};

const pythonProgramWidgetLogic: WidgetLogic = {
name: "python-program",
defaultWidgetOptions,
};

export default pythonProgramWidgetLogic;
20 changes: 20 additions & 0 deletions packages/perseus-core/src/widgets/sorter/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type {PerseusSorterWidgetOptions} from "../../data-schema";
import type {WidgetLogic} from "../logic-export.types";

export type SorterDefaultWidgetOptions = Pick<
PerseusSorterWidgetOptions,
"correct" | "layout" | "padding"
>;

const defaultWidgetOptions: SorterDefaultWidgetOptions = {
correct: ["$x$", "$y$", "$z$"],
layout: "horizontal",
padding: true,
};

const sorterWidgetLogic: WidgetLogic = {
name: "sorter",
defaultWidgetOptions,
};

export default sorterWidgetLogic;
18 changes: 18 additions & 0 deletions packages/perseus-core/src/widgets/video/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type {PerseusVideoWidgetOptions} from "../../data-schema";
import type {WidgetLogic} from "../logic-export.types";

export type VideoDefaultWidgetOptions = Pick<
PerseusVideoWidgetOptions,
"location"
>;

const defaultWidgetOptions: VideoDefaultWidgetOptions = {
location: "",
};

const videoWidgetLogic: WidgetLogic = {
name: "video",
defaultWidgetOptions,
};

export default videoWidgetLogic;
4 changes: 2 additions & 2 deletions packages/perseus-editor/src/widgets/cs-program-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
EditorJsonify,
Log,
} from "@khanacademy/perseus";
import {csPropgramWidgetLogic, Errors} from "@khanacademy/perseus-core";
import {csProgramLogic, Errors} from "@khanacademy/perseus-core";
import {Checkbox} from "@khanacademy/wonder-blocks-form";
import $ from "jquery";
import PropTypes from "prop-types";
Expand Down Expand Up @@ -151,7 +151,7 @@ class CSProgramEditor extends React.Component<any> {
static widgetName = "cs-program" as const;

static defaultProps: CSProgramDefaultWidgetOptions =
csPropgramWidgetLogic.defaultWidgetOptions;
csProgramLogic.defaultWidgetOptions;

change: (...args: ReadonlyArray<unknown>) => any = (...args) => {
// @ts-expect-error - TS2345 - Argument of type 'readonly unknown[]' is not assignable to parameter of type 'any[]'.
Expand Down
13 changes: 5 additions & 8 deletions packages/perseus-editor/src/widgets/matrix-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import {
EditorJsonify,
MatrixWidget,
} from "@khanacademy/perseus";
import {getMatrixSize} from "@khanacademy/perseus-core";
import {getMatrixSize, matrixLogic} from "@khanacademy/perseus-core";
import PropTypes from "prop-types";
import * as React from "react";
import _ from "underscore";

import Editor from "../editor";

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

const {RangeInput} = components;
const Matrix = MatrixWidget.widget;

Expand All @@ -32,13 +34,8 @@ class MatrixEditor extends React.Component<Props> {

static widgetName = "matrix" as const;

static defaultProps: Props = {
matrixBoardSize: [3, 3],
answers: [[]],
prefix: "",
suffix: "",
cursorPosition: [0, 0],
};
static defaultProps: MatrixDefaultWidgetOptions =
matrixLogic.defaultWidgetOptions;

change: (arg1: any, arg2: any, arg3: any) => any = (...args) => {
return Changeable.change.apply(this, args);
Expand Down
13 changes: 6 additions & 7 deletions packages/perseus-editor/src/widgets/numeric-input-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import {
PerseusI18nContext,
iconTrash,
} from "@khanacademy/perseus";
import {
numericInputLogic,
type NumericInputDefaultWidgetOptions,
} from "@khanacademy/perseus-core";
import {Checkbox} from "@khanacademy/wonder-blocks-form";
import * as React from "react";
import _ from "underscore";
Expand Down Expand Up @@ -109,13 +113,8 @@ class NumericInputEditor extends React.Component<Props, State> {
static widgetName = "numeric-input";
static displayName = "NumericInputEditor";

static defaultProps = {
answers: [initAnswer("correct")],
size: "normal",
coefficient: false,
labelText: "",
rightAlign: false,
};
static defaultProps: NumericInputDefaultWidgetOptions =
numericInputLogic.defaultWidgetOptions;

constructor(props: Props) {
super(props);
Expand Down
12 changes: 6 additions & 6 deletions packages/perseus-editor/src/widgets/orderer-editor.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/* eslint-disable @khanacademy/ts-no-error-suppressions */
/* eslint-disable react/forbid-prop-types */
import {components} from "@khanacademy/perseus";
import {
ordererLogic,
type OrdererDefaultWidgetOptions,
} from "@khanacademy/perseus-core";
import PropTypes from "prop-types";
import * as React from "react";
import _ from "underscore";
Expand All @@ -25,12 +29,8 @@ class OrdererEditor extends React.Component<Props> {

static widgetName = "orderer" as const;

static defaultProps: Props = {
correctOptions: [{content: "$x$"}],
otherOptions: [{content: "$y$"}],
height: NORMAL,
layout: HORIZONTAL,
};
static defaultProps: OrdererDefaultWidgetOptions =
ordererLogic.defaultWidgetOptions;

onOptionsChange: (
arg1: "correctOptions" | "otherOptions",
Expand Down
20 changes: 8 additions & 12 deletions packages/perseus-editor/src/widgets/phet-simulation-editor.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
/* eslint-disable @khanacademy/ts-no-error-suppressions */
import {makeSafeUrl} from "@khanacademy/perseus";
import {
phetSimulationLogic,
type PerseusPhetSimulationWidgetOptions,
type PhetSimulationDefaultWidgetOptions,
} from "@khanacademy/perseus-core";
import {LabeledTextField} from "@khanacademy/wonder-blocks-form";
import {spacing} from "@khanacademy/wonder-blocks-tokens";
import * as React from "react";

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

type DefaultProps = {
url: PerseusPhetSimulationWidgetOptions["url"];
description: PerseusPhetSimulationWidgetOptions["description"];
};

type Props = DefaultProps & {
type Props = PhetSimulationDefaultWidgetOptions & {
onChange: (arg1: {
url?: Props["url"];
description?: Props["description"];
}) => void;
};

class PhetSimulationEditor extends React.Component<Props> {
static defaultProps: DefaultProps = {
url: "",
description: "",
};
static defaultProps: PhetSimulationDefaultWidgetOptions =
phetSimulationLogic.defaultWidgetOptions;

static widgetName = "phet-simulation" as const;

Expand Down
19 changes: 8 additions & 11 deletions packages/perseus-editor/src/widgets/python-program-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@
* This editor is for embedding Khan Academy Python programs.
*/
import {components, Changeable} from "@khanacademy/perseus";
import {pythonProgramLogic} from "@khanacademy/perseus-core";
import * as React from "react";

const {NumberInput, TextInput} = components;
import type {
PerseusPythonProgramWidgetOptions,
PythonProgramDefaultWidgetOptions,
} from "@khanacademy/perseus-core";

import type {PerseusPythonProgramWidgetOptions} from "@khanacademy/perseus-core";
const {NumberInput, TextInput} = components;

type Props = Changeable.ChangeableProps & {
programID: string;
height: number;
};

type DefaultProps = {
programID: Props["programID"];
height: Props["height"];
};

export function validateOptions(
height: Props["height"],
programID: Props["programID"],
Expand All @@ -41,10 +40,8 @@ export function validateOptions(
class PythonProgramEditor extends React.Component<Props> {
static widgetName = "python-program" as const;

static defaultProps: DefaultProps = {
programID: "",
height: 400,
};
static defaultProps: PythonProgramDefaultWidgetOptions =
pythonProgramLogic.defaultWidgetOptions;

change: (...args: ReadonlyArray<unknown>) => any = (...args) => {
// @ts-expect-error - TS2345 - Argument of type 'readonly unknown[]' is not assignable to parameter of type 'any[]'.
Expand Down
Loading

0 comments on commit 8a48960

Please sign in to comment.