Skip to content

Commit ea7ede6

Browse files
authored
Knip 12: widget option refinement (#1782)
## Summary: `PerseusSequenceWidgetOptions` and `PerseusSimulatorWidgetOptions` are obsolete due to the deprecated stand-in. LabelImage and Measurer weren't using their widget options type, but I think they should be (the other widgets do). Author: handeyeco Reviewers: jeremywiebe, benchristel, handeyeco Required Reviewers: Approved By: jeremywiebe, benchristel Checks: ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ gerald Pull Request URL: #1782
1 parent f220366 commit ea7ede6

File tree

4 files changed

+20
-48
lines changed

4 files changed

+20
-48
lines changed

.changeset/honest-geckos-brush.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@khanacademy/perseus": patch
3+
---
4+
5+
Cleanup widget option types

packages/perseus/src/perseus-types.ts

+1-19
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ export type PerseusMeasurerWidgetOptions = {
986986
// The number of units to display on the ruler
987987
rulerLength: number;
988988
// Containing area [width, height]
989-
box: ReadonlyArray<number>;
989+
box: [number, number];
990990
// Always false. Not used for this widget
991991
static: boolean;
992992
};
@@ -1200,24 +1200,6 @@ export type PerseusRadioChoice = {
12001200
widgets?: PerseusWidgetsMap;
12011201
};
12021202

1203-
export type PerseusSequenceWidgetOptions = {
1204-
// A list of Renderers to display in sequence
1205-
json: ReadonlyArray<PerseusRenderer>;
1206-
};
1207-
1208-
export type PerseusSimulatorWidgetOptions = {
1209-
// Translatable Text; The X Axis
1210-
xAxisLabel: string;
1211-
// Translatable Text; The Y Axis
1212-
yAxisLabel: string;
1213-
// Translatable Text; A lable to define the proportion of the simulation
1214-
proportionLabel: string;
1215-
// The type of simulation. options: "proportion", "percentage"
1216-
proportionOrPercentage: string;
1217-
// The number of times to run the simulation
1218-
numTrials: number;
1219-
};
1220-
12211203
export type PerseusSorterWidgetOptions = {
12221204
// Translatable Text; The correct answer (in the correct order). The user will see the cards in a randomized order.
12231205
correct: ReadonlyArray<string>;

packages/perseus/src/widgets/label-image/label-image.tsx

+5-13
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import Marker from "./marker";
2929
import type {InteractiveMarkerType} from "./types";
3030
import type {DependencyProps} from "../../dependencies";
3131
import type {ChangeableProps} from "../../mixins/changeable";
32+
import type {PerseusLabelImageWidgetOptions} from "../../perseus-types";
3233
import type {APIOptions, Widget, WidgetExports} from "../../types";
3334
import type {
3435
PerseusLabelImageRubric,
@@ -67,23 +68,14 @@ type Point = {
6768
y: number;
6869
};
6970

70-
// TODO: should this be using WidgetProps / PerseusLabelImageWidgetOptions?
7171
type LabelImageProps = ChangeableProps &
72-
DependencyProps & {
72+
DependencyProps &
73+
// TODO: there's some weirdness in our types between
74+
// PerseusLabelImageMarker and InteractiveMarkerType
75+
Omit<PerseusLabelImageWidgetOptions, "markers"> & {
7376
apiOptions: APIOptions;
74-
// The list of possible answer choices.
75-
choices: ReadonlyArray<string>;
76-
// The question image properties.
77-
imageAlt: string;
78-
imageUrl: string;
79-
imageWidth: number;
80-
imageHeight: number;
8177
// The list of label markers on the question image.
8278
markers: ReadonlyArray<InteractiveMarkerType>;
83-
// Whether multiple answer choices may be selected for markers.
84-
multipleAnswers: boolean;
85-
// Whether to hide answer choices from user instructions.
86-
hideChoicesFromInstructions: boolean;
8779
// Whether the question has been answered by the user.
8880
questionCompleted: boolean;
8981
// preferred placement for popover (preference, not MUST)

packages/perseus/src/widgets/measurer/measurer.tsx

+9-16
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import GraphUtils from "../../util/graph-utils";
88
import noopValidator from "../__shared__/noop-validator";
99

1010
import type {Coord} from "../../interactive2/types";
11-
import type {APIOptions, Widget, WidgetExports} from "../../types";
11+
import type {PerseusMeasurerWidgetOptions} from "../../perseus-types";
12+
import type {Widget, WidgetExports, WidgetProps} from "../../types";
1213
import type {Interval} from "../../util/interval";
1314

1415
const defaultImage = {
@@ -17,22 +18,14 @@ const defaultImage = {
1718
left: 0,
1819
} as const;
1920

20-
type Props = {
21-
apiOptions: APIOptions;
22-
box: [number, number];
23-
image: {
24-
url?: string;
25-
top?: number;
26-
left?: number;
27-
};
28-
showProtractor: boolean;
21+
type Props = WidgetProps<
22+
PerseusMeasurerWidgetOptions,
23+
PerseusMeasurerWidgetOptions
24+
> & {
25+
// TODO: these don't show up anywhere else in code
26+
// I'm guessing they could just be constants
2927
protractorX: number;
3028
protractorY: number;
31-
showRuler: boolean;
32-
rulerLabel: string;
33-
rulerTicks: number;
34-
rulerPixels: number;
35-
rulerLength: number;
3629
};
3730

3831
type DefaultProps = {
@@ -51,7 +44,7 @@ type DefaultProps = {
5144
class Measurer extends React.Component<Props> implements Widget {
5245
static defaultProps: DefaultProps = {
5346
box: [480, 480],
54-
image: {},
47+
image: defaultImage,
5548
showProtractor: true,
5649
protractorX: 7.5,
5750
protractorY: 0.5,

0 commit comments

Comments
 (0)