Skip to content

Commit

Permalink
Fixing up the editor side of things.
Browse files Browse the repository at this point in the history
  • Loading branch information
SonicScrewdriver committed Oct 9, 2024
1 parent a59be5f commit c38dc8c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/perseus-editor/src/components/widget-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ class WidgetEditor extends React.Component<
href="#"
onClick={this._toggleWidget}
>
{this.props.id}
{this.props.id}{" "}
{this.props.id.split(" ")[0] === "input-number"
? " (deprecated)"
: ""}
{this.state.showWidget ? (
<InlineIcon {...iconChevronDown} />
) : (
Expand Down
47 changes: 47 additions & 0 deletions packages/perseus-editor/src/widgets/numeric-input-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,55 @@ class NumericInputEditor extends React.Component<Props, State> {
lastStatus: "wrong",
showOptions: _.map(this.props.answers, () => false),
};
const upgradedProps = this.propsUpgrade(this.props); // quickhack for input number
this.props.onChange({props, ...upgradedProps}); // upgrade the props
}

// Temporary function to upgrade props from the deprecated
// InputNumber widget to the new NumericInput widget. This can be removed
// once the deprecated InputNumber widget is removed from our content. This should
// happen naturally as Content Editors re-save and publish their content.
// SIDE NOTE: Ooo interesting, I wonder if we could build a script to auto re-publish all content somehow.
propsUpgrade = (initialProps: any): PerseusNumericInputWidgetOptions => {
console.log(initialProps);

Check failure on line 134 in packages/perseus-editor/src/widgets/numeric-input-editor.tsx

View workflow job for this annotation

GitHub Actions / Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x)

Unexpected console statement
if (initialProps.value) {
console.log("Upgrading props for input-number");

Check failure on line 136 in packages/perseus-editor/src/widgets/numeric-input-editor.tsx

View workflow job for this annotation

GitHub Actions / Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x)

Unexpected console statement
let provideAnswerForm = true;
if (
initialProps.value !== "number" &&
initialProps.value !== "rational"
) {
provideAnswerForm = false;
}

const answers = [
{
value: initialProps.value,
simplify: initialProps.simplify,
answerForms: provideAnswerForm
? [initialProps.answerType]
: undefined,
strict: initialProps.inexact,
maxError: initialProps.maxError,
status: "correct", // Input-number only allows correct answers
message: "",
},
];

return {
answers,
size: initialProps.size,
coefficient: false, // input-number doesn't have a coefficient prop
labelText: "", // input-number doesn't have a labelText prop
static: false, // static is always false for numeric-input
};
} else {
// Otherwise simply return the initialProps as there's no differences
// between v0 and v1 for numeric-input
return initialProps;
}
};

change = (...args) => {
return Changeable.change.apply(this, args);
};
Expand Down
2 changes: 2 additions & 0 deletions packages/perseus/src/widgets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ export const replaceDeprecatedEditors = () => {
replaceEditor("sequence", "deprecated-standin");
replaceEditor("simulator", "deprecated-standin");
replaceEditor("unit-input", "deprecated-standin");

replaceEditor("input-number", "numeric-input");
};

export const getWidget = (
Expand Down

0 comments on commit c38dc8c

Please sign in to comment.