Skip to content

Commit

Permalink
handle cases where analytics not available
Browse files Browse the repository at this point in the history
  • Loading branch information
nedredmond committed Sep 26, 2023
1 parent d9504cd commit 5033535
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/perseus/src/widgets/expression.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {ApiOptions, ClassNames as ApiClassNames} from "../perseus-api";
import a11y from "../util/a11y";
import KhanAnswerTypes from "../util/answer-types";

import type {DependenciesContext} from "../dependencies";
import type {
PerseusExpressionWidgetOptions,
PerseusExpressionAnswerForm,
Expand Down Expand Up @@ -83,7 +84,7 @@ type RenderProps = {
type ExternalProps = WidgetProps<RenderProps, Rubric>;

export type Props = ExternalProps &
ReturnType<typeof useDependencies> & {
Partial<React.ContextType<typeof DependenciesContext>> & {
apiOptions: NonNullable<ExternalProps["apiOptions"]>;
buttonSets: NonNullable<ExternalProps["buttonSets"]>;
functions: NonNullable<ExternalProps["functions"]>;
Expand Down Expand Up @@ -419,7 +420,7 @@ export class Expression extends React.Component<Props, ExpressionState> {
};

_handleFocus: () => void = () => {
this.props.analytics.onAnalyticsEvent({
this.props.analytics?.onAnalyticsEvent({
type: "perseus:expression-focused",
payload: null,
});
Expand Down Expand Up @@ -494,7 +495,7 @@ export class Expression extends React.Component<Props, ExpressionState> {
};

sendExpressionEvaluatedEvent(result: "correct" | "incorrect" | "invalid") {
this.props.analytics.onAnalyticsEvent({
this.props.analytics?.onAnalyticsEvent({
type: "perseus:expression-evaluated",
payload: {
result,
Expand Down Expand Up @@ -581,7 +582,11 @@ export class Expression extends React.Component<Props, ExpressionState> {
onBlur={this._handleBlur}
hasError={this.state.showErrorStyle}
extraKeys={this.props.keypadConfiguration?.extraKeys}
analytics={this.props.analytics}
analytics={
this.props.analytics ?? {
onAnalyticsEvent: async () => {},
}
}
/>
</Tooltip>
</div>
Expand Down

0 comments on commit 5033535

Please sign in to comment.