-
Notifications
You must be signed in to change notification settings - Fork 350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reviewModeRubric prework: limit reviewModeRubric uses #1741
Conversation
Size Change: -54 B (-0.01%) Total Size: 867 kB
ℹ️ View Unchanged
|
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (1501379) and published it to npm. You Example: yarn add @khanacademy/perseus@PR1741 If you are working in Khan Academy's webapp, you can run: ./dev/tools/bump_perseus_version.sh -t PR1741 |
reviewModeRubric?: Rubric | null | undefined; | ||
reviewMode: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I could tell, the only widget that was really using the contents of reviewModeRubric
was Radio. The other widgets were just using its existence to tell if they were in review mode or not. Then if you looked at how reviewModeRubric
was set, it kind of seemed like needless misdirection:
// renderer.tsx checks if we're in `reviewMode` then sets `reviewModeRubric`
const reviewModeRubric =
this.props.reviewMode && widgetInfo ? widgetInfo.options : null;
// passage.tsx for example then converted that object into a bool
const editable = !this.props.reviewModeRubric;
So the crux of this PR is: why don't we just use reviewMode
everywhere that's using coercing reviewModeRubric
to a flag so that it's clearer what's actually using reviewModeRubric
when we start work on LEMS-2437.
@@ -673,7 +673,8 @@ export type WidgetProps< | |||
onFocus: (blurPath: FocusPath) => void; | |||
onBlur: (blurPath: FocusPath) => void; | |||
findWidgets: (criterion: FilterCriterion) => ReadonlyArray<Widget>; | |||
reviewModeRubric: Rubric; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this was mistyped.
const reviewModeRubric =
this.props.reviewMode && widgetInfo ? widgetInfo.options : null;
@@ -46,14 +48,12 @@ const answerTypes = { | |||
|
|||
type Props = { | |||
value: number; | |||
simplify: PropsFor<typeof InputNumber.widget>["simplify"]; | |||
size: PropsFor<typeof InputNumber.widget>["size"]; | |||
inexact: PropsFor<typeof InputNumber.widget>["reviewModeRubric"]["inexact"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TS was exploding since reviewModeRubric
could have been null/undefined. This might be an unpopular opinion, but I'm not a big fan of the PropsFor<typeof SomeReactComponent>
pattern anyway. The editor exists to set widget options, so I feel like this is more correct anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually agree. I think the widget options types should be the glue between the editors and their widgets. I think we've gone through iterations of understanding Perseus code and so this might have been me doing this even (probably because the widget option type wasn't exported (yet)).
GeraldRequired Reviewers
Don't want to be involved in this pull request? Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I'm in favour!
@@ -46,14 +48,12 @@ const answerTypes = { | |||
|
|||
type Props = { | |||
value: number; | |||
simplify: PropsFor<typeof InputNumber.widget>["simplify"]; | |||
size: PropsFor<typeof InputNumber.widget>["size"]; | |||
inexact: PropsFor<typeof InputNumber.widget>["reviewModeRubric"]["inexact"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually agree. I think the widget options types should be the glue between the editors and their widgets. I think we've gone through iterations of understanding Perseus code and so this might have been me doing this even (probably because the widget option type wasn't exported (yet)).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great refactoring (and simplification)! Thank-you.
@@ -673,7 +673,8 @@ export type WidgetProps< | |||
onFocus: (blurPath: FocusPath) => void; | |||
onBlur: (blurPath: FocusPath) => void; | |||
findWidgets: (criterion: FilterCriterion) => ReadonlyArray<Widget>; | |||
reviewModeRubric: Rubric; | |||
reviewModeRubric?: Rubric | null | undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed with one tiny nit: If we have this typed with ?
then | undefined
is redundant.
Summary:
Not sure we'll want to merge this as it might be too risky/dirty, but I thought I'd try to remove as many instances as I could of
reviewModeRubric
without really changing logic to make it clearer where we're actually using it. Seems to just be radio.Issue: Prework for LEMS-2437