Skip to content

Commit

Permalink
table rubric
Browse files Browse the repository at this point in the history
  • Loading branch information
handeyeco committed Sep 23, 2024
1 parent 4800998 commit 320dccf
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
3 changes: 3 additions & 0 deletions packages/perseus/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,9 @@ export type FilterCriterion =
) => boolean);

// NOTE: Rubric should always be the corresponding widget options type for the component.
// TODO: in fact, is it really the rubric? WidgetOptions is what we use to configure the widget
// (which is what this seems to be for)
// and Rubric is what we use to score the widgets (which not all widgets need validation)
export type WidgetProps<
RenderProps,
Rubric,
Expand Down
7 changes: 7 additions & 0 deletions packages/perseus/src/validation.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import type {
PerseusPlotterWidgetOptions,
PerseusRadioWidgetOptions,
PerseusSorterWidgetOptions,
PerseusTableWidgetOptions,
PerseusVideoWidgetOptions,
} from "./perseus-types";
import type {InteractiveMarkerType} from "./widgets/label-image/types";
import type {Relationship} from "./widgets/number-line/number-line";
Expand Down Expand Up @@ -199,8 +201,13 @@ export type PerseusSorterUserInput = {
options: ReadonlyArray<number>;
};

export type PerseusTableRubric = PerseusTableWidgetOptions;

export type PerseusTableUserInput = ReadonlyArray<ReadonlyArray<string>>;

// TODO (LEMS-2396): remove validation logic from widgets that don't validate
export type PerseusVideoRubric = PerseusVideoWidgetOptions;

export type UserInput =
| PerseusCategorizerUserInput
| PerseusCSProgramUserInput
Expand Down
21 changes: 13 additions & 8 deletions packages/perseus/src/widgets/table/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ import KhanAnswerTypes from "../../util/answer-types";
import type {ChangeableProps} from "../../mixins/changeable";
import type {PerseusTableWidgetOptions} from "../../perseus-types";
import type {PerseusStrings} from "../../strings";
import type {WidgetExports, WidgetProps} from "../../types";
import type {PerseusTableUserInput} from "../../validation.types";
import type {PerseusScore, WidgetExports, WidgetProps} from "../../types";
import type {
PerseusTableRubric,
PerseusTableUserInput,
} from "../../validation.types";

const {assert} = InteractiveUtil;

Expand All @@ -24,9 +27,7 @@ type RenderProps = PerseusTableWidgetOptions & {
Editor: any;
};

type Rubric = PerseusTableWidgetOptions;

type Props = ChangeableProps & WidgetProps<RenderProps, Rubric>;
type Props = ChangeableProps & WidgetProps<RenderProps, PerseusTableRubric>;

type DefaultProps = {
apiOptions: Props["apiOptions"];
Expand Down Expand Up @@ -128,14 +129,14 @@ class Table extends React.Component<Props> {
});
};

simpleValidate: (arg1: any) => any = (rubric) => {
simpleValidate(rubric: PerseusTableWidgetOptions): PerseusScore {
// @ts-expect-error - TS2339 - Property 'validate' does not exist on type 'typeof Table'.
return Table.validate(
this.getUserInput(),
rubric,
this.context.strings,
);
};
}

_handleFocus: (arg1: any) => void = (inputPath) => {
this.props.onFocus(inputPath);
Expand Down Expand Up @@ -319,7 +320,11 @@ class Table extends React.Component<Props> {
}

_.extend(Table, {
validate: function (state, rubric, strings: PerseusStrings) {
validate: function (
state: PerseusTableRubric,
rubric: PerseusTableWidgetOptions,
strings: PerseusStrings,
): PerseusScore {
const filterNonEmpty = function (table: any) {
return _.filter(table, function (row) {
// Check if row has a cell that is nonempty
Expand Down
4 changes: 2 additions & 2 deletions packages/perseus/src/widgets/video/video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import VideoTranscriptLink from "./video-transcript-link";

import type {PerseusVideoWidgetOptions} from "../../perseus-types";
import type {WidgetExports, WidgetProps} from "../../types";
import type {PerseusVideoRubric} from "../../validation.types";

// Current default is 720p, based on the typical videos we upload currently
const DEFAULT_WIDTH = 1280;
Expand All @@ -27,9 +28,8 @@ const IS_URL = /^https?:\/\//;
const IS_KA_SITE = /(khanacademy\.org|localhost)/;
const IS_VIMEO = /(vimeo\.com)/;

type Rubric = PerseusVideoWidgetOptions;
type RenderProps = PerseusVideoWidgetOptions; // exports has no 'transform'
type Props = WidgetProps<RenderProps, Rubric> & {
type Props = WidgetProps<RenderProps, PerseusVideoRubric> & {
alignment: string; // Where does this get set?
};

Expand Down

0 comments on commit 320dccf

Please sign in to comment.