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

Create helper to build public widget options for Matcher #2156

Open
wants to merge 53 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
7560a59
[tb/LEMS-2761/matcher-split] (wip) Add function to get public widget …
Myranae Jan 24, 2025
12bfcf1
[tb/LEMS-2761/matcher-split] Add test for the new function
Myranae Jan 24, 2025
30c9a44
[tb/LEMS-2761/matcher-split] Export function from perseus-core
Myranae Jan 24, 2025
9c3960a
[tb/LEMS-2761/matcher-split] Add function to union type for all publi…
Myranae Jan 24, 2025
844eb7f
[tb/LEMS-2761/matcher-split] Add to matcher's widget export
Myranae Jan 24, 2025
7957294
[tb/LEMS-2761/matcher-split] docs(changeset): Implement a widget expo…
Myranae Jan 24, 2025
0ef061c
[tb/LEMS-2761/matcher-split] Update test, type, and function to shuff…
Myranae Jan 24, 2025
4d36168
[tb/LEMS-2761/matcher-split] Change from a shuffle to a sort
Myranae Jan 24, 2025
bc4c368
[tb/LEMS-2761/matcher-split] Merge branch 'main' into tb/LEMS-2761/ma…
Myranae Jan 24, 2025
042be9e
[tb/LEMS-2761/matcher-split] Update test for sorted information
Myranae Jan 24, 2025
197fa17
[tb/LEMS-2761/matcher-split] Remove unneeded comments
Myranae Jan 24, 2025
95cfb9f
[tb/LEMS-2761/matcher-split] Shorten test data
Myranae Jan 28, 2025
d0cb74a
[tb/LEMS-2761/matcher-split] Merge branch 'main' into tb/LEMS-2761/ma…
Myranae Jan 28, 2025
1bd5449
[tb/LEMS-2761/matcher-split] Update types to match widget options
Myranae Jan 28, 2025
74593a1
[tb/LEMS-2761/matcher-split] Move shuffle, seededRNG, and random to p…
Myranae Jan 29, 2025
e9a035f
[tb/LEMS-2761/matcher-split] Update CoreUtil export and usage
Myranae Jan 29, 2025
7495493
[tb/LEMS-2761/matcher-split] Move matcher shuffle logic to helper
Myranae Jan 30, 2025
0723456
[tb/LEMS-2761/matcher-split] Apply matcherShuffle to public options f…
Myranae Jan 30, 2025
9d5c7be
[tb/LEMS-2761/matcher-split] Update spelling
Myranae Jan 30, 2025
8b39196
[tb/LEMS-2761/matcher-split] Merge branch 'main' into tb/LEMS-2761/ma…
Myranae Jan 30, 2025
31aa314
[tb/LEMS-2761/matcher-split] Merge branch 'main' into tb/LEMS-2761/ma…
Myranae Jan 30, 2025
9611f13
[tb/LEMS-2761/matcher-split] Merge branch 'main' into tb/LEMS-2761/ma…
Myranae Feb 3, 2025
771e1e4
[tb/LEMS-2761/matcher-split] Add note to update Matcher to not shuffl…
Myranae Feb 6, 2025
a84d9a1
[tb/LEMS-2761/matcher-split] Update TODO with ticket
Myranae Feb 6, 2025
328283e
[tb/LEMS-2761/matcher-split] Add TODOs
Myranae Feb 6, 2025
b04bf7b
[tb/LEMS-2761/matcher-split] Simplify return by spreading options
Myranae Feb 6, 2025
3022ba3
[tb/LEMS-2761/matcher-split] Add new type for new shuffling logic
Myranae Feb 6, 2025
139bd8a
[tb/LEMS-2761/matcher-split] Add open source hash function and seed f…
Myranae Feb 6, 2025
7678039
[tb/LEMS-2761/matcher-split] Add matcher shuffle that uses new seed
Myranae Feb 6, 2025
0168779
[tb/LEMS-2761/matcher-split] Update getPublicOptions with hashed shuffle
Myranae Feb 6, 2025
c4e8b82
[tb/LEMS-2761/matcher-split] Update test with new shuffle and more ex…
Myranae Feb 6, 2025
9360065
[tb/LEMS-2761/matcher-split] Merge branch 'main' into tb/LEMS-2761/ma…
Myranae Feb 6, 2025
1f1abe7
[tb/LEMS-2761/matcher-split] Update comment
Myranae Feb 6, 2025
fa1b3aa
[tb/LEMS-2761/matcher-split] Merge branch 'main' into tb/LEMS-2761/ma…
Myranae Feb 7, 2025
3185b4c
[tb/LEMS-2761/matcher-split] Merge branch 'main' into tb/LEMS-2761/ma…
Myranae Feb 7, 2025
6c336b2
[tb/LEMS-2761/matcher-split] Rename file and update comment
Myranae Feb 7, 2025
5a259bd
[tb/LEMS-2761/matcher-split] Put left info before right info in test …
Myranae Feb 7, 2025
de79348
[tb/LEMS-2761/matcher-split] Be more specific with test names
Myranae Feb 7, 2025
7f26be1
[tb/LEMS-2761/matcher-split] Rename to avoid yoda speak
Myranae Feb 7, 2025
aea4ca3
[tb/LEMS-2761/matcher-split] Update comments to jsDoc comments with r…
Myranae Feb 7, 2025
53e37e8
[tb/LEMS-2761/matcher-split] Reorder a type import
Myranae Feb 7, 2025
7ceca4b
[tb/LEMS-2761/matcher-split] Cast to any to remove ts-expect-error st…
Myranae Feb 7, 2025
bea7618
[tb/LEMS-2761/matcher-split] Put left above right again; missed a test
Myranae Feb 7, 2025
7c7c080
[tb/LEMS-2761/matcher-split] Fix format
Myranae Feb 7, 2025
46cd80b
[tb/LEMS-2761/matcher-split] Rename functions based on PR feedback
Myranae Feb 7, 2025
e67b285
[tb/LEMS-2761/matcher-split] Update to JSON.stringify to ensure diffe…
Myranae Feb 7, 2025
3cc37c3
[tb/LEMS-2761/matcher-split] Make comment even more specific
Myranae Feb 7, 2025
182e458
[tb/LEMS-2761/matcher-split] Remove negative in test name and be more…
Myranae Feb 7, 2025
8266eac
[tb/LEMS-2761/matcher-split] Merge branch 'main' into tb/LEMS-2761/ma…
Myranae Feb 7, 2025
32ae1e4
[tb/LEMS-2761/matcher-split] Fix spelling and filename in note
Myranae Feb 10, 2025
53d7fd7
[tb/LEMS-2761/matcher-split] Update shuffle to use Math.random instea…
Myranae Feb 10, 2025
682a039
[tb/LEMS-2761/matcher-split] Commit package manager update
Myranae Feb 10, 2025
3e1a5f2
[tb/LEMS-2761/matcher-split] Update order of columns in test
Myranae Feb 10, 2025
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
6 changes: 6 additions & 0 deletions .changeset/tricky-hairs-grin.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 Matcher widget
1 change: 1 addition & 0 deletions packages/perseus-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,4 @@ 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 getMatcherPublicWidgetOptions} from "./widgets/matcher/matcher-util";
52 changes: 52 additions & 0 deletions packages/perseus-core/src/widgets/matcher/matcher-util.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import getMatcherPublicWidgetOptions from "./matcher-util";

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

describe("getMatcherPublicWidgetOptions", () => {
it("should return left and right arrays with sorted items to remove correct order information", () => {
// Arrange
const options: PerseusMatcherWidgetOptions = {
labels: ["**Claims**", "**Evidence**"],
padding: true,
orderMatters: false,
right: [
"Medium-sized stars typically exist for roughly 10 billion years",
"The current trajectory of the Earth\u2019s tectonic plate movement",
"The life cycle of medium-sized stars includes a red giant stage and ends in a whimper as a white dwarf",
"Rapid escalation of greenhouse gas emissions",
"The current trajectory of the Milky Way galaxy and those in its immediate proximity",
],
left: [
"Our Sun will run out of fuel and die in around 5 billion years ",
"Plate tectonics will rearrange the continents: the Pacific will narrow, bringing Australia closer to the Americas, and the Atlantic will expand to form the largest of the oceans ",
"Our Sun will run out of hydrogen, swell into a red giant, gobble up the inner rocky planets, and then collapse and die ",
"Average global temperatures will rise ",
"In 3 to 4 billion years, our galaxy will begin a slow collision with its closest large neighbor, Andromeda ",
Myranae marked this conversation as resolved.
Show resolved Hide resolved
],
};

// Act
const publicWidgetOptions = getMatcherPublicWidgetOptions(options);

// Assert
expect(publicWidgetOptions).toEqual({
labels: ["**Claims**", "**Evidence**"],
padding: true,
orderMatters: false,
right: [
"Medium-sized stars typically exist for roughly 10 billion years",
"Rapid escalation of greenhouse gas emissions",
"The current trajectory of the Earth\u2019s tectonic plate movement",
"The current trajectory of the Milky Way galaxy and those in its immediate proximity",
"The life cycle of medium-sized stars includes a red giant stage and ends in a whimper as a white dwarf",
],
left: [
"Average global temperatures will rise ",
"In 3 to 4 billion years, our galaxy will begin a slow collision with its closest large neighbor, Andromeda ",
"Our Sun will run out of fuel and die in around 5 billion years ",
"Our Sun will run out of hydrogen, swell into a red giant, gobble up the inner rocky planets, and then collapse and die ",
"Plate tectonics will rearrange the continents: the Pacific will narrow, bringing Australia closer to the Americas, and the Atlantic will expand to form the largest of the oceans ",
],
});
});
});
31 changes: 31 additions & 0 deletions packages/perseus-core/src/widgets/matcher/matcher-util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type {PerseusMatcherWidgetOptions} from "@khanacademy/perseus-core";

/**
* For details on the individual options, see the
* PerseusMatcherWidgetOptions type
*/
type MatcherPublicWidgetOptions = {
labels: PerseusMatcherWidgetOptions["labels"];
left: Array<string>; // First column that is usually static, but could be movable
right: Array<string>; // Second column that appears to be always movable
orderMatters: PerseusMatcherWidgetOptions["orderMatters"]; // when this is on, both columns are dynamic and the order of the pairs in the list matters
padding: PerseusMatcherWidgetOptions["padding"];
};

/**
* Given a PerseusMatcherWidgetOptions object, return a new object with only
* the public options that should be exposed to the client.
*/
function getMatcherPublicWidgetOptions(
options: PerseusMatcherWidgetOptions,
): MatcherPublicWidgetOptions {
return {
labels: options.labels,
left: options.left.slice().sort(),
right: options.right.slice().sort(),
Myranae marked this conversation as resolved.
Show resolved Hide resolved
orderMatters: options.orderMatters,
padding: options.padding,
};
}

export default getMatcherPublicWidgetOptions;
2 changes: 2 additions & 0 deletions packages/perseus/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
getOrdererPublicWidgetOptions,
getCategorizerPublicWidgetOptions,
getExpressionPublicWidgetOptions,
getMatcherPublicWidgetOptions,
} from "@khanacademy/perseus-core";
import type {LinterContextProps} from "@khanacademy/perseus-linter";
import type {
Expand Down Expand Up @@ -541,6 +542,7 @@ export type WidgetScorerFunction = (
* A union type of all the functions that provide public widget options.
*/
export type PublicWidgetOptionsFunction =
| typeof getMatcherPublicWidgetOptions
| typeof getCategorizerPublicWidgetOptions
| typeof getOrdererPublicWidgetOptions
| typeof getExpressionPublicWidgetOptions;
Expand Down
2 changes: 2 additions & 0 deletions packages/perseus/src/widgets/matcher/matcher.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {getMatcherPublicWidgetOptions} from "@khanacademy/perseus-core";
import {linterContextDefault} from "@khanacademy/perseus-linter";
import {scoreMatcher} from "@khanacademy/perseus-score";
import {CircularSpinner} from "@khanacademy/wonder-blocks-progress-spinner";
Expand Down Expand Up @@ -290,4 +291,5 @@ export default {
// TODO(LEMS-2656): remove TS suppression
// @ts-expect-error: Type 'UserInput' is not assignable to type 'PerseusMatcherUserInput'.
scorer: scoreMatcher,
getPublicWidgetOptions: getMatcherPublicWidgetOptions,
} satisfies WidgetExports<typeof Matcher>;
Loading