-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a function to get the public options for LabelImage (#2171)
Issue: LEMS-2769 ## Test plan: `yarn test` Author: benchristel Reviewers: Myranae, benchristel, handeyeco, jeremywiebe Required Reviewers: Approved By: Myranae Checks: ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Check builds for changes in size (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), ✅ Cypress (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x) Pull Request URL: #2171
- Loading branch information
1 parent
0a5599d
commit a470c79
Showing
6 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/perseus-core/src/widgets/label-image/label-image-util.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
41
packages/perseus-core/src/widgets/label-image/label-image-util.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters