Skip to content

Commit

Permalink
Simplify passing onAnalyticsEvent - to help Storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremywiebe committed Oct 25, 2024
1 parent 35bcb77 commit 2b550b1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
18 changes: 9 additions & 9 deletions packages/perseus/src/components/__tests__/math-input.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe("Perseus' MathInput", () => {
<MathInput
onChange={() => {}}
keypadButtonSets={allButtonSets}
analytics={{onAnalyticsEvent: () => Promise.resolve()}}
onAnalyticsEvent={() => Promise.resolve()}
convertDotToTimes={false}
value=""
/>,
Expand All @@ -55,7 +55,7 @@ describe("Perseus' MathInput", () => {
<MathInput
onChange={() => {}}
keypadButtonSets={allButtonSets}
analytics={{onAnalyticsEvent: () => Promise.resolve()}}
onAnalyticsEvent={() => Promise.resolve()}
convertDotToTimes={false}
value=""
/>,
Expand All @@ -74,7 +74,7 @@ describe("Perseus' MathInput", () => {
<MathInput
onChange={() => {}}
keypadButtonSets={allButtonSets}
analytics={{onAnalyticsEvent: () => Promise.resolve()}}
onAnalyticsEvent={() => Promise.resolve()}
convertDotToTimes={false}
value=""
ariaLabel="Hello world"
Expand All @@ -95,7 +95,7 @@ describe("Perseus' MathInput", () => {
<MathInput
onChange={mockOnChange}
keypadButtonSets={allButtonSets}
analytics={{onAnalyticsEvent: () => Promise.resolve()}}
onAnalyticsEvent={() => Promise.resolve()}
convertDotToTimes={false}
value=""
/>,
Expand All @@ -120,7 +120,7 @@ describe("Perseus' MathInput", () => {
<MathInput
onChange={mockOnChange}
keypadButtonSets={allButtonSets}
analytics={{onAnalyticsEvent: () => Promise.resolve()}}
onAnalyticsEvent={() => Promise.resolve()}
convertDotToTimes={false}
value=""
/>,
Expand Down Expand Up @@ -149,7 +149,7 @@ describe("Perseus' MathInput", () => {
<MathInput
onChange={mockOnChange}
buttonSets={["basic+div"]}
analytics={{onAnalyticsEvent: () => Promise.resolve()}}
onAnalyticsEvent={() => Promise.resolve()}
convertDotToTimes={false}
value=""
/>,
Expand Down Expand Up @@ -178,7 +178,7 @@ describe("Perseus' MathInput", () => {
<MathInput
onChange={() => {}}
keypadButtonSets={allButtonSets}
analytics={{onAnalyticsEvent: () => Promise.resolve()}}
onAnalyticsEvent={() => Promise.resolve()}
convertDotToTimes={false}
value=""
/>,
Expand All @@ -202,7 +202,7 @@ describe("Perseus' MathInput", () => {
<MathInput
onChange={() => {}}
keypadButtonSets={allButtonSets}
analytics={{onAnalyticsEvent: () => Promise.resolve()}}
onAnalyticsEvent={() => Promise.resolve()}
convertDotToTimes={false}
value=""
/>,
Expand Down Expand Up @@ -231,7 +231,7 @@ describe("Perseus' MathInput", () => {
<MathInput
onChange={() => {}}
buttonsVisible="always"
analytics={{onAnalyticsEvent: () => Promise.resolve()}}
onAnalyticsEvent={() => Promise.resolve()}
convertDotToTimes={false}
value=""
/>,
Expand Down
6 changes: 3 additions & 3 deletions packages/perseus/src/components/math-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {PerseusI18nContext} from "./i18n-context";
import type {LegacyButtonSets} from "../perseus-types";
import type {PerseusDependenciesV2} from "../types";

Check failure on line 30 in packages/perseus/src/components/math-input.tsx

View workflow job for this annotation

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

'PerseusDependenciesV2' is defined but never used. Allowed unused vars must match /^_*$/u
import type {Keys, MathFieldInterface} from "@khanacademy/math-input";
import type {AnalyticsEventHandlerFn} from "@khanacademy/perseus-core";

type ButtonsVisibleType = "always" | "never" | "focused";

Expand Down Expand Up @@ -68,7 +69,7 @@ type Props = {
* - `never` means that the keypad is **never shown**.
*/
buttonsVisible?: ButtonsVisibleType;
analytics: PerseusDependenciesV2["analytics"];
onAnalyticsEvent: AnalyticsEventHandlerFn;
};

type InnerProps = Props & {
Expand Down Expand Up @@ -352,8 +353,7 @@ class InnerMathInput extends React.Component<InnerProps, State> {
>
<DesktopKeypad
onAnalyticsEvent={
this.props.analytics
.onAnalyticsEvent
this.props.onAnalyticsEvent
}
extraKeys={this.props.extraKeys}
onClickKey={this.handleKeypadPress}
Expand Down
4 changes: 2 additions & 2 deletions packages/perseus/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,9 @@ export type PerseusDependencies = {
*
* Prefer using this type over `PerseusDependencies` when possible.
*/
export type PerseusDependenciesV2 = {
export interface PerseusDependenciesV2 {
analytics: {onAnalyticsEvent: AnalyticsEventHandlerFn};
};
}

/**
* APIOptionsWithDefaults represents the type that is provided to all widgets.
Expand Down
7 changes: 3 additions & 4 deletions packages/perseus/src/widgets/expression/expression.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,9 @@ export class Expression
extraKeys={
this.props.keypadConfiguration?.extraKeys
}
analytics={
this.props.analytics ?? {
onAnalyticsEvent: async () => {},
}
onAnalyticsEvent={
this.props.analytics?.onAnalyticsEvent ??
(async () => {})
}
/>
</Tooltip>
Expand Down

0 comments on commit 2b550b1

Please sign in to comment.