Skip to content

Commit

Permalink
Move Passage widgets default props (#2143)
Browse files Browse the repository at this point in the history
## Summary:
Tidied up some versions and move Passage widget stuff that we'll need to be able to use on the server.

- Passage
- PassageRef
- PassageRefTarget

Issue: LEMS-2737

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

Author: handeyeco

Reviewers: handeyeco, jeremywiebe

Required Reviewers:

Approved By: jeremywiebe

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

Pull Request URL: #2143
  • Loading branch information
handeyeco authored Jan 24, 2025
1 parent d7bcb14 commit 459c250
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 22 deletions.
7 changes: 7 additions & 0 deletions .changeset/fast-kids-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@khanacademy/perseus-core": minor
"@khanacademy/perseus": patch
"@khanacademy/perseus-editor": patch
---

Move Passage widgets upgrade logic to Perseus Core
6 changes: 6 additions & 0 deletions packages/perseus-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ export {default as expressionLogic} from "./widgets/expression";
export type {ExpressionDefaultWidgetOptions} from "./widgets/expression";
export {default as measurerLogic} from "./widgets/measurer";
export type {MeasurerDefaultWidgetOptions} from "./widgets/measurer";
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 radioLogic} from "./widgets/radio";
export type {RadioDefaultWidgetOptions} from "./widgets/radio";

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

export type PassageRefTargetDefaultWidgetOptions = Pick<
PerseusPassageRefTargetWidgetOptions,
"content"
>;

const defaultWidgetOptions: PassageRefTargetDefaultWidgetOptions = {
content: "",
};

const passageRefTargetWidgetLogic: WidgetLogic = {
name: "passageRefTarget",
defaultWidgetOptions,
};

export default passageRefTargetWidgetLogic;
13 changes: 13 additions & 0 deletions packages/perseus-core/src/widgets/passage-ref/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {currentVersion, defaultWidgetOptions} from "./passage-ref-upgrade";

import type {WidgetLogic} from "../logic-export.types";

export type {PassageRefDefaultWidgetOptions} from "./passage-ref-upgrade";

const passageRefWidgetLogic: WidgetLogic = {
name: "passageRef",
version: currentVersion,
defaultWidgetOptions: defaultWidgetOptions,
};

export default passageRefWidgetLogic;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type {PerseusPassageRefWidgetOptions} from "../../data-schema";

export const currentVersion = {major: 0, minor: 1};

export type PassageRefDefaultWidgetOptions = Pick<
PerseusPassageRefWidgetOptions,
"passageNumber" | "referenceNumber" | "summaryText"
>;

export const defaultWidgetOptions: PassageRefDefaultWidgetOptions = {
passageNumber: 1,
referenceNumber: 1,
summaryText: "",
};
21 changes: 21 additions & 0 deletions packages/perseus-core/src/widgets/passage/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type {PerseusPassageWidgetOptions} from "../../data-schema";
import type {WidgetLogic} from "../logic-export.types";

export type PassageDefaultWidgetOptions = Pick<
PerseusPassageWidgetOptions,
"passageTitle" | "passageText" | "footnotes" | "showLineNumbers"
>;

const defaultWidgetOptions: PassageDefaultWidgetOptions = {
passageTitle: "",
passageText: "",
footnotes: "",
showLineNumbers: true,
};

const passageWidgetLogic: WidgetLogic = {
name: "passage",
defaultWidgetOptions,
};

export default passageWidgetLogic;
11 changes: 5 additions & 6 deletions packages/perseus-editor/src/widgets/passage-editor.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import {components, Changeable, EditorJsonify} from "@khanacademy/perseus";
import {passageLogic} from "@khanacademy/perseus-core";
import {Checkbox} from "@khanacademy/wonder-blocks-form";
import PropTypes from "prop-types";
import * as React from "react";
import _ from "underscore";

import Editor from "../editor";

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

const {InfoTip} = components;

type Props = any;
Expand All @@ -21,12 +24,8 @@ class PassageEditor extends React.Component<Props> {

static widgetName = "passage" as const;

static defaultProps: Props = {
passageTitle: "",
passageText: "",
footnotes: "",
showLineNumbers: true,
};
static defaultProps: PassageDefaultWidgetOptions =
passageLogic.defaultWidgetOptions;

change: (arg1: any, arg2: any, arg3: any) => any = (...args) => {
return Changeable.change.apply(this, args);
Expand Down
10 changes: 5 additions & 5 deletions packages/perseus-editor/src/widgets/passage-ref-editor.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/* eslint-disable @khanacademy/ts-no-error-suppressions */
import {components, Changeable, EditorJsonify} from "@khanacademy/perseus";
import {passageRefLogic} from "@khanacademy/perseus-core";
import PropTypes from "prop-types";
import * as React from "react";

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

const {InfoTip, NumberInput, TextInput} = components;

type Props = any;
Expand All @@ -17,11 +20,8 @@ class PassageRefEditor extends React.Component<Props> {

static widgetName = "passage-ref" as const;

static defaultProps: Props = {
passageNumber: 1,
referenceNumber: 1,
summaryText: "",
};
static defaultProps: PassageRefDefaultWidgetOptions =
passageRefLogic.defaultWidgetOptions;

change: (arg1: any, arg2: any, arg3: any) => any = (...args) => {
return Changeable.change.apply(this, args);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import {Changeable, EditorJsonify} from "@khanacademy/perseus";
import {
passageRefTargetLogic,
type PassageRefTargetDefaultWidgetOptions,
} from "@khanacademy/perseus-core";
import PropTypes from "prop-types";
import * as React from "react";
import _ from "underscore";
Expand All @@ -13,9 +17,8 @@ class PassageRefTargetEditor extends React.Component<Props> {

static widgetName = "passage-ref-target" as const;

static defaultProps: Props = {
content: "",
};
static defaultProps: PassageRefTargetDefaultWidgetOptions =
passageRefTargetLogic.defaultWidgetOptions;

change: (arg1: any, arg2: any, arg3: any) => any = (...args) => {
return Changeable.change.apply(this, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ class InteractiveGraphQuestionBuilder {
lockedFigures: this.lockedFigures,
},
type: "interactive-graph",
version: {
major: 0,
minor: 0,
},
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const mockedAssetItem: PerseusItem = {
static: false,
graded: true,
options: Object.freeze({value: ""}),
version: {major: 1, minor: 0},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export default {
transform: (editorProps: any): any => {
return _.pick(editorProps, "content");
},
version: {major: 0, minor: 0},
isLintable: true,
// TODO: things that aren't interactive shouldn't need scoring functions
scorer: () => scoreNoop(),
Expand Down
7 changes: 5 additions & 2 deletions packages/perseus/src/widgets/passage-ref/passage-ref.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import {
passageRefLogic,
type PerseusPassageRefWidgetOptions,
} from "@khanacademy/perseus-core";
import * as React from "react";
import _ from "underscore";

Expand All @@ -10,7 +14,6 @@ import {isPassageWidget} from "../passage/utils";

import type {ChangeFn, Widget, WidgetExports, WidgetProps} from "../../types";
import type {PassageRefPromptJSON} from "../../widget-ai-utils/passage-ref/passage-ref-ai-utils";
import type {PerseusPassageRefWidgetOptions} from "@khanacademy/perseus-core";
import type {PropsFor} from "@khanacademy/wonder-blocks-core";

const EN_DASH = "\u2013";
Expand Down Expand Up @@ -185,7 +188,7 @@ export default {
referenceNumber: widgetOptions.referenceNumber,
summaryText: widgetOptions.summaryText,
}),
version: {major: 0, minor: 1},
version: passageRefLogic.version,
// TODO: things that aren't interactive shouldn't need scoring functions
scorer: () => scoreNoop(),
} satisfies WidgetExports<typeof PassageRef>;

0 comments on commit 459c250

Please sign in to comment.