-
Notifications
You must be signed in to change notification settings - Fork 352
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
Update graph-settings.tsx to React class component #1009
Conversation
todo Issue: https://khanacademy.atlassian.net/browse/LC-1702 Test plan: todo
Size Change: -91 B (0%) Total Size: 815 kB
ℹ️ View Unchanged
|
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #1009 +/- ##
==========================================
+ Coverage 63.65% 64.85% +1.19%
==========================================
Files 425 427 +2
Lines 96484 96523 +39
Branches 6281 8678 +2397
==========================================
+ Hits 61420 62603 +1183
+ Misses 35064 33920 -1144
... and 76 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
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.
Awesome! Thanks.
|
||
stateFromProps: function (props) { | ||
stateFromProps(props) { |
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.
Can you mark this as static
? It will mean a few changes to call sites, but it'll ensure we don't "cheat" in this function ever and start accessing instance fields.
box={this.props.graph.box as [number, number]} | ||
labels={this.props.graph.labels} | ||
range={this.props.graph.range} | ||
step={this.props.graph.tickStep} | ||
gridStep={this.props.graph.gridStep} | ||
range={ | ||
this.props.graph.range as [ | ||
[number, number], | ||
[number, number], | ||
] | ||
} | ||
step={this.props.graph.tickStep as [number, number]} | ||
gridStep={this.props.graph.gridStep as [number, number]} |
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.
suggestion: In the next (or near future) PR you could change this components props so that they use tuples instead of ReadonlyArray<>
. That'd eliminate the need to do the casting you're doing here... and I think it's more accurate.
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 the props are already tuples. The problem is that we're doing a slice()
on them just above this, which is causing it to become number[]
types. And then I get a type error because that means it can be shorter than the tuple expects.
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 can move the as [number, number]
to those lines instead?
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.
Actually, all those .slice()
calls look like they're just used to copy the array. If you switch to spreading the array, Typescript seems to retain that their a tuple and you can eliminate the as
casting entirely.
Note: you are welcome to land this PR as is and do these changes in a new PR. Whatever works for you. :)
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (2156ef4) and published it to npm. You Example: yarn add @khanacademy/perseus@PR1009 |
…#1020) 🖍 _This is an audit!_ 🖍 ## Summary: Revert "Update graph-settings.tsx to React class component (#1009)" Reverting because this caused `this.setState` errors in the exercise editor. Fix for the future: update the functions in GraphSettings to arrow functions. Issue: XXX-XXXX ## Test plan: Author: nishasy Auditors: jeremywiebe Required Reviewers: Approved By: jeremywiebe Checks: ✅ codecov/project, ✅ codecov/patch, ✅ Upload Coverage, ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ Extract i18n strings (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Jest Coverage (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ gerald, ✅ Cypress (ubuntu-latest, 20.x) Pull Request URL: #1020
## Summary: This PR is pretty much the same as #1009. The changes from that PR got rolled back, and now interactive-graph-settings.tsx has been split out as a copy of graph-settings.tsx. Instead of updating graph-settings.tsx, we're keeping that as is as it will only be used by deprecated components. interactive-graph-settings.tsx will continue to be updated along with InteractiveGraph. To make these updates easier, we're making InteractiveGraphSettings a React class component instead of it using the old `createReactClass` const. - Update InteractiveGraphSettings to be a React class - Add types - Use arrow functions so `this` binds correctly Additional cleanup coming in a following PR. Issue: https://khanacademy.atlassian.net/browse/LC-1702 ## Test plan: `yarn jest packages/perseus-editor/src/components/__tests__/interactive-graph-settings.test.tsx` `yarn typecheck` Author: nishasy Reviewers: jeremywiebe, nishasy, nedredmond Required Reviewers: Approved By: jeremywiebe Checks: ✅ codecov/project, ✅ codecov/patch, ✅ Upload Coverage, ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Extract i18n strings (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ Jest Coverage (ubuntu-latest, 20.x), ✅ gerald, ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x) Pull Request URL: #1033
Summary:
createReactClass
const.Tests coming in follow-up PR.
Issue: https://khanacademy.atlassian.net/browse/LC-1702
Test plan:
yarn jest
yarn typecheck