Skip to content

Commit

Permalink
[LEMS-2227-adjust-aphrodite-to-not-use-important] Merge branch 'main'…
Browse files Browse the repository at this point in the history
… into LEMS-2227-adjust-aphrodite-to-not-use-important
  • Loading branch information
mark-fitzgerald committed Jan 30, 2025
2 parents b047e3c + af8f5d3 commit 960e11d
Show file tree
Hide file tree
Showing 33 changed files with 581 additions and 57 deletions.
6 changes: 6 additions & 0 deletions .changeset/beige-glasses-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@khanacademy/perseus": minor
"@khanacademy/perseus-core": minor
---

Implement a widget export function to filter out rubric data from widget options for the Sorter widget
5 changes: 5 additions & 0 deletions .changeset/curly-bikes-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/kmath": patch
---

Update repository information
6 changes: 6 additions & 0 deletions .changeset/dry-fans-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@khanacademy/perseus-core": minor
"@khanacademy/perseus-editor": patch
---

Move default widget options for Grapher to Perseus Core
6 changes: 6 additions & 0 deletions .changeset/forty-meals-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@khanacademy/perseus": minor
"@khanacademy/perseus-core": minor
---

Create a function to get the public options for the LabelImage widget
6 changes: 6 additions & 0 deletions .changeset/honest-parents-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@khanacademy/perseus": minor
"@khanacademy/perseus-editor": minor
---

[Interactive Graph] Allow axis tick labels to be multiples of pi
5 changes: 5 additions & 0 deletions .changeset/poor-masks-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus": major
---

Removes the following deprecated exports from `@khanacademy/perseus`: `parsePerseusItem`, `parseAndMigratePerseusItem`, `parseAndMigratePerseusArticle`, `isSuccess`, `isFailure`, `Result`, `Success`, `Failure`. Clients should import these from `@khanacademy/perseus-core` instead.
6 changes: 6 additions & 0 deletions .changeset/twelve-spies-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@khanacademy/perseus": minor
"@khanacademy/perseus-core": minor
---

Implement a widget export function to filter out rubric data from widget options for the Dropdown widget
5 changes: 3 additions & 2 deletions packages/kmath/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
},
"repository": {
"type": "git",
"url": "https://github.com/Khan/kmath.git"
"url": "https://github.com/Khan/perseus.git",
"directory": "packages/kmath"
},
"bugs": {
"url": "https://github.com/Khan/perseus/issues"
Expand All @@ -35,4 +36,4 @@
"underscore": "1.4.4"
},
"keywords": []
}
}
5 changes: 5 additions & 0 deletions packages/perseus-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export {default as gradedGroupLogic} from "./widgets/graded-group";
export type {GradedGroupDefaultWidgetOptions} from "./widgets/graded-group";
export {default as gradedGroupSetLogic} from "./widgets/graded-group-set";
export type {GradedGroupSetDefaultWidgetOptions} from "./widgets/graded-group-set";
export {default as grapherLogic} from "./widgets/grapher";
export type {GrapherDefaultWidgetOptions} from "./widgets/grapher";
export {default as groupLogic} from "./widgets/group";
export type {GroupDefaultWidgetOptions} from "./widgets/group";
export {default as iframeLogic} from "./widgets/iframe";
Expand Down Expand Up @@ -115,3 +117,6 @@ export type * from "./widgets/logic-export.types";
export {default as getOrdererPublicWidgetOptions} from "./widgets/orderer/orderer-util";
export {default as getCategorizerPublicWidgetOptions} from "./widgets/categorizer/categorizer-util";
export {default as getExpressionPublicWidgetOptions} from "./widgets/expression/expression-util";
export {default as getLabelImagePublicWidgetOptions} from "./widgets/label-image/label-image-util";
export {default as getSorterPublicWidgetOptions} from "./widgets/sorter/sorter-util";
export {default as getDropdownPublicWidgetOptions} from "./widgets/dropdown/dropdown-util";
32 changes: 32 additions & 0 deletions packages/perseus-core/src/widgets/dropdown/dropdown-util.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import getDropdownPublicWidgetOptions from "./dropdown-util";

import type {PerseusDropdownWidgetOptions} from "../../data-schema";

describe("getDropdownPublicWidgetOptions", () => {
it("should return the correct public options without any answer data", () => {
// Arrange
const options: PerseusDropdownWidgetOptions = {
choices: [
{content: "1", correct: false},
{content: "2", correct: false},
{content: "3", correct: true},
],
placeholder: "Select an option",
static: false,
visibleLabel: "Test Label",
ariaLabel: "Test Aria Label",
};

// Act
const publicWidgetOptions = getDropdownPublicWidgetOptions(options);

// Assert
expect(publicWidgetOptions).toEqual({
choices: [{content: "1"}, {content: "2"}, {content: "3"}],
placeholder: "Select an option",
static: false,
visibleLabel: "Test Label",
ariaLabel: "Test Aria Label",
});
});
});
31 changes: 31 additions & 0 deletions packages/perseus-core/src/widgets/dropdown/dropdown-util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type {PerseusDropdownWidgetOptions} from "@khanacademy/perseus-core";

/**
* For details on the individual options, see the
* PerseusDropdownWidgetOptions type
*/
type DropdownPublicWidgetOptions = {
choices: ReadonlyArray<{content: string}>;
placeholder: PerseusDropdownWidgetOptions["placeholder"];
static: PerseusDropdownWidgetOptions["static"];
visibleLabel?: PerseusDropdownWidgetOptions["visibleLabel"];
ariaLabel?: PerseusDropdownWidgetOptions["ariaLabel"];
};

/**
* Given a PerseusDropdownWidgetOptions object, return a new object with only
* the public options that should be exposed to the client.
*/
function getDropdownPublicWidgetOptions(
options: PerseusDropdownWidgetOptions,
): DropdownPublicWidgetOptions {
return {
choices: options.choices.map((choice) => ({content: choice.content})),
placeholder: options.placeholder,
static: options.static,
visibleLabel: options.visibleLabel,
ariaLabel: options.ariaLabel,
};
}

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

export type GrapherDefaultWidgetOptions = Pick<
PerseusGrapherWidgetOptions,
"graph" | "correct" | "availableTypes"
>;

const defaultWidgetOptions: GrapherDefaultWidgetOptions = {
graph: {
labels: ["x", "y"],
range: [
[-10, 10],
[-10, 10],
],
step: [1, 1],
backgroundImage: {
url: null,
},
markings: "graph",
rulerLabel: "",
rulerTicks: 10,
valid: true,
showTooltips: false,
},
correct: {
type: "linear",
coords: null,
},
availableTypes: ["linear"],
};

const grapherWidgetLogic: WidgetLogic = {
name: "grapher",
defaultWidgetOptions,
};

export default grapherWidgetLogic;
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import getLabelImagePublicWidgetOptions from "./label-image-util";

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

describe("getLabelImagePublicWidgetOptions", () => {
it("removes private fields", () => {
const options: PerseusLabelImageWidgetOptions = {
choices: ["right", "wrong"],
markers: [
{
answers: ["right"],
label: "",
x: 0,
y: 0,
},
],
imageUrl: "",
imageHeight: 0,
imageWidth: 0,
imageAlt: "",
hideChoicesFromInstructions: false,
multipleAnswers: false,
static: false,
};

const publicWidgetOptions = getLabelImagePublicWidgetOptions(options);

expect(publicWidgetOptions).toEqual({
choices: ["right", "wrong"],
markers: [
{
label: "",
x: 0,
y: 0,
},
],
imageUrl: "",
imageHeight: 0,
imageWidth: 0,
imageAlt: "",
hideChoicesFromInstructions: false,
multipleAnswers: false,
static: false,
});
});
});
41 changes: 41 additions & 0 deletions packages/perseus-core/src/widgets/label-image/label-image-util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import type {
PerseusLabelImageMarker,
PerseusLabelImageWidgetOptions,
} from "@khanacademy/perseus-core";

/**
* For details on the individual options, see the
* PerseusLabelImageWidgetOptions type
*/
type LabelImagePublicWidgetOptions = {
choices: PerseusLabelImageWidgetOptions["choices"];
imageUrl: PerseusLabelImageWidgetOptions["imageUrl"];
imageAlt: PerseusLabelImageWidgetOptions["imageAlt"];
imageHeight: PerseusLabelImageWidgetOptions["imageHeight"];
imageWidth: PerseusLabelImageWidgetOptions["imageWidth"];
markers: ReadonlyArray<LabelImageMarkerPublicData>;
hideChoicesFromInstructions: PerseusLabelImageWidgetOptions["hideChoicesFromInstructions"];
multipleAnswers: PerseusLabelImageWidgetOptions["multipleAnswers"];
static: PerseusLabelImageWidgetOptions["static"];
};

type LabelImageMarkerPublicData = Pick<
PerseusLabelImageMarker,
"x" | "y" | "label"
>;

export default function getLabelImagePublicWidgetOptions(
options: PerseusLabelImageWidgetOptions,
): LabelImagePublicWidgetOptions {
return {
...options,
markers: options.markers.map(getLabelImageMarkerPublicData),
};
}

function getLabelImageMarkerPublicData(
marker: PerseusLabelImageMarker,
): LabelImageMarkerPublicData {
const {answers: _, ...publicData} = marker;
return publicData;
}
24 changes: 24 additions & 0 deletions packages/perseus-core/src/widgets/sorter/sorter-util.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import getSorterPublicWidgetOptions from "./sorter-util";

import type {PerseusSorterWidgetOptions} from "../../data-schema";

describe("getSorterPublicWidgetOptions", () => {
it("should return the correct public options without any answer data", () => {
// Arrange
const options: PerseusSorterWidgetOptions = {
correct: ["$15$ grams", "$55$ grams", "$0.005$ kilograms"],
layout: "horizontal",
padding: true,
};

// Act
const publicWidgetOptions = getSorterPublicWidgetOptions(options);

// Assert
expect(publicWidgetOptions).toEqual({
correct: ["$0.005$ kilograms", "$15$ grams", "$55$ grams"],
layout: "horizontal",
padding: true,
});
});
});
30 changes: 30 additions & 0 deletions packages/perseus-core/src/widgets/sorter/sorter-util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type {PerseusSorterWidgetOptions} from "@khanacademy/perseus-core";

/**
* For details on the individual options, see the
* PerseusSorterWidgetOptions type
*/
type SorterPublicWidgetOptions = {
correct: PerseusSorterWidgetOptions["correct"];
padding: PerseusSorterWidgetOptions["padding"];
layout: PerseusSorterWidgetOptions["layout"];
};

/**
* Given a PerseusSorterWidgetOptions object, return a new object with only
* the public options that should be exposed to the client.
*/
function getSorterPublicWidgetOptions(
options: PerseusSorterWidgetOptions,
): SorterPublicWidgetOptions {
return {
// Note(Tamara): This does not provide correct answer information any longer.
// To maintain compatibility with the original widget options, we are
// keeping the key the same. Represents initial state of the cards here.
correct: options.correct.slice().sort(),
padding: options.padding,
layout: options.layout,
};
}

export default getSorterPublicWidgetOptions;
23 changes: 10 additions & 13 deletions packages/perseus-editor/src/widgets/grapher-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ import {
containerSizeClass,
getInteractiveBoxFromSizeClass,
} from "@khanacademy/perseus";
import {GrapherUtil as CoreGrapherUtil} from "@khanacademy/perseus-core";
import {
GrapherUtil as CoreGrapherUtil,
grapherLogic,
} from "@khanacademy/perseus-core";
import * as React from "react";
import _ from "underscore";

import GraphSettings from "../components/graph-settings";

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

const {InfoTip, MultiButtonGroup} = components;
const Grapher = GrapherWidget.widget;
const {
DEFAULT_GRAPHER_PROPS,
chooseType,
defaultPlotProps,
getEquationString,
typeToButton,
} = GrapherUtil;
const {chooseType, defaultPlotProps, getEquationString, typeToButton} =
GrapherUtil;

type Props = any;

Expand All @@ -32,11 +32,8 @@ class GrapherEditor extends React.Component<Props> {

static widgetName = "grapher" as const;

static defaultProps: Props = {
correct: DEFAULT_GRAPHER_PROPS.plot,
graph: DEFAULT_GRAPHER_PROPS.graph,
availableTypes: DEFAULT_GRAPHER_PROPS.availableTypes,
};
static defaultProps: GrapherDefaultWidgetOptions =
grapherLogic.defaultWidgetOptions;

change: (arg1: any, arg2: any, arg3: any) => any = (...args) => {
return Changeable.change.apply(this, args);
Expand Down
Loading

0 comments on commit 960e11d

Please sign in to comment.