Skip to content

Commit

Permalink
Remove getGrammarTypeForPath (#1740)
Browse files Browse the repository at this point in the history
## Summary:
Pretty sure based on the comments, [searching for uses](https://github.com/search?q=org%3AKhan%20getGrammarTypeForPath&type=code), and [this message](https://khanacademy.slack.com/archives/C02NN49RF/p1627234916002000) that this is just dead code.

Author: handeyeco

Reviewers: benchristel, jeremywiebe, Myranae

Required Reviewers:

Approved By: benchristel

Checks: ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ gerald, 🚫 Publish npm snapshot (ubuntu-latest, 20.x), 🚫 Check builds for changes in size (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), 🚫 Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ gerald

Pull Request URL: #1740
  • Loading branch information
handeyeco authored Oct 23, 2024
1 parent 236ef44 commit c6ee266
Show file tree
Hide file tree
Showing 12 changed files with 5 additions and 87 deletions.
5 changes: 5 additions & 0 deletions .changeset/tough-socks-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus": major
---

Remove external-facing but unused API (getGrammarTypeForPath)
26 changes: 0 additions & 26 deletions packages/perseus/src/__tests__/renderer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1509,32 +1509,6 @@ describe("renderer", () => {
});
});

describe("getGrammarTypeForPath", () => {
it("should return undefined if matching widget doesn't implement getGrammarTypeForPath", () => {
// Arrange
const {renderer} = renderQuestion(question1);

// Act
const grammarType = renderer.getGrammarTypeForPath(["dropdown 1"]);

// Assert
expect(grammarType).toBeUndefined();
});

it("should return widget result if matching widget implements getGrammarTypeForPath", () => {
// Arrange
const {renderer} = renderQuestion(question2);

// Act
const grammarType = renderer.getGrammarTypeForPath([
"input-number 1",
]);

// Assert
expect(grammarType).toBe("number");
});
});

describe("getInputPaths", () => {
it("should return all input paths for all rendererd widgets", () => {
// Arrange
Expand Down
11 changes: 0 additions & 11 deletions packages/perseus/src/__tests__/server-item-renderer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,6 @@ describe("server item renderer", () => {
expect(await within(node).findAllByRole("textbox")).toHaveLength(1);
});

it("should return the grammar type for the requested focus path", () => {
// Arrange
const {renderer} = renderQuestion(itemWithInput);

// Act
const grammarType = renderer.getGrammarTypeForPath(["input-number 1"]);

// Assert
expect(grammarType).toBe("number");
});

it("should return the number of hints available", () => {
// Arrange
const {renderer} = renderQuestion({
Expand Down
12 changes: 0 additions & 12 deletions packages/perseus/src/renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1503,18 +1503,6 @@ class Renderer extends React.Component<Props, State> {
}
};

getGrammarTypeForPath: (path: FocusPath) => string | undefined = (
path: FocusPath,
) => {
// @ts-expect-error - TS2345 - Argument of type 'FocusPath' is not assignable to parameter of type 'List<any>'.
const widgetId = _.first(path);
// @ts-expect-error - TS2345 - Argument of type 'FocusPath' is not assignable to parameter of type 'List<any>'.
const interWidgetPath = _.rest(path);

const widget = this.getWidgetInstance(widgetId);
return widget?.getGrammarTypeForPath?.(interWidgetPath);
};

getInputPaths: () => ReadonlyArray<FocusPath> = () => {
const inputPaths: Array<FocusPath> = [];
_.each(this.widgetIds, (widgetId: string) => {
Expand Down
4 changes: 0 additions & 4 deletions packages/perseus/src/server-item-renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,6 @@ export class ServerItemRenderer
return this.questionRenderer.getDOMNodeForPath(path);
}

getGrammarTypeForPath(path: FocusPath): string | null | undefined {
return this.questionRenderer.getGrammarTypeForPath(path);
}

getInputPaths(): ReadonlyArray<FocusPath> {
const questionAreaInputPaths = this.questionRenderer.getInputPaths();
return questionAreaInputPaths;
Expand Down
2 changes: 0 additions & 2 deletions packages/perseus/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ export interface Widget {
getSerializedState?: () => SerializedState; // SUSPECT,
restoreSerializedState?: (props: any, callback: () => void) => any;

getGrammarTypeForPath?: (path: FocusPath) => string | undefined;

blurInputPath?: (path: FocusPath) => void;
focusInputPath?: (path: FocusPath) => void;
getInputPaths?: () => ReadonlyArray<FocusPath>;
Expand Down
6 changes: 0 additions & 6 deletions packages/perseus/src/widgets/expression/expression.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,6 @@ export class Expression
return [[]];
};

// TODO(Nicole): I believe this is going away and won't be needed anymore
getGrammarTypeForPath(inputPath: FocusPath): string {
/* c8 ignore next */
return "expression";
}

setInputValue(path: FocusPath, newValue: string, cb: () => void) {
this.props.onChange(
{
Expand Down
7 changes: 0 additions & 7 deletions packages/perseus/src/widgets/input-number/input-number.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,6 @@ class InputNumber extends React.Component<Props> implements Widget {
return [[]];
};

// Note: We believe that this isn't used anywhere but are leaving it during
// the initial refactor
getGrammarTypeForPath: (arg1: Path) => string = (path) => {
/* c8 ignore next */
return "number";
};

setInputValue: (arg1: Path, arg2: string, arg3: () => void) => void = (
path,
newValue,
Expand Down
4 changes: 0 additions & 4 deletions packages/perseus/src/widgets/matrix/matrix.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,6 @@ class Matrix extends React.Component<Props, State> implements Widget {
return inputPaths;
};

getGrammarTypeForPath: (arg1: any) => string = (inputPath) => {
return "number";
};

_handleFocus: (arg1: any, arg2: any) => void = (row, col) => {
this.props.onFocus(getInputPath(row, col));
};
Expand Down
6 changes: 0 additions & 6 deletions packages/perseus/src/widgets/number-line/number-line.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -374,12 +374,6 @@ class NumberLine extends React.Component<Props, State> implements Widget {
return null;
}

getGrammarTypeForPath(inputPath: FocusPath) {
if (inputPath?.length === 1 && inputPath[0] === "tick-ctrl") {
return "number";
}
}

setInputValue: (arg1: any, arg2: any, arg3: any) => void = (
inputPath,
value,
Expand Down
5 changes: 0 additions & 5 deletions packages/perseus/src/widgets/numeric-input/numeric-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,6 @@ export class NumericInput
return [[]];
};

getGrammarTypeForPath: (arg1: FocusPath) => string = (inputPath) => {
/* c8 ignore next */
return "number";
};

setInputValue: (
arg1: FocusPath,
arg2: string,
Expand Down
4 changes: 0 additions & 4 deletions packages/perseus/src/widgets/table/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,6 @@ class Table extends React.Component<Props> implements Widget {
return inputPaths;
};

getGrammarTypeForPath: (arg1: any) => string = (inputPath) => {
return "number";
};

setInputValue: (arg1: any, arg2: any, arg3: any) => void = (
path,
newValue,
Expand Down

0 comments on commit c6ee266

Please sign in to comment.